Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg,hLst As Dword, BW, BMax As Long
Enum Equates Singular
IDC_Toolbar = 150
IDC_Scrollbar
IDM_Misc
End Enum
Function PBMain()
Dialog New Pixels, 0, "Toolbar Test",,, 500,250, %WS_OverlappedWindow To hDlg
Control Add ScrollBar, hDlg, %IDC_Scrollbar,"", 0,50,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h,iPos As Long
Select Case Cb.Msg
Case %WM_InitDialog
BMax = 35 : BW = 31
ScrollBar Set Pagesize hDlg, %IDC_Scrollbar, 25
ScrollBar Set Pos hDlg, %IDC_Scrollbar, 1
ScrollBar Set Range hDlg, %IDC_Scrollbar, 1, BW*BMax
CreateToolbar
Case %WM_HScroll
Dialog Get Client hDlg To w,h
ScrollBar Get Pos hDlg, %IDC_ScrollBar To iPos
Select Case Lo(Word, Cb.WParam)
Case %SB_LineLeft : iPos -= BW
Case %SB_PageLeft : iPos -= 5*BW
Case %SB_LineRight : iPos += BW
Case %SB_PageRight : iPos += 5*BW
Case %SB_ThumbTrack : iPos=Hi(Word, Cb.WParam)
End Select
ScrollBar Set Pos hDlg, %IDC_Scrollbar, iPos
Control Set Loc hDlg, %IDC_Toolbar, -iPos,0
Control ReDraw hDlg, %IDC_Toolbar
Dialog ReDraw hDlg
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_Scrollbar, w,20
ScrollBar Set Range hDlg, %IDC_Scrollbar, 1, BW*(BMax+1)-w
End Select
End Function
Sub CreateToolbar
Local i As Long
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,BW*BMax,50, %CCS_NoResize
ImageList New Icon 24,24,24,1 To hLst
Toolbar Set ImageList hDlg, %IDC_Toolbar, hLst, 0
For i = 1 To BMax
Toolbar Add Button hDlg, %IDC_Toolbar, 0, %IDM_Misc+i, %TbStyle_Button, Str$(i)
Next i
End Sub
'gbs_01232
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm