Detecting mouse click out of a window

Detecting mouse click out of a window

Postby Rafael Clemente » Mon Jan 23, 2006 7: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
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Postby Antonio Linares » Tue Jan 24, 2006 1: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rafael Clemente » Tue Jan 24, 2006 7: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
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Postby Antonio Linares » Tue Jan 24, 2006 9: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:

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests