FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Detecting mouse click out of a window
Posts: 365
Joined: Sat Oct 08, 2005 07:59 PM
Detecting mouse click out of a window
Posted: Mon Jan 23, 2006 07:31 PM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Detecting mouse click out of a window
Posted: Tue Jan 24, 2006 01:02 AM

Rafael,

There are two ways to do it:

  1. You may capture the mouse, so all the mouse events get routed to your window, until you release the mouse capture.

  2. You may use a timer to call GetCursorPos() to know the mouse position on a certain time interval.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 365
Joined: Sat Oct 08, 2005 07:59 PM
Detecting mouse click out of a window
Posted: Tue Jan 24, 2006 07:59 AM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Detecting mouse click out of a window
Posted: Tue Jan 24, 2006 09:50 AM
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:Capture()
oWnd:bLClicked := {|r,c| MsgInfo("Clicked at "+STR(x)+STR(y)}


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 }.
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion