How can I get MouseWheel status? (api)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

How can I get MouseWheel status? (api)

Post by Joakim Christiansen »

How can I get MouseWheel status without using ExamineMouse()? :oops:
Think I need some windows-api code!
Thanks!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How can I get MouseWheel status? (api)

Post by PB »

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

If you mean to trap movements of the mousewheel, then look out for the #WM_MOUSEWHEEL message within your window callback.
I may look like a mule, but I'm not a complete ass.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

But how can I know which way it's scrolled?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

check on events, they're 511 and 512 iirc, one for up, one for down
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Detect mousewheel direction...

Code: Select all

Procedure.l WinCallback(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_MOUSEWHEEL
      If wparam < 0
        direction$ = "Scrolling towards user"
      Else
        direction$ = "Scrolling away from user"
      EndIf
      SetGadgetText(0, direction$)
  EndSelect
  ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Detect Mousewheel") And CreateGadgetList(WindowID(0))
  SetWindowCallback(@WinCallback())
  TextGadget(0, 10, 50, 280, 25, "", #PB_Text_Center)
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

blueznl wrote:check on events, they're 511 and 512 iirc, one for up, one for down
That didn't work :roll:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

This is what I've been using:

Code: Select all

If OpenWindow(0,300,300,400,200,#PB_Window_SystemMenu,"test")
  CreateGadgetList(WindowID(0))
  TextGadget(0,20,20,200,20,"Scroll the mouse wheel...")
  Repeat
    ev=WaitWindowEvent()
    If ev=#WM_MOUSEWHEEL
      If EventwParam()>0
        SetGadgetText(0,"UP")
      ElseIf EventwParam()<0
        SetGadgetText(0,"DOWN")
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Speaking of EventwParam() (and EventlParam()), when I first joined the PB Board, I saw various posts that said not to use them as they will/may no longer be supported in future versions of PB.

viewtopic.php?p=59106#59106
viewtopic.php?p=49334#49334
viewtopic.php?p=66452#66452

Well here we are 2 years later with PB 4 and there they are, still functioning. Fred :?: :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

well, these two commands aren't 'officials' but it would probably hurt if we remove it as we can't replace it with something else. So it's still here..
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks Fred. :)

I think I'll still avoid using them, even though they are there. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply