Win32 Console Disable System Menu Buttons

拟墨画扇 提交于 2021-02-19 06:30:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!