Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource Icon x "x.ico"
#Resource Icon y "y.ico"
#Resource Icon z "z.ico"
#Resource Icon xtype "type.ico"
Enum Equates Singular
IDC_Toolbar = 500
IDC_Button
IDT_X
IDT_Y
IDT_Z
End Enum
Global hDlg, hLst, hToolbar As Dword
Function PBMain()
'create dialog
Dialog Default Font "Tahoma", 10, 0
Dialog New Pixels, 0, "Toolbar Image Test",,, 200,150, %WS_SysMenu, To hDlg
Dialog Set Color hDlg, %White, %White
Dialog Set Icon hDlg, "x"
Control Add Button, hDLg, %IDC_Button, "Change Icon of Button #2", 10,80,165,25
'add toolbar
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0, %CCS_NoMoveY
Control Handle hDlg, %IDC_Toolbar To hToolbar
'create imagelist
ImageList New Icon 16,16,32,3 To hLst
ImageList Add Icon hLst, "x" '1
ImageList Add Icon hLst, "y" '2
ImageList Add Icon hLst, "z" '3
ImageList Add Icon hLst, "xtype" '4
'attach imagelist
Toolbar Set ImageList hDlg, 500, hLst, 0
'create buttons
Toolbar Add Button hDlg, %IDC_Toolbar, 1, %IDT_X, %TbStyle_Button, "x"
Toolbar Add Button hDlg, %IDC_Toolbar, 2, %IDT_Y, %TbStyle_Button, "y"
Toolbar Add Button hDlg, %IDC_Toolbar, 3, %IDT_Z, %TbStyle_Button, "z"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Toolbar_SetIcon hToolbar, %IDT_Y, 2 'toolbar handle, button ID, image index in imagelist (zero based)
End Select
End Select
End Function
Function Toolbar_SetIcon(hToolbar As Dword, cID As Dword, ImageIndex As Long) As Long
Local ToolBarButtonInfo As TBBUTTONINFO
Toolbar_GetButtonInfo hToolbar, cID, ToolbarButtonInfo
ToolBarButtonInfo.cbSize = SizeOf(TBBUTTONINFO)
ToolBarButtonInfo.dwMask = %TBIF_IMAGE Or %TBIF_COMMAND
ToolBarButtonInfo.iImage = 3
SendMessage(hToolbar, %TB_SETBUTTONINFO, cID, VarPtr(ToolBarButtonInfo))
End Function
http://www.garybeene.com/sw/gbsnippets.htm