0
votes

I need to disable all resizing but by WMSZ_BOTTOM, including disabling corresponding mouse icons.

Processing WM_GETMINMAXINFO doesn't help, because it is called before window rectangle gets adjusted (inside WM_CREATE), so I have nothing to set into it. I tried to copy the current rectangle and set it on WM_SIZING into lParam, but there's no perfect point when to call GetWindowRect() for that copy, because sometimes when I move my window and then resize it by dragging the unintended sides, it jumps to the previous position (old rect gets restored). And these look like hacking instead of some smart method.

And how to disable resizing mouse icon when it hovers over window borders other than bottom?

2
Does the WM_NCHITTEST method fix the Alt+Space, S keyboard shortcut for resizing? E.g if you do Alt+Space, S, RightArrow this allows you to resize the right border using the keyboard.Ben

2 Answers

4
votes

An alternative method to @manuell's which doesn't require you to check the mouse position yourself:

case WM_NCHITTEST:
    {
        LRESULT lRes = DefWindowProc(hWnd, uMsg, wParam, lParam);
        if (lRes == HTBOTTOMLEFT || lRes == HTBOTTOMRIGHT
        ||  lRes == HTTOPLEFT || lRes == HTTOPRIGHT || lRes == HTTOP
        ||  lRes == HTLEFT || lRes == HTRIGHT || lRes == HTSIZE)
            lRes = HTBORDER; // block resizing for all but HTBOTTOM

        return lRes;
    }
0
votes

For the "how to disable resizing mouse icon when it hovers over window borders other than bottom?" question: Process the WM_NCHITTEST message.

The mouse coordinates of the cursor are in lParam, relatives to the screen.

#include <windowsx.h>

case WM_NCHITTEST: {
    int iMouseX = GET_X_LPARAM( lParam );
    int iMouseY = GET_Y_LPARAM( lParam );
    RECT rect;
    GetWindowRect( hWnd, &rect );
    int xPos = iMouseX - rect.left; 
    int yPos = iMouseY - rect.top;
    // here, check where the mouse is
    // return DefWindowProc for default processing
    // return HTBORDER for "no sizing border" if mouse is over border