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 :) !!
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to call a C++ dll from C# windows application
- how to get running process information in java?
- efficiently calling unmanaged method taking unmana
- Is TWebBrowser dependant on IE version?
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- CosmosDB emulator can't start since port is al
- How to print to stdout from Python script with .py
- Determine if an executable (or library) is 32 -or
You could always use signals:
You should obviously allow an option for the user to close the app, by changing my_handler. my_handler calls main, so whenever the program is closed, my_handler is called, so therefore main is called.
It is possible to trap the close message for a window and prevent it from closing, if you are receiving messages for the window. Unfortunately a console is independent of the program running within it and you don't have that kind of control.
You can use SetConsoleCtrlHandler to control the console-window. You need to write up a callback to handle events (such as
CTRL_CLOSE_EVENT
). You may also use GetConsoleWindow function to get the window-handle, and handle window messages. I have done controlling the window with former method, and not sure about handling specific window message (via window-handle).Refer Console Functions.
This worked for me:
While we're at it, to re-enable the button:
... and to set the window's title:
I saw that most references used
DeleteMenu
and notEnableMenuItem
. 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 FunctionsSorry this isn't a comment, I don't have enough points to comment yet.
Can't you just remove the button in the properties for the form?