Date: 02-16-2022
Return to Index
created by gbSnippets
'Several standard bitmaps are available from the comctl32.dll file. These
'bitmaps can be used in a Toolbar control as an alternative to using images
'from a resource file (*.pbr). The approach creates an imagelist without
'having to use the DDT imagelist commands.
'Primary Code:
'Credit: Dave Biggs
'The TBAddBitmap structure is used to define the bitmaps
'which are merged into an imagelist for the toolbar.
Dim BMP As TBADDBITMAP, BMP2 As TBADDBITMAP, BMP3 As TBADDBITMAP
'define 3 images - 2 from standard bitmpas (comctl32.dll) and one from file on disk
BMP.hInst = %HINST_COMMCTRL ' System defined 'standard' bitmaps
BMP.nID = %IDB_STD_SMALL_COLOR
BMP2.hInst = %HINST_COMMCTRL ' System defined 'standard' bitmaps
BMP2.nID = %IDB_HIST_SMALL_COLOR
hBmp = LoadImage(0, "16x16.bmp", %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE) ' 16x16.bmp in app folder
BMP3.hInst = 0 ' User supplied bitmap
BMP3.nID = hBmp
'add all 3 bitmaps to imagelist
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP) ' add to list of button images
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP2) ' add to list of button images
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP3) ' add to list of button images
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
Global hDlg As Dword, hLst As Dword, hToolbar as Dword, hBmp As Dword
%IDC_Toolbar = 700
Function PBMain()
Dim BMP As TBADDBITMAP, BMP2 As TBADDBITMAP, BMP3 As TBADDBITMAP
'create dialog
Dialog New Pixels, 0, "Toolbar Test",,, 500,250, %WS_SysMenu, To hDlg
'add toolbar
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0
Control Handle hDlg, %IDC_Toolbar to hToolbar
'define 3 images - 2 from standard bitmpas (comctl32.dll) and one from file on disk
BMP.hInst = %HINST_COMMCTRL ' System defined 'standard' bitmaps
BMP.nID = %IDB_STD_SMALL_COLOR
BMP2.hInst = %HINST_COMMCTRL ' System defined 'standard' bitmaps
BMP2.nID = %IDB_HIST_SMALL_COLOR
Graphic Bitmap Load "16x16.bmp", 16, 16 TO hBMP 'file is loaded, but not visible
' hBmp = LoadImage(0, "16x16.bmp", %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE) ' 16x16.bmp in app folder
BMP3.hInst = 0 ' User supplied bitmap
BMP3.nID = hBmp
'add all 3 bitmaps to imagelist
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP) ' add to list of button images
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP2) ' add to list of button images
Control Send hDlg, %IDC_Toolbar, %TB_ADDBITMAP, 0, VarPTR(BMP3) ' add to list of button images
' create buttons from fist toolbar bitmap (%STD_CUT to %STD_PRINT)
Toolbar Add Button hDlg, %IDC_Toolbar, %STD_FILENEW+1, 200, %TbStyle_Button, "New"
Toolbar Add Button hDlg, %IDC_Toolbar, %STD_FILEOPEN+1, 201, %TbStyle_Button, "Open"
' create buttons from second toolbar bitmap (%HIST_BACK to %HIST_FORWARD)
Toolbar Add Button hDlg, %IDC_Toolbar, %STD_PRINT+1 + %HIST_BACK+1, 202, %TbStyle_Button, "Back"
Toolbar Add Button hDlg, %IDC_Toolbar, %STD_PRINT+1 + %HIST_FORWARD+1, 203, %TbStyle_Button, "Forward"
' create button from individual bitmap added to end of image list
Toolbar Add Button hDlg, %IDC_Toolbar, %STD_PRINT+1 + %HIST_VIEWTREE+1 + 1, 204, %TbStyle_Button, "Your Btn"
'show the dialog
Dialog Show Modal hDlg Call DlgProc
DeleteObject hBmp ' Free bitmap resources
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 200 Then MsgBox "New"
If CB.Msg = %WM_Command AND CB.Ctl = 201 Then MsgBox "Open"
If CB.Msg = %WM_Command AND CB.Ctl = 202 Then MsgBox "Back"
If CB.Msg = %WM_Command AND CB.Ctl = 203 Then MsgBox "Forward"
If CB.Msg = %WM_Command AND CB.Ctl = 204 Then MsgBox "Etcetera"
End Function
'gbs_00294
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm