Announcement

Collapse
No announcement yet.

dialog with tabstrip

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

  • dialog with tabstrip

    Here is a TabStrip.bas program which demonstrates tab strips. It is a work in progress for anyone who needs a start.

    Resource:
    Code:
     
    
    #include "resource.h"
    //#define IDD_DLG0 1000
    #define IDC_BTN1 1002
    #define IDC_TAB1 1001
    
    #define IDD_TAB1 1200
    #define CHK_2 1201
    #define CHK_3 1202
    #define EDT_2 1203
    #define EDT_3 1204
    #define EDT_4 1205
    
    #define IDD_TAB2 1100
    #define CHK_1 1101
    #define EDT_1 1102
    
    #define IDD_TAB3 1300
    #define CHK_4 1301
    #define CHK_5 1302
    #define EDT_5 1303
    
    DIALOG_0 DIALOGEX 226,226,248,188
    CAPTION "Tabstrip"
    FONT 8,"MS Sans Serif",400,0
    //STYLE 0x10C80880
    STYLE DS_FIXEDSYS |DS_SETFONT |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_CAPTION
    //EXSTYLE 0x00000001
    BEGIN
      CONTROL "Exit",IDC_BTN1,"Button",0x50010000,176,166,64,17
      CONTROL "",IDC_TAB1,"SysTabControl32",0x50018000,2,3,244,157
    END
    
    IDD_TAB1 DIALOGEX 6,15,200,123
    FONT 8,"MS Sans Serif",400,0
    STYLE 0x50000000
    
    BEGIN
      CONTROL "CheckBox",CHK_2,"Button",0x50010003,8,24,170,13
      CONTROL "CheckBox",CHK_3,"Button",0x50010003,8,38,170,15
      CONTROL "",EDT_2,"Edit",0x50010000,8,55,174,13,0x00000200
      CONTROL "",EDT_3,"Edit",0x50010000,8,73,174,13,0x00000200
      CONTROL "",EDT_4,"Edit",0x50010000,8,92,174,13,0x00000200
    END
    
    IDD_TAB2 DIALOGEX 6,15,200,123
    FONT 8,"MS Sans Serif",400,0
    STYLE 0x40000000
    BEGIN
      CONTROL "CheckBox",CHK_1,"Button",0x50010003,14,38,172,9
      CONTROL "",EDT_1,"Edit",0x50010000,14,49,172,13,0x00000200
    END
    
    IDD_TAB3 DIALOGEX 6,15,200,123
    FONT 8,"MS Sans Serif",400,0
    STYLE 0x40000000
    BEGIN
      CONTROL "CheckBox",CHK_4,"Button",0x50010003,8,24,170,13
      CONTROL "CheckBox",CHK_5,"Button",0x50010003,8,38,170,15
      CONTROL "",EDT_5,"Edit",0x50010000,8,55,174,13,0x00000200
    
    END
    Program:

    Code:
        
    ' tabstrip.bas
    ' djt
    
    #COMPILE EXE
    '#CONSOLE OFF
    
    #INCLUDE "Win32API.inc"
    #INCLUDE "commctrl.inc"
    
    #RESOURCE "tabstrip.pbr"
    
    GLOBAL buffer AS ASCIIZ * 45
    GLOBAL cnt AS LONG
    
    DEFLNG a-z
    
    %IDC_TAB1 = 1001
    %IDC_BTN1 = 1002
    
    %IDD_TAB1 = 1200
    %IDD_TAB2 = 1100
    %IDD_TAB3 = 1300
    
    %EDT_2    = 1203
    %EDT_3    = 1204
    %EDT_5    = 1303
    
    
    FUNCTION WINMAIN (BYVAL hCurInstance  AS LONG, _     'Not PBMain since
                      BYVAL hPrevInstance AS LONG, _     'hCurInstance is needed
                      BYVAL lpszCmdLine         AS ASCIIZ PTR, _
                      BYVAL nCmdShow AS LONG ) EXPORT AS LONG
    
        hInstance=GetModuleHandle("")
        InitCommonControls
    
         DialogBoxParam(hCurInstance, "dialog_0",hWndParent, CODEPTR(DlgProc), 0)
    
    
    END FUNCTION
    
    FUNCTION Tab1Proc(BYVAL hDlg AS LONG, uMsg AS ASCIIZ,BYVAL wParam AS LONG,BYVAL lParam AS LONG) AS LONG
    
        GetDlgItemtext(hdlg,%edt_2,buffer,40)
    
    
    END FUNCTION
    
    FUNCTION Tab2Proc(BYVAL hDlg AS LONG, uMsg AS ASCIIZ,BYVAL wParam AS LONG,BYVAL lParam AS LONG) AS LONG
    
    
    END FUNCTION
    
    FUNCTION Tab3Proc(BYVAL hDlg AS LONG, uMsg AS ASCIIZ,BYVAL wParam AS LONG,BYVAL lParam AS LONG) AS LONG
    
    '    setfocus(getdlgitem(hdlg,%edt_5))
    END FUNCTION
    
    
    FUNCTION DlgProc(BYVAL hDlg AS LONG, BYVAL uMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
        DIM id AS LONG
        DIM event AS LONG
        DIM x AS LONG
        DIM y AS LONG
        DIM hBtn AS LONG
        DIM rc AS RECT
        DIM ts AS TC_ITEM
        DIM tabtext AS ASCIIZ * 5
        DIM hTab AS LONG
        DIM lpNMHDR AS NMHDR PTR
        DIM tpnmhdr AS NMHDR
    
        SELECT CASE uMsg
            CASE %WM_INITDIALOG
                ' Get handle of tabstrip
                hTab=GetDlgItem(hDlg,%IDC_TAB1)
    
                ts.mask=%TCIF_TEXT OR %TCIF_PARAM
    
    ' Create Tab1 child dialog
                tabtext="TAB1"
                ts.pszText=VARPTR(tabtext)
                ts.lParam=CreateDialogParam(hInstance,BYVAL %IDD_TAB1,hTab,CODEPTR(Tab1Proc),0)   'puts controls on tab dialog (textbox,chkmark etc.)
                SendMessage(hTab,%TCM_INSERTITEM,0,VARPTR(ts)) 'creates tab dialog & label
    
                setfocus(getdlgitem(LOWRD(ts.lparam),%edt_2))
    
    ' Create Tab2 child dialog
                tabtext1$="TAB2"
                ts.pszText=STRPTR(tabtext1$)
                ts.lParam=CreateDialogParam(hInstance,BYVAL %IDD_TAB2,hTab,CODEPTR(Tab2Proc),0)
                SendMessage(hTab,%TCM_INSERTITEM,1,VARPTR(ts))
    
    ' Create Tab3 child dialog
                tabtext1$="TAB3"
                ts.pszText=STRPTR(tabtext1$)
                ts.lParam=CreateDialogParam(hInstance,BYVAL %IDD_TAB3,hTab,CODEPTR(Tab3Proc),0)
                SendMessage(hTab,%TCM_INSERTITEM,2,VARPTR(ts))
    
    
    
            CASE %WM_NOTIFY
                lpnmhdr=lparam
    
                IF @lpNMHDR.code=%TCN_SELCHANGING THEN          '-552
                    ' Hide the currently selected dialog
                    id=SendMessage(@lpNMHDR.hwndfrom,%TCM_GETCURSEL,0,0)
                    ts.mask=%TCIF_PARAM
                    SendMessage(@lpNMHDR.hwndfrom,%TCM_GETITEM,id,VARPTR(ts))
                    ShowWindow(LOWRD(ts.lparam),%SW_HIDE)
                ELSEIF @lpNMHDR.code=%TCN_SELCHANGE THEN        '-551
                    ' Show the currently selected dialog
                    id=SendMessage(@lpNMHDR.hwndfrom,%TCM_GETCURSEL,0,0)
                    ts.mask=%TCIF_PARAM
                    SendMessage(@lpNMHDR.hwndfrom,%TCM_GETITEM,id,VARPTR(ts))
                    ShowWindow(LOWRD(ts.lparam),%SW_SHOW)
    
                END IF
    
                setdlgitemtext(LOWRD(ts.lparam),%edt_5,buffer)
    
    
            CASE %WM_CLOSE
                CLOSE 1
                EndDialog(hDlg, 0)
    
            CASE %WM_COMMAND
                id=LOWRD(wParam)
                event=HIWRD(wParam)
    
                SELECT CASE id
    
                     CASE %idcancel 'esc keydown
                        EndDialog( hDlg, NULL )
    
                     CASE %idc_btn1       'exit
                        EndDialog hDlg, 0
                        FUNCTION = 0
                 END SELECT
    
    
        END SELECT
    
    END FUNCTION
    djt
    Last edited by david thain; 26 Feb 2008, 04:12 PM.
    djthain

  • #2
    YOu need to InitCommonControls[Eex] (In Winmain() suggested, but anytime before CreateDialog/DialogBox call is OK). for the Tab control or it won't be created.

    Usually the dialog creation totally fails if you fail to do this, but it's possible the dialog will be created without the tab control.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Code change

      Added InitCommonControls and made other changes but still no controls or labels???
      djthain

      Comment


      • #4
        Hint:
        Code:
           ......
           CASE %WM_INITDIALOG  
           ....   
             MSGBOX "ts.lparam=" & FORMAT$ (ts.lparam),,"TAB2"
        Which you would have found, too if only you had checked the value returned by CreateDialogParam. (Hint: the function is failing to create the next dialog).

        CreateDialogParam - like all Windows API functions - returns a value for a reason.

        MCM
        Last edited by Michael Mattias; 15 Feb 2008, 02:45 PM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          That's failing because....
          Code:
          #define IDD_TAB1 1100
          .....
          IDD_TAB1 DIALOGEX 6,15,200,123
          ... makes the dialog identifier numeric, meaning you want to Pass "BYVAL %IDD_TAB1" not a character string "IDD_TAB1"

          Let me see if that works now...yeah it does.
          Last edited by Michael Mattias; 15 Feb 2008, 02:54 PM.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X