Forbid to close the console program with a cross on b. OS: Windows

  • There are many ways. For example, hide the mouse or start the console program in fullscreen. What kind of problem are you trying to solve? - KoVadim 9:59

1 answer 1

If you delete the "Close" command from the window (system) menu, then the "cross" button becomes inaccessible

HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); 

Instead of deleting a menu item, you can simply make it inactive.

 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); 

This, however, does not prohibit the closing of the window by Alt - F4 .