SW_MAXIMIZE does not work without WS_MAXIMIZEBOX style?

I made an overlapped window that has its maximize button greyed out. I want the window to be always maximized, to disable moving or resizing at all times, so I added ShowWindow(mainwindow, SW_MAXIMIZE).

The latter doesn't seem to work. The window does not completely fill the screen (though it's close) and I can still drag it around by the title bar.
However, when I add the WS_MAXIMIZEBOX style, ShowWindow(mainwindow, SW_MAXIMIZE) does do its job properly (complete maximize and disable moving by dragging), but now the maximize button is not greyed out, so the user can resize the window that way.

Could anyone help me out?

1
2
HWND mainwindow = CreateWindow("mainwindowclass", mainwindowstr, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, maininst, NULL);
ShowWindow(mainwindow, SW_MAXIMIZE);


p.s. I'm using Vista, in case that matters.
Just remove maximize button after you call ShowWindow:
1
2
3
LONG_PTR Style = GetWindowLongPtr(windowHandle, GWLP_STYLE);
Style &= ~WS_MAXIMIZEBOX; //this makes it still work when WS_MAXIMIZEBOX is actually already toggled off
SetWindowLongPtr(windowHandle, GWLP_STYLE, Style);



Alternatively, leave the button there, but block the event from your window procedure.
Last edited on
The former method doesn't work; removing the maximize button automatically de-maximizes the window.

The second method doesn't grey out the maximize button, so it gives the user the impression that the program is bugged.

Anyway, thanks for the tips but I'm getting the impression that Winapi was designed to prevent permanent maximizing.
Topic archived. No new replies allowed.