Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
%IDC_Toolbar = 500
Global hDlg,hLst As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Dynamic Toolbar Icons",300,300,250,100, %WS_OverlappedWindow To hDlg
CreateToolbarAndImageList
Dialog Show Modal hDlg
End Function
Sub CreateToolbarAndImageList
Randomize Timer
ImageList New Icon 24,24,32,50 To hLst
ImageList Add Icon hLst, CreateColorIcon(RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255)),16,16)
ImageList Add Icon hLst, CreateColorIcon(RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255)),16,16)
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0, %TbStyle_Flat Or %WS_Border Or %WS_Child
Toolbar Set ImageList hDlg, %IDC_Toolbar, hLst, 0 'attach imagelist
Toolbar Add Button hDlg, %IDC_Toolbar, 1, 600, %TbStyle_Button, "Color1"
Toolbar Add Button hDlg, %IDC_Toolbar, 2, 600, %TbStyle_Button, "Color2"
End Sub
Function CreateColorIcon(iColor As Long, w As Long, h As Long) As Dword
Local B As Bitmap, P As IconInfo, hBMPXor, hBMPAnd As Dword 'required variables
Graphic Bitmap New w,h To hBMPXOR : Graphic Attach hBMPXOR, 0 : Graphic Clear iColor 'Create an XOR bitmap of specified color
hBMPAND = CopyImage(hBMPXor, %Image_Bitmap, 0, 0, %LR_MonoChrome) 'create the MASK bitmap variable information
P.fIcon = %True : P.hbmColor = hBMPXOR : P.hbmMask = hBMPAND 'fill in the ICONINFO variable
Function = CreateIconIndirect (P) 'create the icon (.xHotSpot/.yHotSpot are ignored)
End Function
'gbs_01395
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm