[Windows] Scroll through PanelGadget tabs
Posted: Fri May 01, 2009 3:36 pm
Keep the cursor on the "tab line" in a PanelGadget and use the mouse wheel to scroll through each tab. Mouse tilting (horizontal scrolling) is supported, too

Code: Select all
Procedure PreviousTab()
Protected point.POINT, rect.RECT, item
; Checks if the cursor is over the "tab line"
GetCursorPos_(point)
GetWindowRect_(GadgetID(0), rect)
rect\bottom = rect\top + GetGadgetAttribute(0, #PB_Panel_TabHeight)
If PtInRect_(rect, point\y << 32 + point\x)
item = GetGadgetState(0)
If item = 0 : item = CountGadgetItems(0) : EndIf
item - 1
SetGadgetState(0, item)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure NextTab()
Protected point.POINT, rect.RECT, item
; Checks if the cursor is over the "tab line"
GetCursorPos_(point)
GetWindowRect_(GadgetID(0), rect)
rect\bottom = rect\top + GetGadgetAttribute(0, #PB_Panel_TabHeight)
If PtInRect_(rect, point\y << 32 + point\x)
item = GetGadgetState(0)
If item = CountGadgetItems(0) - 1 : item = -1 : EndIf
item + 1
SetGadgetState(0, item)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure MainCallback(hWnd, uMsg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_MOUSEWHEEL ; "Standard" mouse wheel
If wParam > 0 : PreviousTab() : Else : NextTab() : EndIf
Case 526 ; Mouse tilt - horizontal mouse wheel
If wParam < 0 : PreviousTab() : Else : NextTab() : EndIf
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0, 100, 100, 500, 300, "Scroll through PanelGadget tabs")
SetWindowCallback(@MainCallback())
PanelGadget(0, 5, 5, 490, 290)
AddGadgetItem(0, -1, "Tab 1")
AddGadgetItem(0, -1, "Tab 2")
AddGadgetItem(0, -1, "Tab 3")
AddGadgetItem(0, -1, "Tab 4")
AddGadgetItem(0, -1, "Tab 5")
AddGadgetItem(0, -1, "Tab 6")
AddGadgetItem(0, -1, "Tab 7")
AddGadgetItem(0, -1, "Tab 8")
AddGadgetItem(0, -1, "Tab 9")
AddGadgetItem(0, -1, "Tab 10")
CloseGadgetList()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End