C++ Prevent the console window from closing when red X is clicked
问题 I'm developing a simple C++ console application without classes & objects. Is there any method or function to prevent the console from closing when red X button is clicked ? I'm using Visual Studio C++ Express 2010 : A simple console application which containes only main.cpp file. Thank you for answering my question :) !! 回答1: This worked for me: #include "conio.h" void main() { HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED