Is there any function to detect LClick of RClick on any place of the screen?. What I am trying to do is to find a function that returns the cursor absolute coordinates (with GetCursorPos()) when I press LClick(), irrespective of any window.
Thanks
Rafael
Detecting mouse click out of a window
- Rafael Clemente
- Posts: 365
- Joined: Sat Oct 08, 2005 7:59 pm
- Location: Barcelona, Spain
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Rafael Clemente
- Posts: 365
- Joined: Sat Oct 08, 2005 7:59 pm
- Location: Barcelona, Spain
Antonio:
1.- Yes, but how can I capture the mouse all over the desktop?. I want to click anywhere in the screen and get its coords. For example:
hWnd := GetDesktopWindow() // Handle to the desktop
oWnd:bLClicked := {|r,c| MsgInfo("Clicked at "+STR(x)+STR(y)}
But how can I get oWnd from hWnd? I tried oWnd := oWndFromhWnd(hWnd) but it returns NIL
2.- GetCursorPos() works fine. The problem is capturing the click.
Rafael
1.- Yes, but how can I capture the mouse all over the desktop?. I want to click anywhere in the screen and get its coords. For example:
hWnd := GetDesktopWindow() // Handle to the desktop
oWnd:bLClicked := {|r,c| MsgInfo("Clicked at "+STR(x)+STR(y)}
But how can I get oWnd from hWnd? I tried oWnd := oWndFromhWnd(hWnd) but it returns NIL
2.- GetCursorPos() works fine. The problem is capturing the click.
Rafael
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Rafael,
To capture the mouse you use SetCapture():
The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, regardless of whether the cursor is within the borders of that window. Only one window at a time can capture the mouse.
You may do:
oWnd is your window. Not the desktop window.
From that moment on, any click, anywhere on the screen, will be routed to your oWnd:bLClicked codeblock. Same for bLButtonUp, bMButtonDown, bMButtonUp, bRClicked, bRButtonUp, bLDblClick.
To release the capture, you call ReleaseCapture() (no parameters).
The coordinates you will get are relative to the window that has captured the mouse, so if you want to locate another window from a click then you have to use WindowFromPoint( nRow, nCol ) --> hWnd. To locate a specific child control use ChildWindowFromPoint( hWndParent, aPoint ) where aPoint is { nRow, nCol }.
To capture the mouse you use SetCapture():
The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, regardless of whether the cursor is within the borders of that window. Only one window at a time can capture the mouse.
You may do:
Code: Select all
oWnd:Capture()
oWnd:bLClicked := {|r,c| MsgInfo("Clicked at "+STR(x)+STR(y)}
From that moment on, any click, anywhere on the screen, will be routed to your oWnd:bLClicked codeblock. Same for bLButtonUp, bMButtonDown, bMButtonUp, bRClicked, bRButtonUp, bLDblClick.
To release the capture, you call ReleaseCapture() (no parameters).
The coordinates you will get are relative to the window that has captured the mouse, so if you want to locate another window from a click then you have to use WindowFromPoint( nRow, nCol ) --> hWnd. To locate a specific child control use ChildWindowFromPoint( hWndParent, aPoint ) where aPoint is { nRow, nCol }.