Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Very simple Tab Control example with menu and controls on main dialog

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

  • PBWin Very simple Tab Control example with menu and controls on main dialog

    ' Very simple Tab Control example with menu and controls on main dialog.
    '
    ' Version 1
    '
    ' Inspired by the PowerBasic example in the DDT folder.
    ' I think it simplifies construction and facilitates operation to
    ' explicitely define a common callback function for all tab dialogs
    ' AND the main dialog. You do not need a modeless main dialog.
    ' A modal main dialog is sufficient. This version uses global
    ' dialog handles.

    ' Best regards
    '
    ' Erik

    Code:
    ' Very simple Tab Control example with menu and controls on main dialog.
    '
    ' Version 1
    '
    ' Inspired by the PowerBasic example in the DDT folder.
    ' I think it simplifies construction and facilitates operation to
    ' explicitely define a common callback function for all tab dialogs
    ' AND the main dialog. You do not need a modeless main dialog.
    ' A modal main dialog is sufficient. This version uses global
    ' dialog handles.
    
    ' Best regards :)
    '
    ' Erik
    
    #COMPILER PBWIN 9
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "win32api.inc"
    
    ' Control equates
    %ID_TAB            = 1000
    %ID_TAB1_TBFIRST   = 1001
    %ID_TAB1_LBFIRST   = 1002
    %ID_TAB1_LBLAST    = 1003
    %ID_TAB1_TBLAST    = 1004
    %ID_TAB1_BNSUBMIT  = 1005
    %ID_TAB2_CBCHOICES = 1006
    %ID_TAB3_LBCHOICES = 1007
    %ID_TAB3_TEXTBOX   = 1008
    
    %ID_DIAL_BN_EXIT   = 1100
    
    %ID_OPEN           = 2000
    %ID_EXIT           = 2001
    
    ' global handles for main dialog and tab dialogs
    GLOBAL hDlg      AS LONG
    GLOBAL hTab1     AS LONG
    GLOBAL hTab2     AS LONG
    GLOBAL hTab3     AS LONG
    
    FUNCTION PBMAIN () AS LONG
      LOCAL hBoldFont AS LONG
      LOCAL hMenu AS DWORD
      LOCAL hPopup1 AS DWORD
    
      ' Create the font used by some controls in this example
      FONT NEW "Arial", 10, 1 TO hBoldFont
    
      DIALOG NEW PIXELS, 0, "Easy Tab Control Example", , , 1020, 532, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    
      ' Add a Tab control to the main dialog box
      CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 700, 400
      CONTROL SET FONT hDlg, %ID_TAB, hBoldFont
    
      ' Build the Tab 1 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1", CALL DialAndTabCallBackFunct TO hTab1
    
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 4, 12, 200, 24
      CONTROL SET COLOR    hTab1, %ID_TAB1_LBFIRST, %BLUE, -2
      CONTROL SET FONT     hTab1, %ID_TAB1_LBFIRST, hBoldFont
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 120, 12, 200, 24
    
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 40, 200, 24
      CONTROL SET COLOR    hTab1, %ID_TAB1_LBLAST, %BLUE, -2
      CONTROL SET FONT     hTab1, %ID_TAB1_LBLAST, hBoldFont
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 120, 40, 200, 24
    
      CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 578, 330, 100, 28
      CONTROL SET FONT     hTab1, %ID_TAB1_BNSUBMIT, hBoldFont
    
      ' Build the Tab 2 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2", CALL DialAndTabCallBackFunct TO hTab2
      CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 4, 12, 200, 200, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
      CONTROL SET COLOR     hTab2, %ID_TAB2_CBCHOICES, %BLACK, %GREEN
      CONTROL SET FONT      hTab2, %ID_TAB2_CBCHOICES, hBoldFont
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
      COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
    
      ' Build the Tab 3 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3", CALL DialAndTabCallBackFunct TO hTab3
      CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 4, 12, 200, 87
      CONTROL SET COLOR     hTab3, %ID_TAB3_LBCHOICES, %WHITE, %RED
      CONTROL SET FONT      hTab3, %ID_TAB3_LBCHOICES, hBoldFont
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
    
      CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 240, 12, 200, 24, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
      CONTROL SET COLOR     hTab3, %ID_TAB3_TEXTBOX, %WHITE, %RED
      CONTROL SET FONT      hTab3, %ID_TAB3_TEXTBOX, hBoldFont
    
      ' Make exit button on main dialog
      CONTROL ADD BUTTON,   hDlg, %ID_DIAL_BN_EXIT, "E&xit", 900, 450, 90, 30
      CONTROL SET FONT      hDlg, %ID_DIAL_BN_EXIT, hBoldFont
    
      ' Create a top-level menu:
      MENU NEW BAR TO hMenu
    
      ' Add a top-level menu item with a popup menu:
      MENU NEW POPUP TO hPopup1
      MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Exit", %ID_EXIT, %MF_ENABLED
    
      MENU ATTACH hMenu, hDlg
    
      ' Display the main dialog box
      DIALOG SHOW MODAL hDlg CALL DialAndTabCallBackFunct
    
      ' Destroy font
      FONT END hBoldFont
    
    END FUNCTION
    
    ' Callback function used by main dialog and all Tab dialogs
    CALLBACK FUNCTION DialAndTabCallBackFunct
      LOCAL i    AS LONG
      LOCAL s    AS STRING
    
      SELECT CASE AS LONG CB.MSG
    
        CASE %WM_INITDIALOG
    
            ' %WM_INITDIALOG is fired for each dialog. We need it only once.
            IF CBHNDL = hDlg THEN
    
               ' DIALOG SET COLOR hDlg, -1, %RGB_LIGHTGRAY
               ' DIALOG REDRAW hDlg
                DIALOG SET COLOR hTab1, -1, RGB(220,220,249)
                DIALOG REDRAW hTab1
                DIALOG SET COLOR hTab2, -1, RGB(220,249,220)
                DIALOG REDRAW hTab2
                DIALOG SET COLOR hTab3, -1, RGB(249,220,220)
                DIALOG REDRAW hTab3
    
            END IF
    
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
    
            CASE %ID_TAB1_BNSUBMIT
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
              END IF
    
            CASE %ID_TAB2_CBCHOICES
              IF CB.CTLMSG = %CBN_SELCHANGE THEN
                COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                MSGBOX "You selected "+s
              END IF
    
            CASE %ID_TAB3_LBCHOICES
              IF CB.CTLMSG = %LBN_SELCHANGE THEN
                LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
              END IF
    
            CASE %ID_DIAL_BN_EXIT
                IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CBHNDL
    
            ' menu items
            CASE %ID_OPEN
                MSGBOX "You selected Menu item Open"
    
            CASE %ID_EXIT
                MSGBOX "You selected Menu item Exit"
                ' DIALOG END CBHNDL
    
          END SELECT
    
      END SELECT
    
    END FUNCTION
    Last edited by Erik Christensen; 25 Apr 2011, 08:18 AM. Reason: Small change in %WM_INITDIALOG section

  • #2
    --
    Last edited by Erik Christensen; 24 Apr 2011, 05:36 AM.

    Comment


    • #3
      ' Very simple Tab Control example with menu and controls on main dialog.
      '
      ' Version 2
      '
      ' This version avoids global handles. Instead static dialog handles are
      ' used in the common dialog callback function. This is accomplished in the
      ' %WM_INITDIALOG section of the callback function. I think this
      ' version is the best. Avoiding global handles may reduce the risk of
      ' coding errors.
      '
      ' Best regards
      '
      ' Erik

      Code:
      ' Very simple Tab Control example with menu and controls on main dialog.
      '
      ' Version 2
      '
      ' This version avoids global handles. Instead static dialog handles are 
      ' used in the common dialog callback function. This is accomplished in the
      ' %WM_INITDIALOG section of the callback function. I think this
      ' version is the best. Avoiding global handles may reduce the risk of
      ' coding errors.
      '
      ' Best regards :)
      '
      ' Erik
      
      #COMPILER PBWIN 9
      #COMPILE EXE
      #DIM ALL
      
      #INCLUDE "win32api.inc"
      
      ' Control equates
      %ID_TAB            = 1000
      %ID_TAB1_TBFIRST   = 1001
      %ID_TAB1_LBFIRST   = 1002
      %ID_TAB1_LBLAST    = 1003
      %ID_TAB1_TBLAST    = 1004
      %ID_TAB1_BNSUBMIT  = 1005
      %ID_TAB2_CBCHOICES = 1006
      %ID_TAB3_LBCHOICES = 1007
      %ID_TAB3_TEXTBOX   = 1008
      
      %ID_DIAL_BN_EXIT   = 1100
      
      %ID_OPEN           = 2000
      %ID_EXIT           = 2001
      
      GLOBAL hDlg      AS LONG ' TEMPORARY global handle for main dialog
      
      FUNCTION PBMAIN () AS LONG
        LOCAL hTab1     AS LONG
        LOCAL hTab2     AS LONG
        LOCAL hTab3     AS LONG
        LOCAL hBoldFont AS LONG
        LOCAL hMenu AS DWORD
        LOCAL hPopup1 AS DWORD
      
        ' Create the font used by some controls in this example
        FONT NEW "Arial", 10, 1 TO hBoldFont
      
        DIALOG NEW PIXELS, 0, "Easy Tab Control Example - version 2", , , 1020, 532, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
          %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
          %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
      
        ' Add a Tab control to the main dialog box
        CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 700, 400
        CONTROL SET FONT hDlg, %ID_TAB, hBoldFont
      
        ' Build the Tab 1 dialog and it's controls
        TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1" CALL DialAndTabCallBackFunct TO hTab1
      
        CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 4, 12, 200, 24
        CONTROL SET COLOR    hTab1, %ID_TAB1_LBFIRST, %BLUE, -2
        CONTROL SET FONT     hTab1, %ID_TAB1_LBFIRST, hBoldFont
        CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 120, 12, 200, 24
      
        CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 40, 200, 24
        CONTROL SET COLOR    hTab1, %ID_TAB1_LBLAST, %BLUE, -2
        CONTROL SET FONT     hTab1, %ID_TAB1_LBLAST, hBoldFont
        CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 120, 40, 200, 24
      
        CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 578, 330, 100, 28
        CONTROL SET FONT     hTab1, %ID_TAB1_BNSUBMIT, hBoldFont
      
        ' Build the Tab 2 dialog and it's controls
        TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2" CALL DialAndTabCallBackFunct TO hTab2
        CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 4, 12, 200, 200, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
        CONTROL SET COLOR     hTab2, %ID_TAB2_CBCHOICES, %BLACK, %GREEN
        CONTROL SET FONT      hTab2, %ID_TAB2_CBCHOICES, hBoldFont
        COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
        COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
        COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
        COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
      
        ' Build the Tab 3 dialog and it's controls
        TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3" CALL DialAndTabCallBackFunct TO hTab3
        CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 4, 12, 200, 87
        CONTROL SET COLOR     hTab3, %ID_TAB3_LBCHOICES, %WHITE, %RED
        CONTROL SET FONT      hTab3, %ID_TAB3_LBCHOICES, hBoldFont
        LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
        LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
        LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
        LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
      
        CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 240, 12, 200, 24, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
        CONTROL SET COLOR     hTab3, %ID_TAB3_TEXTBOX, %WHITE, %RED
        CONTROL SET FONT      hTab3, %ID_TAB3_TEXTBOX, hBoldFont
      
        ' Make exit button on main dialog
        CONTROL ADD BUTTON,   hDlg, %ID_DIAL_BN_EXIT, "E&xit", 900, 450, 90, 30
        CONTROL SET FONT      hDlg, %ID_DIAL_BN_EXIT, hBoldFont
      
        ' Create a top-level menu:
        MENU NEW BAR TO hMenu
      
        ' Add a top-level menu item with a popup menu:
        MENU NEW POPUP TO hPopup1
        MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
        MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_ENABLED
        MENU ADD STRING, hPopup1, "&Exit", %ID_EXIT, %MF_ENABLED
      
        MENU ATTACH hMenu, hDlg
      
        ' Display the main dialog box
        DIALOG SHOW MODAL hDlg CALL DialAndTabCallBackFunct
      
        ' Destroy font
        FONT END hBoldFont
      
      END FUNCTION
      
      ' Callback function used by main dialog and all Tab dialogs
      CALLBACK FUNCTION DialAndTabCallBackFunct
      
        LOCAL i       AS LONG
        LOCAL j       AS LONG
        LOCAL s       AS STRING
      
        STATIC hMain  AS LONG
        STATIC hTab1  AS LONG
        STATIC hTab2  AS LONG
        STATIC hTab3  AS LONG
      
        SELECT CASE AS LONG CB.MSG
      
          CASE %WM_INITDIALOG
      
              ' %WM_INITDIALOG is fired for each dialog. We need it only once - for the main dialog.
              IF CBHNDL = hDlg THEN
      
                  ' Get the values for the new static dialog handles
                  hMain = CBHNDL
                  TAB GET DIALOG CBHNDL, %ID_TAB, 1 TO hTab1
                  TAB GET DIALOG CBHNDL, %ID_TAB, 2 TO hTab2
                  TAB GET DIALOG CBHNDL, %ID_TAB, 3 TO hTab3
                  
                  ' set the dialog colors using the specific handles
                  DIALOG SET COLOR hMain, -1, %RGB_LIGHTGRAY
                  DIALOG REDRAW hMain
      
                  DIALOG SET COLOR hTab1, -1, RGB(220,220,249)
                  DIALOG REDRAW hTab1
      
                  DIALOG SET COLOR hTab2, -1, RGB(220,249,220)
                  DIALOG REDRAW hTab2
      
                  DIALOG SET COLOR hTab3, -1, RGB(249,220,220)
                  DIALOG REDRAW hTab3
      
                  RESET hDlg ' Disable global handle, which is no longer used.
              END IF
      
          CASE %WM_COMMAND
            SELECT CASE AS LONG CB.CTL
      
              CASE %ID_TAB1_BNSUBMIT
                IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                  MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
                END IF
      
              CASE %ID_TAB2_CBCHOICES
                IF CB.CTLMSG = %CBN_SELCHANGE THEN
                  COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                  COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                  MSGBOX "You selected "+s
                END IF
      
              CASE %ID_TAB3_LBCHOICES
                IF CB.CTLMSG = %LBN_SELCHANGE THEN
                  LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                  LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                  CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
                END IF
      
              CASE %ID_DIAL_BN_EXIT
                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CBHNDL
      
              ' menu items
              CASE %ID_OPEN
                  MSGBOX "You selected Menu item Open"
      
              CASE %ID_EXIT
                  MSGBOX "You selected Menu item Exit"
                  ' DIALOG END CBHNDL
      
            END SELECT
      
        END SELECT
      
      END FUNCTION
      Last edited by Erik Christensen; 25 Apr 2011, 08:22 AM.

      Comment


      • #4
        Erik, versions 1 & 2 runs fine on PB10 too.
        "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

        Comment


        • #5
          ' Very simple Tab Control example with menu and controls on main dialog.
          '
          ' Version 3
          '
          ' In this version the static dialog handles are placed in an array.
          ' This may sometimes be an advantage in the coding of more complex
          ' programs. The handle array is made in the %WM_INITDIALOG section
          ' of the callback function.
          '
          ' Best regards
          '
          ' Erik

          Code:
          ' Very simple Tab Control example with menu and controls on main dialog.
          '
          ' Version 3
          '
          ' In this version the static dialog handles are placed in an array.
          ' This may sometimes be an advantage in the coding of more complex
          ' programs. The handle array is made in the %WM_INITDIALOG section
          ' of the callback function.
          '
          ' Best regards :)
          '
          ' Erik
          
          #COMPILER PBWIN 9
          #COMPILE EXE
          #DIM ALL
          
          #INCLUDE "win32api.inc"
          
          ' Control equates
          %ID_TAB            = 1000
          %ID_TAB1_TBFIRST   = 1001
          %ID_TAB1_LBFIRST   = 1002
          %ID_TAB1_LBLAST    = 1003
          %ID_TAB1_TBLAST    = 1004
          %ID_TAB1_BNSUBMIT  = 1005
          %ID_TAB2_CBCHOICES = 1006
          %ID_TAB3_LBCHOICES = 1007
          %ID_TAB3_TEXTBOX   = 1008
          
          %ID_DIAL_BN_EXIT   = 1100
          
          %ID_OPEN           = 2000
          %ID_EXIT           = 2001
          
          GLOBAL hDlg      AS LONG ' TEMPORARY global handle for main dialog
          
          FUNCTION PBMAIN () AS LONG
            LOCAL hTab1     AS LONG
            LOCAL hTab2     AS LONG
            LOCAL hTab3     AS LONG
            LOCAL hBoldFont AS LONG
            LOCAL hMenu AS DWORD
            LOCAL hPopup1 AS DWORD
          
            ' Create the font used by some controls in this example
            FONT NEW "Arial", 10, 1 TO hBoldFont
          
            DIALOG NEW PIXELS, 0, "Easy Tab Control Example - version 2", , , 1020, 532, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
              %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
              %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          
            ' Add a Tab control to the main dialog box
            CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 700, 400
            CONTROL SET FONT hDlg, %ID_TAB, hBoldFont
          
            ' Build the Tab 1 dialog and it's controls
            TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1" CALL DialAndTabCallBackFunct TO hTab1
          
            CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 4, 12, 200, 24
            CONTROL SET COLOR    hTab1, %ID_TAB1_LBFIRST, %BLUE, -2
            CONTROL SET FONT     hTab1, %ID_TAB1_LBFIRST, hBoldFont
            CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 120, 12, 200, 24
          
            CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 40, 200, 24
            CONTROL SET COLOR    hTab1, %ID_TAB1_LBLAST, %BLUE, -2
            CONTROL SET FONT     hTab1, %ID_TAB1_LBLAST, hBoldFont
            CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 120, 40, 200, 24
          
            CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 578, 330, 100, 28
            CONTROL SET FONT     hTab1, %ID_TAB1_BNSUBMIT, hBoldFont
          
            ' Build the Tab 2 dialog and it's controls
            TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2" CALL DialAndTabCallBackFunct TO hTab2
            CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 4, 12, 200, 200, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
            CONTROL SET COLOR     hTab2, %ID_TAB2_CBCHOICES, %BLACK, %GREEN
            CONTROL SET FONT      hTab2, %ID_TAB2_CBCHOICES, hBoldFont
            COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
            COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
            COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
            COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
          
            ' Build the Tab 3 dialog and it's controls
            TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3" CALL DialAndTabCallBackFunct TO hTab3
            CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 4, 12, 200, 87
            CONTROL SET COLOR     hTab3, %ID_TAB3_LBCHOICES, %WHITE, %RED
            CONTROL SET FONT      hTab3, %ID_TAB3_LBCHOICES, hBoldFont
            LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
            LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
            LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
            LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
          
            CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 240, 12, 200, 24, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
            CONTROL SET COLOR     hTab3, %ID_TAB3_TEXTBOX, %WHITE, %RED
            CONTROL SET FONT      hTab3, %ID_TAB3_TEXTBOX, hBoldFont
          
            ' Make exit button on main dialog
            CONTROL ADD BUTTON,   hDlg, %ID_DIAL_BN_EXIT, "E&xit", 900, 450, 90, 30
            CONTROL SET FONT      hDlg, %ID_DIAL_BN_EXIT, hBoldFont
          
            ' Create a top-level menu:
            MENU NEW BAR TO hMenu
          
            ' Add a top-level menu item with a popup menu:
            MENU NEW POPUP TO hPopup1
            MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
            MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_ENABLED
            MENU ADD STRING, hPopup1, "&Exit", %ID_EXIT, %MF_ENABLED
          
            MENU ATTACH hMenu, hDlg
          
            ' Display the main dialog box
            DIALOG SHOW MODAL hDlg CALL DialAndTabCallBackFunct
          
            ' Destroy font
            FONT END hBoldFont
          
          END FUNCTION
          
          ' Callback function used by main dialog and all Tab dialogs
          CALLBACK FUNCTION DialAndTabCallBackFunct
          
            LOCAL i       AS LONG
            LOCAL j       AS LONG
            LOCAL s       AS STRING
          
            SELECT CASE AS LONG CB.MSG
          
              CASE %WM_INITDIALOG
          
                  ' %WM_INITDIALOG is fired for each dialog. We need it only once - for the main dialog.
                  IF CBHNDL = hDlg THEN
          
                      TAB GET COUNT CBHNDL, %ID_TAB TO i ' Get number of tabs
                      
                      DIM hTab(0 TO i) AS STATIC LONG ' Static array for dialog handles
          
                      hTab(0) = CBHNDL                ' Handle for main dialog gets index zero
          
                      FOR j = 1 TO i                  ' Get tab dialog handles to array
                          TAB GET DIALOG CBHNDL, %ID_TAB, j TO hTab(j)
                      NEXT
          
                      DIM ColArr(0 TO i) AS STATIC LONG ' Array for colors
                      
                      ARRAY ASSIGN ColArr() = %RGB_LIGHTGRAY, RGB(220,220,249), RGB(220,249,220), RGB(249,220,220)
          
                      FOR j = 0 TO i                    ' Set dialog colors
                          DIALOG SET COLOR hTab(j), -1, ColArr(j)
                          DIALOG REDRAW hTab(j)
                      NEXT
          
                      RESET hDlg ' Disable global handle, which is no longer used.
                  END IF
          
              CASE %WM_COMMAND
                SELECT CASE AS LONG CB.CTL
          
                  CASE %ID_TAB1_BNSUBMIT
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                      MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
                    END IF
          
                  CASE %ID_TAB2_CBCHOICES
                    IF CB.CTLMSG = %CBN_SELCHANGE THEN
                      COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                      COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                      MSGBOX "You selected "+s
                    END IF
          
                  CASE %ID_TAB3_LBCHOICES
                    IF CB.CTLMSG = %LBN_SELCHANGE THEN
                      LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                      LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                      CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
                    END IF
          
                  CASE %ID_DIAL_BN_EXIT
                      IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CBHNDL
          
                  ' menu items
                  CASE %ID_OPEN
                      MSGBOX "You selected Menu item Open"
          
                  CASE %ID_EXIT
                      MSGBOX "You selected Menu item Exit"
                      ' DIALOG END CBHNDL
          
                END SELECT
          
            END SELECT
          
          END FUNCTION

          Comment

          Working...
          X