Trackbar and SetGadgetState

Just starting out? Need help? Post your questions and find answers here.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Trackbar and SetGadgetState

Post 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).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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. :o
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.

Code: Select all

REMOVED
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

netmaestro, he wants to intercept changes to the trackbar position instigated not by the user, but by use of the SetGadgetState() function.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

My thoughts exactly.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Well, you may look like a mule... :lol:
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

There's no may about it! :lol:
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

My friends, the path you suggest is the path to madness :P 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? :P
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
Post Reply