Variant WindowMouseX()

Share your advanced PureBasic knowledge/code with the community.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Variant WindowMouseX()

Post by blueznl »

Code: Select all

global gs_windowmousedx.i, gs_windowmousedy.i

Procedure.i gs_windowmousex(windownr.i)                                               ; return window related mouse coordinate
  Protected wmx.i, dmx.i
  ;
  ; *** return window related mouse coordinate
  ;
  ; the normal windowmousex() returns -1 for any position outside the window, this returns a coordinate relative to the window interior
  ; no matter if the mouse is in- or outside the window
  ;
  wmx = WindowMouseX(windownr)
  dmx = DesktopMouseX()
  If wmx >= 0
    gs_windowmousedx = dmx-wmx
  EndIf
  ProcedureReturn DesktopMouseX()-gs_windowmousedx                  
EndProcedure

Procedure.i gs_windowmousey(windownr.i)                                               ; return window related mouse coordinate
  Protected wmy.i, dmy.i
  ;
  ; *** return window related mouse coordinate
  ;
  ; the normal windowmousex() returns -1 for any position outside the window, this returns a coordinate relative to the window interior
  ; no matter if the mouse is in- or outside the window
  ;
  wmy = WindowMouseY(windownr)
  dmy = DesktopMouseY()
  If wmy >= 0
    gs_windowmousedy = dmy-wmy
  EndIf
  ProcedureReturn DesktopMouseY()-gs_windowmousedy                  
EndProcedure
( 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... )