简体   繁体   中英

Block window maximize functionality? (Completely)

I am trying to create a window with behavior similar to cmd.exe , specifically whereby I don't want to support maximizing the window, since I only show fully visible lines of text (vertically). I have come up with two solutions so far:

Solution 1:

case WM_SYSCOMMAND:
            if (wParam == SC_MAXIMIZE) {
                return 0;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;

Solution 2:

case WM_SIZE:
        if (wParam == SIZE_MAXIMIZED) {
            SendMessage(hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
            return 0;
        }
        break;

Unfortunately, the former is only effective if the user explicitly clicks the maximize button in the title bar, or in a context menu. It won't block it if the user simply double clicks the title bar for example.

The problem with the latter solution, for me, is that it causes scrollbars to disappear until you resize the window manually (by dragging the sides). Also, you can sometimes see the window flash before the window size is restored (I did try disabling redrawing before sending WM_SYSCOMMAND / SC_RESTORE , but unfortunately it did not help much).

Is there a better solution that I'm missing?

case WM_SYSCOMMAND:
    UINT SysCommandCode = wParam & 0xFFF0;
    if (SysCommandCode == SC_MAXIMIZE) {
        return 0;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;

Also it is recommended to remove WS_MAXIMIZEBOX from the windows style (when creating).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM