MouseEvent code. WindowFromPoint_ return bad value (SOLVED)

Just starting out? Need help? Post your questions and find answers here.
Mike Yurgalavage
Enthusiast
Enthusiast
Posts: 118
Joined: Thu May 17, 2007 8:35 pm
Location: USA

MouseEvent code. WindowFromPoint_ return bad value (SOLVED)

Post by Mike Yurgalavage »

There is a great little code here that simplifies catching mouse events:

http://www.purebasic.fr/english/viewtop ... et#p349606


However, I am finding that some of the users of my software, the code fails when they are mousing over gadgets and whatnot on OTHER MONITORS/Desktops. I.e. the main monitor, the program works without fail. Drag the window to a second monitor, in some cases the 'events' are never captured.

I think I have managed to isolate that maybe the problem is the code here:

Code: Select all

Window = WindowFromPoint_(MouseEvent_MouseY<<32|MouseEvent_MouseX)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

and that the proper 'window' is never being gathered due to it being in another monitor?

Is there a fix for this, or does someone know this windows API call function (or a different call to make sure that this Window is obtained)? Maybe there is a better api call to gather the WINDOW handle that the mouse is over, even on multiple monitors?

This code/handle gathering API call is probably to help with gadgets that open up from the same app in multiple windows from the same app. The coder of this nice code project probably didn't anticipate multiple monitors/desktops, etc.

Any help is appreciated!

Always an amazing product with Purebasic and the forums here are second to none.

*EDIT The solution was to fix the math, which was not working when the user dragged app window to monitor on left, which was negative values. Here is the proper code to fix it

Code: Select all

Window = WindowFromPoint_(DesktopMouseY()<<32 + DesktopMouseX())
Note we ADD DesktopMouseX() instead of OR.



best,
Mike
Last edited by Mike Yurgalavage on Mon Mar 06, 2017 1:57 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: MouseEvent code. Can someone help figure out my problem?

Post by mk-soft »

Perhaps help this. It´s from my Module MouseOver. Link: http://www.purebasic.fr/german/viewtopi ... =8&t=29047

Code: Select all

CompilerSelect #PB_Compiler_OS
        CompilerCase #PB_OS_Windows
          Protected desktop_x, desktop_y
          desktop_x = DesktopMouseX()
          desktop_y = DesktopMouseY()
          handle = WindowFromPoint_(desktop_y << 32 | desktop_x)
        CompilerCase #PB_OS_MacOS
          Protected win_id, win_cv, pt.NSPoint
          win_id = WindowID(EventWindow())
          win_cv = CocoaMessage(0, win_id, "contentView")
          CocoaMessage(@pt, win_id, "mouseLocationOutsideOfEventStream")
          handle = CocoaMessage(0, win_cv, "hitTest:@", @pt)
        CompilerCase #PB_OS_Linux
          Protected desktop_x, desktop_y, *GdkWindow.GdkWindowObject
          *GdkWindow.GdkWindowObject = gdk_window_at_pointer_(@desktop_x,@desktop_y)
          If *GdkWindow
            gdk_window_get_user_data_(*GdkWindow, @handle)
          Else
            handle = 0
          EndIf
      CompilerEndSelect
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Mike Yurgalavage
Enthusiast
Enthusiast
Posts: 118
Joined: Thu May 17, 2007 8:35 pm
Location: USA

Re: MouseEvent code. Can someone help figure out my problem?

Post by Mike Yurgalavage »

Thanks for sharing. I will try some code changes to see if this helps, based on your code.

However, I would like to know exactly WHY this is occurring or if people know a fix for my current code.

Bump for more views and possible tests from people and replies?

thx,
Mike
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: MouseEvent code. Can someone help figure out my problem?

Post by #NULL »

i'm not shure but maybe depending on the display arrangement you could get also negative mouse coordinates, in which case the above method won't work correctly if the variables are of type quad, like the default integer on x64. explicit long type may help.
Mike Yurgalavage
Enthusiast
Enthusiast
Posts: 118
Joined: Thu May 17, 2007 8:35 pm
Location: USA

Re: MouseEvent code. WindowFromPoint_ return bad value (SOL

Post by Mike Yurgalavage »

SOLUTION is


The solution was to fix the math, which was not working when the user dragged app window to monitor on left, which was negative values. Here is the proper code to fix it

Code: Select all

Window = WindowFromPoint_(DesktopMouseY()<<32 + DesktopMouseX())
Note we ADD DesktopMouseX() instead of OR.


Maybe this will help someone who is using similar code.

best,
Mike
Post Reply