简体   繁体   English

如何确定鼠标是否指向光标下方的最大化窗口按钮

[英]How determine if mouse points to maximise button of window under cursor

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 ? 有API吗?

You may send a WM_NCHITTEST to that window. 您可以将WM_NCHITTEST发送到该窗口。 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. 您可以考虑使用SendMessageTimeout来确保您的线程不会挂起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM