What is the proper way to create a win32 toolbar on vb6 using win32 api?

107 Views Asked by At

I want to create toolbar using win32 api to have more control over styles.

'Form1
Option Explicit

Private hWndTb As Long
Private tbb As TBBUTTON
Private tbab As TBADDBITMAP

Private Sub Form_Load()
    Show
    hWndTb = CreateWindowEx(WS_EX_CLIENTEDGE, "ToolbarWindow32", "", WS_CHILD Or WS_VISIBLE Or TBSTYLE_TOOLTIPS, 0, 0, 100, 100, Me.hwnd, 1001, App.hInstance, 0)
    SendMessage hWndTb, TB_BUTTONSTRUCTSIZE, Len(tbb), 0
    
    tbab.hInst = HINST_COMMCTRL
    tbab.nID = IDB_STD_SMALL_COLOR

    SendMessage hWndTb, TB_ADDBITMAP, 0, ByVal VarPtr(tbab)
    SendMessage hWndTb, TB_ADDSTRINGA, 0, ByVal "Text1"
    SendMessage hWndTb, TB_ADDSTRINGA, 0, ByVal "Text2"
    tbb.iBitmap = 0
    tbb.fsState = TBSTATE_ENABLED
    tbb.fsStyle = TBSTYLE_BUTTON
    tbb.idCommand = 101
    tbb.iString = 0

    SendMessage hWndTb, TB_ADDBUTTONSA, 1, ByVal tbb
    tbb.iBitmap = 1
    tbb.fsState = TBSTATE_ENABLED
    tbb.fsStyle = TBSTYLE_BUTTON
    tbb.idCommand = 102
    tbb.iString = 1
    SendMessage hWndTb, TB_ADDBUTTONSA, 1, ByVal tbb
    Form_Resize
End Sub

Private Sub Form_Resize()
    SendMessage hWndTb, TB_AUTOSIZE, 0, 0
End Sub

It successfully created the toolbar with two buttons but the text on the button is not as intended,the first button's text is "Text1" but the second button's text is the same. The second button's text should be "Text2".

enter image description here

0

There are 0 best solutions below