Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
#Resource Icon test, "test.ico"
Global hDlg,hLst As Dword, EW,BW,First,Last,BMax,BCount As Long
Enum Equates Singular
IDC_Toolbar = 150
IDM_Previous
IDM_Next
IDM_Misc
End Enum
Function PBMain()
Local i As Long
Dialog New Pixels, 0, "Toolbar Test",,, 500,250, %WS_OverlappedWindow, To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
First = 1 : Last = 17 : EW = 31 : BW = 31 : BMax = 35
ImageList New Icon 24,24,24,1 To hLst
ImageList Add Icon hLst, "test"
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_Previous 'previous - add button on left
If First > 1 Then
Toolbar Delete Button hDlg, %IDC_Toolbar, BCount+1
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Misc+First-1, %TbStyle_Button, Str$(First-1) At 2
Decr First : Decr Last
End If
Case %IDM_Next 'next - remove button on right
If Last < BMax Then
Toolbar Delete Button hDlg, %IDC_Toolbar, 2
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Misc+Last+1, %TbStyle_Button, Str$(Last+1) At BCount+1
Incr First : Incr Last
End If
End Select
Case %WM_Size
Dialog Get Client hDlg To w,h
BCount = (w-2*EW)\BW
Last = First + BCount -1
CreateToolbar
End Select
End Function
Sub CreateToolbar
Local i As Long
Control Kill hDlg, %IDC_Toolbar
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0, %CCS_NoMoveY
Toolbar Set ImageList hDlg, %IDC_Toolbar, hLst, 0
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Previous, %TbStyle_Button, "Prev"
For i = First To Last
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Misc+i, %TbStyle_Button, Str$(i)
Next i
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Next, %TbStyle_Button, "Next"
End Sub
'gbs_01186
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm