Armentage
Armentage

Reputation: 12763

WM_NCHITTEST not changing mouse cursor

I have a Layered Window (WS_EX_LAYERED) that implements a custom NCHITTEST and NCCALCSIZE to make the client rect of my window the same as the window rect. My window sizes and paints correctly; I can return HTBOTTOM from WM_NCHITTEST when the cursor is near the bottom edge of my window to cause a vertical-resize-window-from-the-bottom type action. However, I am not getting the vertical resize cursor. Is there way a do fix this without having to implement WM_SETCURSOR and test the pointer's position vs the edges of the windows?

Here's a snippet of my code:

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;
    }   

Upvotes: 1

Views: 1734

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37192

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);

Upvotes: 3

Related Questions