Announcement

Collapse
No announcement yet.

TAB Stop question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TAB Stop question

    I hardly ever write GUI apps so this is probably a very simple thing to solve but I can't figure it out.

    If you run this example, using the TAB key on the first run will cycle through the TEXTBOX, OPTION BUTTON and COMMAND BUTTON sections as expected, but once I click the CLEAR button (and reset the fields), Using TAB will go from the TEXTBOX directly to the Command Buttons--skipping the OPTION BUTTON sections. I can't figure out why (you can just type anything in the TextBox for now-or leave it blank).

    I'm porting this from a PBCC app and the usual operation is that the program gets a batch number from the user, reads some stuff from a file and 'does its thing' and then resets for the next batch number--until the user quits.

    Code:
    #COMPILE EXE
    #DIM ALL
    %USEMACROS = 1
    #INCLUDE "WIN32API.INC"
                                                     
    '//////////////////////////////
    
    %IDC_LABEL      = 102             'Control ID's for the User Interface
    %IDC_LBL1_FRAME = 103
    %IDC_LBL2_FRAME = 104
    %IDC_TXTBOX     = 105
    
    %IDC_OPT_TV     = 106   'TV Batch
    %IDC_OPT_FM     = 107   'FM Batch
    %IDC_OPT_LB     = 108   'LockBox
    %IDC_OPT_ME     = 109   'Manual Entry
    
    %IDC_RUN        = 110
    %IDC_CLEAR      = 111
    %IDc_EXIT       = 112
    
    
    
    FUNCTION PBMAIN () AS LONG
    
        '///////////////////////////////////////////////////////////////////////////////////////////////
        '// Build the user interface ///////////////////////////////////////////////////////////////////
        '///////////////////////////////////////////////////////////////////////////////////////////////
    
        GLOBAL hDlg AS DWORD                                    
    
        DIALOG NEW 0, "KERA: Batch Preview",,, 285, 115, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
    
                                                               
        CONTROL ADD LABEL, hDlg, %IDC_LABEL, "Batch Number:",   12, 05, 50, 12
        CONTROL ADD TEXTBOX, hDlg, %IDC_TXTBOX,"",              12, 15, 50, 13,
    
        CONTROL ADD FRAME, hDlg, %IDC_LBL1_FRAME, "Entity",     12, 35, 95, 42  
        CONTROL ADD FRAME, hDlg, %IDC_LBL2_FRAME, "Batch Type", 120, 35, 95, 42
    
        CONTROL ADD OPTION, hDlg, %IDC_OPT_TV, "TV Batch",      17, 45, 80, 12,  %WS_GROUP OR %WS_TABSTOP
        CONTROL ADD OPTION, hDlg, %IDC_OPT_FM, "FM Batch",      17, 60, 80, 12
    
        CONTROL ADD OPTION, hDlg, %IDC_OPT_LB, "Lockbox",       125, 45, 80, 12, %WS_GROUP OR %WS_TABSTOP
        CONTROL ADD OPTION, hDlg, %IDC_OPT_ME, "Manual Entry",  125, 60, 80, 12
    
        CONTROL ADD BUTTON, hDlg, %IDC_RUN,    "&Run",          12,  83, 43, 20
        CONTROL ADD BUTTON, hDlg, %IDC_CLEAR,  "&Clear",        120, 83, 43, 20
        CONTROL ADD BUTTON, hDlg, %IDC_EXIT,   "E&xit",         172, 83, 43, 20
    
        CONTROL SET FOCUS hDlg, %IDC_TXTBOX
        DIALOG SHOW MODAL hDlg, CALL DlgProc()
    
        '//////////////////////////////////////////////////////////////////////////////////////////////
        '//////////////////////////////////////////////////////////////////////////////////////////////
    
    END FUNCTION
    
    
    CALLBACK FUNCTION DlgProc() AS LONG
    
        SELECT CASE AS LONG CBMSG
    
            CASE %WM_INITDIALOG
    
    
            CASE %WM_COMMAND
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_EXIT
                        IF CBCTLMSG = %BN_CLICKED THEN
                           'add code to close files, delete temp files
                            DIALOG END CBHNDL
                        END IF
                    CASE %IDC_CLEAR
                        IF CBCTLMSG = %BN_CLICKED THEN
                            CONTROL SET CHECK  hDlg, %IDC_OPT_TV, 0   'deselect the OptionButtons.
                            CONTROL SET CHECK  hDlg, %IDC_OPT_FM, 0
                            CONTROL SET CHECK  hDlg, %IDC_OPT_LB, 0
                            CONTROL SET CHECK  hDlg, %IDC_OPT_ME, 0
                            CONTROL SET TEXT   hDlg, %IDC_TXTBOX, ""  'clear the Batch Number TextBox and
                            CONTROL SET FOCUS  hDlg, %IDC_TXTBOX      'reset the focus for a new entry.
                        END IF
                    CASE %IDC_RUN
                        IF CBCTLMSG = %BN_CLICKED THEN
                           'Check the state of controls. Add error message if something is left
                           'blank or unselected.
                        END IF
    
                END SELECT
        END SELECT
    
    END FUNCTION
    I feel like this is due to something really simple like the placement of my
    '%WS_' styles or the way I'm clearing the form in the CALLBACK.

    By the way, is there a better way to reset everything on the form other than the way I'm doing it?

    Thanks.

    -Michael

  • #2
    See the remarks in the help file for the CONTROL ADD OPTION statement and for CONTROL SET OPTION statement
    Use Control Set Option to set the option buttons.

    Your code works ok with a couple of small changes..
    Code:
            CASE %WM_INITDIALOG
              CONTROL POST CBHNDL, %IDC_CLEAR, %BM_CLICK, 0, 0  ' Initialize controls
    ..
                    CASE %IDC_CLEAR
                        IF CBCTLMSG = %BN_CLICKED THEN
                            CONTROL SET OPTION  hDlg, %IDC_OPT_TV, %IDC_OPT_TV, %IDC_OPT_FM   ' set the Option Buttons.
                            CONTROL SET OPTION  hDlg, %IDC_OPT_LB, %IDC_OPT_LB, %IDC_OPT_ME   '
    If you have a lot of controls to reset at the same time it is useful to ensure that you create them with contiguous IDs,
    then you can deal with them in a loop, starting with the lowest ID and upping it on each iteration. Something like:
    Code:
    FOR ID = 0 TO Total
      Control Set Text CbHndl, %IDC_TEXTBOX1 + ID, ""
    NEXT
    Rgds, Dave

    Comment


    • #3
      I think yo unset all radio's?
      WM_TABSTOP is removed from not-selected radio's by Windows.
      You may want to force this style for the first or have a default radiobutton (which is selected)
      hellobasic

      Comment


      • #4
        Ok,

        Thanks guys. I knew how to set a default at start-up but was wanting it to default to 'no selection' each time through the process. However, maybe that's not possible. And when I think about it, I can't really think of any other program that acts that way.

        Setting a default solves the keyboard navigation problem.

        Thanks.

        -Michael.

        Comment

        Working...
        X