Canvas Horizontal MouseWheel

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Canvas Horizontal MouseWheel

Post by Polo »

Hello,

Would that be possible to get horizontal mousewheel as well as the current vertical mousewhell?

Thanks!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Canvas Horizontal MouseWheel

Post by STARGÅTE »

No, because this event is not a standard windows event.
It is from your mouse driver (for example logitech).

This also applies to the forward and back buttons on the mouse.

Edit:
Example with callback:

Code: Select all

Enumeration
	#Window
	#Gadget
EndEnumeration

Enumeration
	#WM_MOUSEHWHEEL = $020E
	#WM_XBUTTONDOWN = $020B
EndEnumeration


Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
	Select Message
		Case #WM_MOUSEHWHEEL
			Debug "horizontal wheel: "+Str((wParam>>16)/120)
		Case #WM_XBUTTONDOWN
			Select wParam>>16
				Case 1
					Debug "back"
				Case 2
					Debug "forward"
			EndSelect
	EndSelect
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@MyWindowCallback(), #Window)

Repeat 
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			End
	EndSelect
ForEver
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Canvas Horizontal MouseWheel

Post by Polo »

Don't know about Windows, but on MacOSX with Carbon it's possible:
http://developer.apple.com/carbon/tipsa ... MouseWheel

As the most common application in Windows can handle any horizontal mousewheel I guess there's a way too! :)
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Canvas Horizontal MouseWheel

Post by Shardik »

Polo wrote:Would that be possible to get horizontal mousewheel as well as the current vertical mousewhell?
For Mac OS X you only needed to modify my Window handler... :wink:

Code: Select all

EnableExplicit

#kEventClassMouse = 'mous'
#kEventMouseWheelAxisX = 0
#kEventMouseWheelAxisY = 1
#kEventMouseWheelMoved = 10
#kEventParamMouseWheelAxis = 'mwax'
#kEventParamMouseWheelDelta = 'mwdl'
#typeMouseWheelAxis = 'mwax'
#typeSInt32 = 'long'
#typeUInt32 = 'magn'

Structure EventTypeSpec
  EventClass.L
  EventKind.L
EndStructure

Define EventHandlerUPP.L

Dim EventTypes.EventTypeSpec(0)

Procedure EventHandler(*NextEventHandler, Event.L, UserData.L)
  Protected MouseWheelAxis.L
  Protected MouseWheelDelta.L
  Protected WheelInfo.S

  If GetEventParameter_(Event, #kEventParamMouseWheelAxis, #typeMouseWheelAxis, 0, SizeOf(MouseWheelAxis), 0, @MouseWheelAxis) = 0
    Select MouseWheelAxis
      Case #kEventMouseWheelAxisX
        WheelInfo = "Mouse wheel moved horizontally"
      Case #kEventMouseWheelAxisY
        WheelInfo = "Mouse wheel moved vertically"
    EndSelect
  EndIf
  
  If GetEventParameter_(Event, #kEventParamMouseWheelDelta, #typeSInt32, 0, 4, 0, @MouseWheelDelta) = 0
    WheelInfo + ", Delta = " + Str(MouseWheelDelta)
    Debug WheelInfo
  EndIf
EndProcedure

OpenWindow(0, 200, 100, 130, 130, "")
CanvasGadget(0, 10, 10, 110, 110)

StartDrawing(CanvasOutput(0))
  Box(0, 0, 180, 180, RGB(249, 230, 191))
StopDrawing()

EventTypes(0)\EventClass = #kEventClassMouse
Eventtypes(0)\EventKind = #kEventMouseWheelMoved
EventHandlerUPP = NewEventHandlerUPP_(@EventHandler())
InstallEventHandler_(GetControlEventTarget_(GadgetID(0)), EventHandlerUPP, 1, @EventTypes(), @EventHandler(), 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Canvas Horizontal MouseWheel

Post by Polo »

Thanks Shardik, you've got the answer for everything when it comes to Carbon :)
Post Reply