问题
I want to disable/grey a system menu button on the console window, particularly the minimize button. I've tried functions mentioned on another thread, but even after using them, the console window still doesn't have the minimize button grayed out. I have also looked into the DeleteMenu() function, but it doesn't seem to have the option to grey out buttons.
Here's the test code:
#include <Windows.h>
using namespace std;
int main()
{
//SetConsoleTitle(L"CPU Information");
HWND consoleWindow = GetConsoleWindow();
HMENU hMenu = GetSystemMenu(consoleWindow, FALSE);
EnableMenuItem(hMenu, SC_MINIMIZE, MF_BYCOMMAND | MF_GRAYED);
DrawMenuBar(consoleWindow);
return 0;
}
回答1:
GetWindowLong + SetWindowLong FTW!
int main(int argc, _TCHAR* argv[])
{
HWND consoleWindow = GetConsoleWindow();
LONG style = GetWindowLong(consoleWindow , GWL_STYLE);
style = style & ~(WS_MINIMIZEBOX);
SetWindowLong(consoleWindow, GWL_STYLE, style);
return 0;
}
This will grey-out and disable both the minimize box in the top-right corner of the window as well as the "minimize" option from the system menu.
来源:https://stackoverflow.com/questions/21508278/win32-console-disable-system-menu-buttons