VB Code:
Dim nPos As Long
Dim tbb As TBBUTTON
' You only have to send the TB_BUTTONSTRUCTSIZE message once, before inserting the first button.
SendMessage hwndTb, TB_BUTTONSTRUCTSIZE, Len(tbb), ByVal 0&
' Since we want to insert the button at the end of the toolbar, set
' nPos to the number of buttons in the toolbar
nPos = SendMessage(hwndTb, TB_BUTTONCOUNT, 0, ByVal 0&)
' Fill in the button structure
tbb.idCommand = 50 ' Change the ID to be whatever you want
tbb.iBitmap = -1 ' Change this value to indicate the index of the button icon, or -1 for no icon
tbb.iString = -1 ' If your toolbar button needs to display text, you need to send the toolbar a TB_ADDSTRING message and set iString to the value returned
tbb.fsState = TBSTATE_ENABLED
tbb.fsStyle = TBSTYLE_BUTTON
' Insert the button
SendMessage hwndTb, TB_INSERTBUTTON, nPos, tbb
' You could also have used:
SendMessage hwndTb, TB_ADDBUTTONS, 1, tbb