This code was written to do much the same, but for scrollbars.It uses just one API call... and that could be worked around. It allows maths and colour changes for the ToolTip data and also shows the control position when the various parts of the scroll bar are clicked. No hover...
Code: Select all
; Simple ToolTip ro report ScrollBar() position
Declare.l WinCallback(hwnd, uMsg, wParam, lParam) ; Window callback
Enumeration 1
#VS_1
#VS_2
#VS_3
#HS_1
#HS_2
#TT_Data
EndEnumeration
Enumeration 1
#MainW
#TipW
EndEnumeration
; Open test window with three vertical scroll bars and two horizontal
OpenWindow(#MainW,100,100,500,500,"Test")
ScrollBarGadget(#VS_1,20,20, 15,200,0,105,5,#PB_ScrollBar_Vertical)
ScrollBarGadget(#VS_2,120,20, 25,200,0,1005,5,#PB_ScrollBar_Vertical)
ScrollBarGadget(#VS_3,200,60,35,200,0,105,5,#PB_ScrollBar_Vertical)
ScrollBarGadget(#HS_1,20,300,320,20,0,1005,5)
ScrollBarGadget(#HS_2,20,350,350,30,0,105,5)
; A small window and text gadget used for reporting values
OpenWindow(#TipW,0,0,40,15,"",#PB_Window_Invisible | #PB_Window_BorderLess)
StickyWindow(2,#True)
TextGadget(#TT_Data,0,0,40,15,"",#PB_Text_Center)
SetGadgetColor(#TT_Data, #PB_Gadget_BackColor,#Yellow)
; Start window callback
SetWindowCallback(@WinCallback())
; Skeleton event manager
Finish.w = #False
Repeat
Select WaitWindowEvent(5)
Case #PB_Event_CloseWindow ; Close windows
Finish = #True
EndSelect
Until Finish = #True
End
Procedure.l WinCallback(hwnd, uMsg, wParam, lParam) ;- Window callback
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_VSCROLL ;{- VERTICAL scroll bars
If wParam <> 8
G = GetDlgCtrlID_(lParam) ; Get Gadget# corresponding to ID
v = GetGadgetState(G) ; Get current slider value
x = WindowX(#MainW) + GadgetX(G)+GadgetWidth(G)+4 ; X position for data display
y = WindowY(#MainW) + GadgetY(G)+15+18 + Int(v/GetGadgetAttribute(G,#PB_ScrollBar_Maximum)* (GadgetHeight(G)-30)); Y...
; Format dispalyed data specific to each scrollbar
Select G
Case #VS_1
SetGadgetText(#TT_Data,Str(v))
Case #VS_2
SetGadgetText(#TT_Data,StrF(100*v/1000,1)+"%")
Case #VS_3
SetGadgetText(#TT_Data,Str(50-v))
If v<50
SetGadgetColor(#TT_Data, #PB_Gadget_BackColor,#Red)
Else
SetGadgetColor(#TT_Data, #PB_Gadget_BackColor,#Green)
EndIf
EndSelect
ResizeWindow(#TipW,x,y, #PB_Ignore, #PB_Ignore) ; Position the data window
HideWindow(#TipW,#False) ; Reveal it
Else ; Mouse UP
HideWindow(#TipW,#True) ; Hide the data window
SetGadgetColor(#TT_Data, #PB_Gadget_BackColor,#Yellow) ; Re-colour with default
EndIf
;}
Case #WM_HSCROLL ;{- HORIZONTAL scroll bars
If wParam <> 8
G = GetDlgCtrlID_(lParam) ; Get Gadget#
v = GetGadgetState(G) ; Current value
x = WindowX(#MainW) + GadgetX(G) + 15 + Int(v/GetGadgetAttribute(G,#PB_ScrollBar_Maximum)* (GadgetWidth(G)-30)) - WindowWidth(2)/2
y = WindowY(#MainW) + 18 + GadgetY(G) - WindowHeight(2)
SetGadgetText(#TT_Data,Str(v)) ; Put result in data window
ResizeWindow(#TipW,x,y, #PB_Ignore, #PB_Ignore) ; Position the data window
HideWindow(#TipW,#False) ; Reveal it
Else ; Mouse UP
HideWindow(#TipW,#True) ; Hide the data window
SetGadgetColor(#TT_Data, #PB_Gadget_BackColor,#Yellow) ; Re-colour with default
EndIf
;}
EndSelect
ProcedureReturn Result
EndProcedure