我有一个分层窗口(WS_EX_LAYERED),它实现了一个自定义的NCHITTEST和NCCALCSIZE,使我的窗口的客户端矩形与窗口矩形相同。我的窗户尺寸和油漆正确;当光标靠近窗口的下边缘时,我可以从WM_NCHITTEST返回HTBOTTOM,从而导致垂直调整大小窗口从底部类型操作。但是,我没有得到垂直调整大小的光标。有没有办法解决这个问题,而不必实现WM_SETCURSOR并测试指针的位置与窗口边缘的对比?
以下是我的代码片段:
case WM_NCCALCSIZE:
// Bypass DefWindowProc, so the Window Rect == Client Rect
return 0;
case WM_NCHITTEST: {
RECT w;
::GetWindowRect(hwnd, &w);
// Compare the mouse X/Y vs the rect of the window to detect
// resizing from the bottom edges
int r = HTCLIENT;
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
if (w.bottom - y < 10) {
// If I was not using NCHITTEST, I should get a verticle resize pointer here
if (x - w.left < 10)
r = HTBOTTOMLEFT;
else if (w.right - x < 10)
r = HTBOTTOMRIGHT;
else
r = HTBOTTOM;
}
return r;
}
答案 0 :(得分:3)
您需要处理WM_SETCURSOR消息 - lParam的低位字指定命中测试代码。
例如,
case WM_SETCURSOR:
switch (LOWORD(lParam))
{
case HTBOTTOM:
SetCursor(LoadCursor(0, IDC_SIZENS));
return 0;
}
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);