c++windowswinapiconsolewindows-11

How can I disable the console window's maximize button, resize by drag, and X button in Windows 11?


I want to disable the console window's maximize button, resize by drag, and X button in a C++ program.

But it doesn't work with this code:

#include <iostream>
#include <Windows.h>

using namespace std;

int main(void)
{
    DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_MAXIMIZE, MF_GRAYED); // maximize button
    EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_GRAYED); // X button
    DrawMenuBar(GetConsoleWindow());

    return 0;
}

I remember this worked on Windows 10.

Is this a Windows 11 problem, or is there another way to solve it?


Solution

  • Refer to the Blog:Windows Terminal is now the Default in Windows 11

    On win10, the default terminal is Windows Console Host. I suggest you could set the default terminal to Windows Console Host in win11.

    Settings -> System -> For developers -> Terminal

    enter image description here

    enter image description here