[英]WM_NCHITTEST not changing mouse cursor
我有一個分層窗口(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;
}
您需要處理WM_SETCURSOR消息 - lParam的低位字指定命中測試代碼。
例如,
case WM_SETCURSOR:
switch (LOWORD(lParam))
{
case HTBOTTOM:
SetCursor(LoadCursor(0, IDC_SIZENS));
return 0;
}
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.