Reputation: 41
I am maintaining old C++ application running console. I has disabled "close" buttun . I need to disable maximize button as well. The following code disabes the close button
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());
I have added line to disable maximize button:
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND);
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());
It works, the button is disabled but it is not greyed out. (The Close button is greyed out) What am I missing? Thank you.
Upvotes: 3
Views: 3137
Reputation: 31599
Use SetWindowLong
to change the window style, then call SetWindowPos
. Example:
HWND hwnd = GetConsoleWindow();
DWORD style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~WS_MAXIMIZEBOX;
SetWindowLong(hwnd, GWL_STYLE, style);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
Upvotes: 6