为何OnNcMouseMove()始终无法响应
目的:自绘整个框架,在底部的100像素非客户区中添加按钮,并当鼠标移动到按钮上时作出响应。
首先,我在以下函数中,将底部100像素的区域设置为非客户区。
void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
lpncsp->rgrc[0].bottom -= 100;
CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
}
但在底部的100像素非客户区中移动鼠标,为何始终无法响应?请各位高手赐教!!!
void CMainFrame::OnNcMouseMove(UINT nHitTest, CPoint point)
{
AfxMessageBox("OK");
CFrameWnd::OnNcMouseMove(nHitTest, point);
}
[解决办法]
ON_WM_NCMOUSEMOVE()
[解决办法]
To have mouse messages over the non-client area, you should first have a non-client area. To get that, handle: WM_NCCALCSIZE to notify windows about the non-client-area. After that, you should deal with WM_NCHITTEST and return a non-client area value, like HTTOPLEFT or HTCAPTION to notify windows that the mouse is currently NOT on the Client Area.
Then you will receive WM_NCMOUSEMOVE messages.
For details on those messages:
WM_NCCALCSIZE
http://msdn2.microsoft.com/en-us/library/ms632634(VS.85).aspx
WM_NCHITTEST
http://msdn2.microsoft.com/en-us/library/ms645618(VS.85).aspx
[解决办法]
忘记1楼吧,那是个错误的答案,参考2楼,下面是我写一个小测试程序,它工作你可以参考一下:
void CMainFrame::OnNcMouseMove(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CFrameWnd::OnNcMouseMove(nHitTest, point);
}
void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
// TODO: Add your message handler code here and/or call default
lpncsp->rgrc[0].bottom -= 100;
CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
}
void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CFrameWnd::OnMouseMove(nFlags, point);
}
LRESULT CMainFrame::OnNcHitTest(CPoint point)
{
// TODO: Add your message handler code here and/or call default
RECT rectWindows, rectClient;
this->GetWindowRect(&rectWindows);
this->GetClientRect(&rectClient);
if (point.y < rectWindows.bottom && point.y > rectWindows.bottom - 100)
{
return HTBOTTOM;
}
else
{
return CFrameWnd::OnNcHitTest(point);
}
}