【发布时间】:2012-05-28 23:24:52
【问题描述】:
我正在尝试将鼠标指针(使用自定义光标)限制在我的应用程序窗口的客户区,该应用程序最初可以工作,但在我从应用程序切换回来时遇到问题。我使用ClipCursor() 来限制光标并使用几个不同的光标,这些光标取决于情况,所以我使用SetCursor() 而不是设置窗口的类光标。
通过检查我的 WndProc 中的 WM_SETCURSOR 消息,当 Alt-Tabbing 离开应用程序并返回(我想允许)时,我已经正确恢复了光标:
case WM_SETCURSOR:
{
if (mIsMouseGrabOn) // a bool that indicates if the mouse should be restricted to the cient area or not
SetCursor(gmInstance->m_cursorTargetGreen);
else
SetCursor(gmInstance->m_cursorTargetRed);
return 0; // prevent DefWndProc from resetting it
}
但是在切换回来时,光标不再被剪辑到我的应用程序窗口的客户区。我尝试检查 WM_ACTIVATEAPP(如下所示),但没有成功,并尝试使用相同的代码和相同的结果检查 WM_ACTIVATE。
case WM_ACTIVATEAPP:
{
if(wParam == TRUE) // When we are activated
{
if (mIsMouseGrabOn)
GrabMouse(); // function to determine client area and call ClipCusor with the results
else
ClipCusor(NULL); // make the sure cursor is freed
}
else if(wParam == FALSE) // When we are deactivated
{
ClipCursor(NULL);
}
//return 0; // Let DefWndProc handle anything else
}
使用上面的代码,光标会正确更改,但无论mIsMouseGrabOn 的状态如何,都不会被捕获。
从应用程序切换回来时,如何正确绑定光标?我应该注意哪些消息而不是 WM_ACTIVATEAPP?
【问题讨论】: