How determine if mouse points to(hover on) maximise button of window even if this window is not of my application. Is there API for that ?
Asked
Active
Viewed 268 times
0
-
What programming language are you talking about? – Vinit Feb 01 '12 at 20:36
-
[GetTitleBarInfo](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633513(v=vs.85).aspx) looks very promising. – Raymond Chen Feb 01 '12 at 21:18
-
@Raymond, that API appears to only tell whether the button is *visible* or *pressed*, but not whether the mouse is merely *hovering* over the button. – Rob Kennedy Feb 01 '12 at 22:38
-
valdo's got your answer, but this sounds suspiciously like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. I'm sure there's a better way than the proposed solution you've invented. – Cody Gray - on strike Feb 02 '12 at 04:30
-
@RobKennedy It also gives you the coordinates of the button, which you can use to determine whether the mouse is in it. – Raymond Chen Feb 02 '12 at 05:45
-
Where, @Raymond? `TITLEBARINFO` has the coordinates of the whole title bar, plus an array for the states of the buttons. I don't see an array of coordinates or any way to tell the API which button you're interested in the coordinates of. – Rob Kennedy Feb 02 '12 at 14:47
-
@RobKennedy Oops, you're right. I had it confused with the other accessibility interface `IAccessible`, which has a `get_accLocation` method. – Raymond Chen Feb 02 '12 at 18:21
1 Answers
5
You may send a WM_NCHITTEST
to that window. The return value will correspond to the object type on the requested coordinates.
Something like this:
bool IsMouseOverMaxBtn(HWND hWnd)
{
POINT pt;
VERIFY(GetCursorPos(&pt)); // get mouse position
int retVal = SendMessage(hWnd, WM_NCHITTEST, 0, MAKELONG(pt.x, pt.y));
return HTMAXBUTTON == retVal;
}
Edit:
You may send this message to any window (not necessarily belong to your thread/process). Since no pointers are involved (such as string pointers) - there's no problem.
However you should note that sending (not posting) a message to a window belonging to another thread is a pretty heavy operation, during which your thread is suspended. There may even happen a situation where your thread hangs, because the thread of the application that serves that window hangs.
You may consider using SendMessageTimeout
to guarantee your thread won't hang.

valdo
- 12,632
- 2
- 37
- 67