Date: 02-16-2022
Return to Index
created by gbSnippets
'Several standard bitmaps are available from the commctrl32.dll file. These
'bitmaps can be used in a Toolbar control as an alternative to using a resource
'file to populate an imagelist.
'Primary Code:
'Two structures TBButton and TBAddBitmap are used to define the buttons
'and to select the bitmap for use in the toolbar.
Sub CreateToolbarButtons
Dim B(1) as TBButton, BMP As TBADDBITMAP
'create buttons
B(0).idCommand = %IDC_NEW
B(0).fsState = %TBSTATE_ENABLED
B(0).fsStyle = %TBSTYLE_BUTTON
B(0).iBitmap = %STD_FILENEW
B(1).idCommand = %IDC_OPEN
B(1).fsState = %TBSTATE_ENABLED
B(1).fsStyle = %TBSTYLE_BUTTON
B(1).iBitmap = %STD_FILEOPEN
BMP.hInst = %HINST_COMMCTRL
BMP.nID = %IDB_STD_SMALL_COLOR
'use OS (commctrl) std bitmap
SendMessage hToolbar, %TB_ADDBITMAP, 0, VarPTR(BMP)
End Sub
'The six bitmaps available in comctl32.dll are:
IDB_VIEW_LARGE_COLOR
IDB_VIEW_SMALL_COLOR
IDB_STD_LARGE_COLOR
IDB_STD_SMALL_COLOR
IDB_HIST_LARGE_COLOR
IDB_HIST_SMALL_COLOR
'PowerBASIC equates describing the individual images in the six bitmaps are:
HIST_BACK, HIST_FORWARD, HIST_FAVORITES, HIST_ADDTOFAVORITES, HIST_VIEWTREE
STD_CUT, STD_COPY, STD_PASTE, STD_UNDO, STD_REDOW, STD_DELETE, STD_FILENEW
STD_FILEOPEN, STD_FILESAVE, STD_PRINTPRE, STD_PROPERTIES, STD_HELP, STD_FIND
STD_REPLACE, STD_PRINT
VIEW_LARGEICONS, VIEW_SMALLICONS, VIEW_LIST, VIEW_DETAILS, VIEW_SORTNAME
VIEW_SORTSIZE, VIEW_SORTDATE, VIEW_SORTTYPE, VIEW_PARENTFOLDER
VIEW_NETCONNECT, VIEW_NETDISCONNECT, VIEW_NEWFOLDER
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
%IDC_New = 600 : %IDC_Open = 601 : %IDC_Toolbar = 700
Global hDlg As DWord, hToolbar as DWord
Function PBMain()
'create dialog
Dialog New Pixels, 0, "Toolbar Test",,, 500,250, %WS_SysMenu, To hDlg
'add toolbar and toolbar buttons and toolbar imagelist (from standard bitmap)
CreateToolbarButtons
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = %IDC_New Then MsgBox "Pushed New!"
If CB.Msg = %WM_Command AND CB.Ctl = %IDC_Open Then MsgBox "Pushed Open!"
End Function
Sub CreateToolbarButtons
Dim B(1) as TBButton, BMP As TBADDBITMAP
'create buttons
B(0).idCommand = %IDC_NEW
B(0).fsState = %TBSTATE_ENABLED
B(0).fsStyle = %TBSTYLE_BUTTON
B(0).iBitmap = %STD_FILENEW
B(1).idCommand = %IDC_OPEN
B(1).fsState = %TBSTATE_ENABLED
B(1).fsStyle = %TBSTYLE_BUTTON
B(1).iBitmap = %STD_FILEOPEN
BMP.hInst = %HINST_COMMCTRL
BMP.nID = %IDB_STD_SMALL_COLOR
'create toolbar
hToolbar = CreateToolbarEx(hDlg, %WS_CHILD Or %TBSTYLE_TOOLTIPS Or %TBSTYLE_FLAT Or %TBSTYLE_TRANSPARENT, _
%IDC_TOOLBAR, 0, %NULL, 0, B(0), UBound(B)+1, 16, 16, 0, 0, Len(TBBUTTON))
'use CommCtrl std bitmap
SendMessage hToolbar, %TB_ADDBITMAP, 0, VarPTR(BMP)
Control Redraw hDlg, %IDC_Toolbar
ShowWindow hToolBar, %SW_SHOW
End Sub
'gbs_00289
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm