Event for scrolling of ScrollAreaGadget?

Just starting out? Need help? Post your questions and find answers here.
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Event for scrolling of ScrollAreaGadget?

Post by mesozorn »

What would be the best way to capture an event WHILE the user is scrolling the scrollbars of a ScrollAreaGadget? #WM_ACTIVATE only works when the user initially clicks the scrollbar and then later lets go, and #WM_MOUSEMOVE also stops reporting while the user is moving a scrollbar.

I need to be able to track the #PB_ScollArea_X and #PB_ScrollArea_Y while it is being moved by the user, rather than just after the user has let go of the mouse button and chosen a final landing position.

Is there an easy way to do this? Thanks...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Event for scrolling of ScrollAreaGadget?

Post by srod »

#WM_HSCROLL, #WM_VSCROLL and #WM_MOUSEWHEEL are probably what you are after. You'll need to subclass the scrollarea first though.
I may look like a mule, but I'm not a complete ass.
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Re: Event for scrolling of ScrollAreaGadget?

Post by mesozorn »

srod wrote:#WM_HSCROLL, #WM_VSCROLL and #WM_MOUSEWHEEL are probably what you are after. You'll need to subclass the scrollarea first though.
Thanks.. So far I haven't had any luck getting the #WM_VSCROLL/#WM_HSCROLL messages to show up, but my knowledge of the API is admittedly very limited. Is there an example that you know of anywhere that might provide further guidance?
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Event for scrolling of ScrollAreaGadget?

Post by Arctic Fox »

Try this

Code: Select all

Global OldSubclass

Procedure ScrollCallback(Handle, Message, wParam, lParam)

Select Message
Case #WM_HSCROLL
Debug "#WM_HSCROLL"

Case #WM_VSCROLL
Debug "#WM_VSCROLL"
EndSelect

ProcedureReturn CallWindowProc_(OldSubclass, Handle, Message, wParam, lParam)
EndProcedure

OpenWindow(0, 100, 100, 300, 300, "")
ScrollAreaGadget(0, 5, 5, 290, 290, 500, 500, 30)
StringGadget(1, 5, 5, 100, 20, "Gadget 1")
StringGadget(2, 305, 405, 100, 20, "Gadget 2")
CloseGadgetList()

OldSubclass = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @ScrollCallback())

Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Re: Event for scrolling of ScrollAreaGadget?

Post by mesozorn »

Thanks Arctic Fox, that's great and much appreciated. I am learning the API a little at a time, but callbacks and subclassing are still mostly foreign to me so I wouldn't likely have stumbled onto the right syntax without assistance.
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Event for scrolling of ScrollAreaGadget?

Post by Arctic Fox »

You are welcome :)
When you are ready to learn more about subclassing, you should definitely have a look at srod's tutorial (see the nxSoftware website.)
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Re: Event for scrolling of ScrollAreaGadget?

Post by mesozorn »

Arctic Fox wrote:You are welcome :)
When you are ready to learn more about subclassing, you should definitely have a look at srod's tutorial (see the nxSoftware website.)
Wow, I just read through the entire thing and it was both extremely helpful and excellently written. Thanks for the direction to it and thanks srod for writing it in the first place. Though the API in general is still somewhat of a big daunting dragon to me, I now feel that I am at least equipped with a nice shiny new dagger with which to do battle, as opposed to the wooden toothpick I was brandishing before. Perhaps someday I'll wield a powerful broadsword like srod does but I wouldn't count on it anytime soon! 8)
Post Reply