TABSTRIP DEMO

© 2003, Alyce Watson

by Alyce Watson [Alyce's Restaurant]

Home

Collision Simulator

Foon's Tips

Encryption

Lesson Browser

Cookie DLL

LB NoteBoard

LB Clipboard Commands

Clipboard API Demos

Compiled HTML Help

Tabstrip

Tabstrip Demo

Scrolling Controls

Why API?

Sprite in a Box

Newsletter Help

Index


'tab control demo
'use dialog_popup windows to hold controls
'set parent of popups to be main program window
'when tab is clicked, use MoveWindow to move popups on and off
'if a graphicbox is used, use GetParent on popup
'if graphicbox is used, restore parent of popup at close
'doesn't work properly with type window_popup

nomainwin
    'constants:
    TCIF.TEXT = 1
    TCIF.IMAGE =2
    TCS.MULTILINE = 512
    TCM.INSERTITEMA = 4871
    TCM.GETCURSEL = 4875
    TCM.SETCURSEL = 4876

    tabID = 1   'current tab
    oldTab = 0  'previously selected tab

    struct TCITEM,_
    mask as ulong,_
    dwState as ulong,_
    dwStateMask as ulong,_
    pszText$ as ptr,_
    txtMax as long,_
    iImage as long,_
    lParam as long

    'initialize DLL
    calldll #comctl32, "InitCommonControls", ret as void

    WindowWidth=350:WindowHeight=210
    'example controls:
    'first page
    Statictext #tab1.s1, "First Tab Page!", 145, 75, 180, 30
    Button #tab1.b1, "Button 1", [buttonOne], UL, 145, 140, 90, 24
    open "" for window_popup as #tab1

    'second page
    Textbox #tab2.t2, 40, 40, 180, 30
    Button #tab2.b2, "Button 2", [buttonTwo], UL, 40, 80, 90, 24
    open "" for window_popup as #tab2

    'third page
    graphicbox #tab3.g, 0, 0, 350, 210
    open "" for window_popup as #tab3

    'main program window
    WindowWidth = 400:WindowHeight = 300
    open "Tab Demo" for window_nf as #1

    print #1, "trapclose [quit]"
    print #1, "font ms_sans_serif 10"
    #tab2.t2 "Second Tab Page!"

    print #tab3.g, "down; fill blue; color white"
    print #tab3.g, "backcolor blue"
    print #tab3.g, "place 30 50;\Third page!\Click Me!"
    print #tab3.g, "flush"
    print #tab3.g, "setfocus; when leftButtonDown [mouseClick]"

    hwndParent = hwnd(#1)    'retrieve window handle
    hTab1=hwnd(#tab1):hTab2=hwnd(#tab2):hTab3=hwnd(#tab3)
    dim tab(3)  'hold tab window handles in array
    tab(0)=hTab1:tab(1)=hTab2:tab(2)=hTab3

    'because of graphicbox, get parent on third tab window for use later
    hTab3Parent=GetParent(hTab3)
    
    'set popups to be children of main program window
    for i = 0 to 2
        call SetParent hwndParent,tab(i)
    next
    
    'move child windows
    gosub [clear]
    call MoveWindow hTab1, 20,40,350,210

    ' Get window instance handle
    CallDLL #user32, "GetWindowLongA",_
    hwndParent As long,_    'parent window handle
    _GWL_HINSTANCE As long,_'flag to retrieve instance handle
    hInstance As long       'instance handle

    ' Create control
    style =  _WS_CHILD or _WS_CLIPSIBLINGS or _WS_VISIBLE _
        or TCS.MULTILINE
    calldll #user32, "CreateWindowExA",_
        0 As long,_                  ' extended style
        "SysTabControl32" as ptr,_   ' class name
        "" as ptr,_
        style as long,_              ' style
        10 as long,_                 ' left x
        10 as long,_                 ' top y
        370 as long,_                ' width
        250 as long,_                ' height
        hwndParent as long,_         ' parent hWnd
        0 as long,_
        hInstance as long,_          ' hInstance
        "" as ptr,_
        hwndTab as long              ' tab control handle

    'set mask and fill struct members:
    TCITEM.mask.struct = TCIF.TEXT or TCIF.IMAGE
    TCITEM.iImage.struct = -1 'no image
    TCITEM.pszText$.struct = "First Tab"+chr$(0)
    'TCITEM.txtMax.struct=len("First Tab")+1 'used when retrieving text, not needed here

    'add first tab:
    calldll #user32, "SendMessageA",_
        hwndTab as long,_
        TCM.INSERTITEMA as long,_
        0 as long,_     'zero-based, so 0=first tab
        TCITEM as struct,_
        ret as long

    'add second tab:
    TCITEM.pszText$.struct = "Second Tab"+chr$(0)
    'TCITEM.txtMax.struct=len("Second Tab")+1  'used when retrieving text, not needed here
    calldll #user32, "SendMessageA",_
        hwndTab as long,_
        TCM.INSERTITEMA as long,_
        1 as long,_         'zero-based, so 1=second tab
        TCITEM as struct,_
        ret as long

    'add third tab:
    TCITEM.pszText$.struct = "Third Tab"+chr$(0)
    'TCITEM.txtMax.struct=len("Third Tab")+1  'used when retrieving text, not needed here
    calldll #user32, "SendMessageA",_
        hwndTab as long,_
        TCM.INSERTITEMA as long,_
        2 as long,_         'zero-based, so 2=third tab
        TCITEM as struct,_
        ret as long

    calldll #gdi32, "GetStockObject",_
        _DEFAULT_GUI_FONT as long, hFont as long

    'set the font to the control:
    CallDLL #user32, "SendMessageA",_
        hwndTab As long,_       'tab control handle
        _WM_SETFONT As long,_   'message
        hFont As long,_         'handle of font
        1 As long,_             'repaint flag
        ret As long

    timer 300, [checkForTab]
    calldll #user32, "SetFocus",hwndParent as ulong,re as ulong
    wait

[quit]
    timer 0
    'because of graphicbox, restore parent to third tab window
    call SetParent hTab3Parent, hTab3
    close #1:close #tab1:close #tab2:close #tab3:end

[checkForTab]   'see if selected tab is the same
                'as previously selected tab and
                'change controls if tab has changed
    timer 0     'turn off timer

    'get the current tab ID
    calldll #user32, "SendMessageA",_
        hwndTab as long,_       'tab control handle
        TCM.GETCURSEL as long,_ 'message to get current selection
        0 as long, 0 as long,_  'always 0's
        tabID as long           'returns selected tab ID

    if tabID <> oldTab then     'change page displayed
        oldTab = tabID          'for next check of selected tab
        gosub [clear]
        call MoveWindow tab(tabID), 20,40,350,210
    end if

    print #1, "refresh"
    timer 300, [checkForTab]    'reactivate timer
    wait

[buttonOne]
    timer 0
    notice "First page."
    timer 300, [checkForTab]
    wait

[buttonTwo]
    timer 0
    #tab2.t2 "!contents? txt$"
    notice "Textbox contents: ";txt$
    timer 300, [checkForTab]
    wait

[mouseClick]
    timer 0
    notice "Mouse clicked on third page."
    timer 300, [checkForTab]
    wait

[clear] 'hide all windows
    for i = 0 to 2
        call MoveWindow tab(i), 3000,3000,350,210
    next
    return

Function GetParent(hWnd)
    calldll #user32, "GetParent",hWnd as ulong,_
        GetParent as ulong
    End Function

Sub SetParent hWnd,hWndChild
    CallDLL #user32, "SetParent", hWndChild As Long,_
     hWnd As Long, result As Long
    End Sub

Sub MoveWindow hWnd,x,y,w,h
    CallDLL #user32, "MoveWindow",hWnd As Long,_
         x As Long, y As Long,_
         w As Long, h As Long,_
         1 As Boolean, r As Boolean
    End Sub


Home

Collision Simulator

Foon's Tips

Encryption

Lesson Browser

Cookie DLL

LB NoteBoard

LB Clipboard Commands

Clipboard API Demos

Compiled HTML Help

Tabstrip

Tabstrip Demo

Scrolling Controls

Why API?

Sprite in a Box

Newsletter Help

Index