Page 1 of 2
Trackbar and SetGadgetState
Posted: Sat May 06, 2006 8:25 am
by dmoc
I have a trackbar that is used as an indicator, ie, changed using SetGadgetState(). What EventType/#WM_???? tells me it has changed? I want to update a text control when the bars value changes, possibly from several places so I want to capture an event. Another situation is where a trackbar is used for both input and output (at different times).
Posted: Sat May 06, 2006 11:01 am
by srod
In a window callback, use #WM_HSCROLL and check the lParam for the handle of the control etc.
This event doesn't seem to fire within a normal PB event loop for these controls as PB swallows the message.
Posted: Sat May 06, 2006 11:03 am
by josku_x
Now I understand why my attemps don't work.
I hoped to help dmoc, but thanks to you srod now one more thing is clear here.

Posted: Sat May 06, 2006 11:22 am
by dmoc
Thanks for the reply srod but the callback is not getting #WM_HSCROLL or #WM_VSCROLL (it's a vertical trackbar) messages when SetGadgetState() is called even though the trkbar is visibly changing.
PS: This is PB v4b11 if it makes any difference
Posted: Sat May 06, 2006 11:27 am
by srod
Sorry, I didn't read the bit about SetGadgetState(). Back in a mo...
The following works here ok. Also on PB 4 -b11.
Posted: Sat May 06, 2006 11:39 am
by srod
dmoc, it's true the #TBM_SETPOS message doesn't seem to fire off any messages (at least at first glance). I guess the thing is, why would you need to intercept a message when your code is actually changing the track position anyhow? Surely you can set the contents of the text gadget at the same time?
I'll keep looking however.
Posted: Sat May 06, 2006 11:43 am
by netmaestro
This works here:
Code: Select all
Procedure Callback(hwnd, message, wparam, lparam)
If message = #WM_VSCROLL
If wparam & $FFFFFFFF = #SB_ENDSCROLL
Debug "Changed!"
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,640,480,"VistaClock dll Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
TrackBarGadget(0,200,50,20,200,64,320,#PB_TrackBar_Vertical)
SetWindowCallback(@callback())
Repeat
EventID=WaitWindowEvent()
Until EventID=#PB_Event_CloseWindow
Posted: Sat May 06, 2006 11:49 am
by srod
netmaestro, he wants to intercept changes to the trackbar position instigated not by the user, but by use of the SetGadgetState() function.
Posted: Sat May 06, 2006 11:53 am
by netmaestro
Why does that need trapped when the program already knows it just set the gadget state? And anyways, you can always put GetGadgetState in the loop and store its values.
Posted: Sat May 06, 2006 11:55 am
by srod
My thoughts exactly.
Posted: Sat May 06, 2006 11:57 am
by netmaestro
Well, you may look like a mule...

Posted: Sat May 06, 2006 12:02 pm
by srod
There's no may about it!

Posted: Sat May 06, 2006 12:06 pm
by srod
dmoc, one completely unsubtle approach is to subclass the TrackBar and intercept it's #WM_PAINT event.
Code: Select all
Global oldproc
Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
Select Message
Case #WM_PAINT
Debug 1
EndSelect
ProcedureReturn CallWindowProc_(oldproc, WindowID, Message, wParam, lParam)
EndProcedure
If OpenWindow(0, 0, 0, 320, 200, "TrackBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
TextGadget (3, 10, 40, 250, 20,"TrackBar Standard", #PB_Text_Center)
TrackBarGadget(0, 10, 60, 250, 20, 0, 10000)
ButtonGadget(1,10,10,100,20,"Click!")
oldproc=SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @MyWindowCallback())
SetGadgetState(0, 5000)
Repeat
ev=WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetState(0, 6000)
EndSelect
EndSelect
Until ev = #PB_Event_CloseWindow
EndIf
It aint pretty though!
Posted: Sat May 06, 2006 12:09 pm
by dmoc
My friends, the path you suggest is the path to madness

I speak now of only one control and one dependent control. But a time may come when there are many controls each of which beget yet more controls. And so a multitude of controls and message thus go forth and hence forth chaos shall rule the world.
You see now how important it is that we find an answer and save the world?

Posted: Sat May 06, 2006 12:16 pm
by srod
The following avoids subclassing and only fires for the the specified trackbar.
However, I've no idea what message corresponds to 312!!!
Code: Select all
Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case 312
If lparam=GadgetID(0)
Debug "Trackbar changed!"
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(0, 0, 0, 320, 200, "TrackBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
TextGadget (3, 10, 40, 250, 20,"TrackBar Standard", #PB_Text_Center)
TrackBarGadget(0, 10, 60, 250, 20, 0, 10000)
ButtonGadget(1,10,10,100,20,"Click!")
SetWindowCallback(@MyWindowCallback(),0)
;SetGadgetState(0, 5000)
Repeat
ev=WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetState(0, 6000)
EndSelect
EndSelect
Until ev = #PB_Event_CloseWindow
EndIf