Skip to main content
Updated links
Source Link
funie200
  • 3.9k
  • 5
  • 25
  • 38

This worked for me:

#include "conio.h" void main() { HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); } 

While we're at it, to re-enable the button:

EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); 

... and to set the window's title:

char consoleTitle[256]; wsprintf(consoleTitle, _T("My little window")); SetConsoleTitle((LPCTSTR)consoleTitle); 

I saw that most references used DeleteMenu and not EnableMenuItem. I preffer the later, as you get more control (enable/disable/greyed-out etc.). For full options, take a look at MSDN Console FunctionsConsole Functions and Menu FunctionsMenu Functions

This worked for me:

#include "conio.h" void main() { HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); } 

While we're at it, to re-enable the button:

EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); 

... and to set the window's title:

char consoleTitle[256]; wsprintf(consoleTitle, _T("My little window")); SetConsoleTitle((LPCTSTR)consoleTitle); 

I saw that most references used DeleteMenu and not EnableMenuItem. I preffer the later, as you get more control (enable/disable/greyed-out etc.). For full options, take a look at MSDN Console Functions and Menu Functions

This worked for me:

#include "conio.h" void main() { HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); } 

While we're at it, to re-enable the button:

EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); 

... and to set the window's title:

char consoleTitle[256]; wsprintf(consoleTitle, _T("My little window")); SetConsoleTitle((LPCTSTR)consoleTitle); 

I saw that most references used DeleteMenu and not EnableMenuItem. I preffer the later, as you get more control (enable/disable/greyed-out etc.). For full options, take a look at MSDN Console Functions and Menu Functions

Source Link
bavaza
  • 11.1k
  • 11
  • 78
  • 109

This worked for me:

#include "conio.h" void main() { HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); } 

While we're at it, to re-enable the button:

EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); 

... and to set the window's title:

char consoleTitle[256]; wsprintf(consoleTitle, _T("My little window")); SetConsoleTitle((LPCTSTR)consoleTitle); 

I saw that most references used DeleteMenu and not EnableMenuItem. I preffer the later, as you get more control (enable/disable/greyed-out etc.). For full options, take a look at MSDN Console Functions and Menu Functions