Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes I want a few icons but don't want to create a new PRB file, nor include
'one in an EXE because of the increase in size that results. There are standard
'icons in the comctrl32.dll file which can be accessed.
'It requires creation of a toolbar, which contains an internal imagelist that can
'be used to hold the icons. The icons in that imagelist can then be used with
'GRAPHIC statements.
'Primary Code:
Local BMP As TBADDBITMAP, i As Long
Control Add Toolbar, hDlg, %IDC_Toolbar1,"", 0,0,0,0, %WS_Child 'add toolbar, NOT visible
BMP.hInst = %HINST_COMMCTRL
BMP.nID = %IDB_STD_SMALL_COLOR
Control Send hDlg, %IDC_Toolbar1, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
Control Send hDlg, %IDC_Toolbar1, %TB_GETIMAGELIST, 0, 0 To hLstSmall 'handle of image list created by API
ImageList Get Count hLstSmall To i 'necessary to access imagelist with Graphic statements
'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, hToolbar1 As DWord, hToolbar2 As DWord
Global hLstSmall As DWord, hLstLarge As DWord
%IDC_Toolbar1 = 700 : %IDC_Toolbar2 = 750 : %ID_Graphic = 800
Function PBMain()
Local i As Long, x As Long, y As Long
Dialog New Pixels, 0, "Toolbar Test",,, 675,200, %WS_SysMenu, To hDlg
CreateSmallImageList 'uses hLst global value
CreateLargeImageList 'uses hLst global value
Control Add Graphic, hDlg, %ID_Graphic, "", 10,10,650,150
Graphic Attach hDlg, %ID_Graphic
'display small icons
For i = 1 To 32
x = (i-1) * 20 : y = 10
Graphic ImageList (x,y), hLstSmall, i, 0, %ILD_Normal 'try GRAPHIC command to send copy icon from toolbar imagelist to Graphic Control
Next i
'display large icons
For i = 1 To 32
If i < 17 Then
x = (i-1) * 40 : y = 60
Else
x = (i-17) * 40 : y = 100
End If
Graphic ImageList (x,y), hLstLarge, i, 0, %ILD_Normal 'try GRAPHIC command to send copy icon from toolbar imagelist to Graphic Control
Next i
Dialog Show Modal hDlg
End Function
Sub CreateSmallImagelist
'adds all 3 small icon bitmaps from the comctl32.dll images - total of 32 icons
Local BMP As TBADDBITMAP, i As Long
Control Add Toolbar, hDlg, %IDC_Toolbar1,"", 0,0,0,0, %WS_Child 'add toolbar, NOT visible
BMP.hInst = %HINST_COMMCTRL
BMP.nID = %IDB_STD_SMALL_COLOR
Control Send hDlg, %IDC_Toolbar1, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
BMP.nID = %IDB_VIEW_SMALL_COLOR
Control Send hDlg, %IDC_Toolbar1, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
BMP.nID = %IDB_HIST_SMALL_COLOR
Control Send hDlg, %IDC_Toolbar1, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
Control Send hDlg, %IDC_Toolbar1, %TB_GETIMAGELIST, 0, 0 To hLstSmall 'handle of image list created by API
ImageList Get Count hLstSmall To i 'necessary to access imagelist with Graphic statements
End Sub
Sub CreateLargeImagelist
'adds all 3 large icon bitmaps from the comctl32.dll images - total of 32 icons
Local BMP As TBADDBITMAP, i As Long
Control Add Toolbar, hDlg, %IDC_Toolbar2,"", 0,0,0,0, %WS_Child 'add toolbar, NOT visible
BMP.hInst = %HINST_COMMCTRL
BMP.nID = %IDB_STD_LARGE_COLOR
Control Send hDlg, %IDC_Toolbar2, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
BMP.nID = %IDB_VIEW_LARGE_COLOR
Control Send hDlg, %IDC_Toolbar2, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
BMP.nID = %IDB_HIST_LARGE_COLOR
Control Send hDlg, %IDC_Toolbar2, %TB_ADDBITMAP, 0, VarPTR(BMP) 'add comctrl32.dll icons to internal toolbar imagelist
Control Send hDlg, %IDC_Toolbar2, %TB_GETIMAGELIST, 0, 0 To hLstLarge 'handle of image list created by API
ImageList Get Count hLstLarge To i 'necessary to access imagelist with Graphic statements
End Sub
'gbs_00469
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm