1

我有一个分层窗口 (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;
    }   
4

1 回答 1

3

You need to handle the WM_SETCURSOR message - the low-order word of lParam specifies the hit-test code.

For instance,

case WM_SETCURSOR:
    switch (LOWORD(lParam))
    {
        case HTBOTTOM:
            SetCursor(LoadCursor(0, IDC_SIZENS));
            return 0;
            }
        }
    }
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
于 2012-08-27T20:41:37.887 回答