Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Maximize Button c++ console application

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.

like image 228
Marek Avatar asked Dec 08 '25 19:12

Marek


1 Answers

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);
like image 94
Barmak Shemirani Avatar answered Dec 10 '25 10:12

Barmak Shemirani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!