Page 1 of 1

How can I get MouseWheel status? (api)

Posted: Wed Feb 08, 2006 10:25 pm
by Joakim Christiansen
How can I get MouseWheel status without using ExamineMouse()? :oops:
Think I need some windows-api code!
Thanks!

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

Posted: Wed Feb 08, 2006 10:35 pm
by PB

Posted: Wed Feb 08, 2006 10:37 pm
by srod
If you mean to trap movements of the mousewheel, then look out for the #WM_MOUSEWHEEL message within your window callback.

Posted: Thu Feb 09, 2006 4:08 pm
by Joakim Christiansen
But how can I know which way it's scrolled?

Posted: Thu Feb 09, 2006 4:22 pm
by blueznl
check on events, they're 511 and 512 iirc, one for up, one for down

Posted: Thu Feb 09, 2006 6:21 pm
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

Posted: Thu Feb 09, 2006 6:25 pm
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:

Posted: Thu Feb 09, 2006 9:19 pm
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

Posted: Thu Feb 09, 2006 10:06 pm
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 :?: :?

Posted: Thu Feb 09, 2006 10:08 pm
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..

Posted: Thu Feb 09, 2006 10:16 pm
by Sparkie
Thanks Fred. :)

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