一个console程序,当按下窗口的关闭按键时,不想退出而是进行自己的处理,应如何进行。敬请指教。
解决方案 »
- CPaintDC指定绘画控件?
- VC+opengl 树木建模 急急急!!!
- MFC基本对话框中,如何 手动选择一个文件(a.exe文件),作为资源,点确定会生成一个新的文件(b.exe),其中a.exe就成为了b.exe中的资源?
- 如何从服务器下载文件(HTTP,FTP),但是不使用MFC的类,大家给些方法吧,谢谢啦
- ado vc 添加记录时 idispatch error #3105错误问题
- 走过路过,近来看看,帮忙想想思路,一周内结贴
- 请问如何作outlook的插件
- 请大牛帮助——输入法拦截消息响应的诡异问题
- 关于子线程结束的问题
- 关于CSplitterWnd的问题?
- 关于连续send数据的问题
- 如何用程序向一个exe文件动态添加资源文件,并在该exe运行的时候读取该资源文件???急ing...
When a CTRL+C signal is received, the control handler returns TRUE, indicating that it has handled the signal. Doing this prevents other control handlers from being called.When a CTRL_CLOSE_EVENT signal is received, the control handler returns TRUE, causing the system to display a dialog box that gives the user the choice of terminating the process and closing the console or allowing the process to continue execution. If the user chooses not to terminate the process, the system closes the console when the process finally terminates.When a CTRL+BREAK, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT signal is received, the control handler returns FALSE. Doing this causes the signal to be passed to the next control handler function. If no other control handlers have been registered or none of the registered handlers returns TRUE, the default handler will be used, resulting in the process being terminated.Note that MyErrorExit is a placeholder for an application-defined function to display and handle error conditions.BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL+C signal.
case CTRL_C_EVENT:
Beep(1000, 1000);
return TRUE;
// CTRL+CLOSE: confirm that the user wants to exit.
case CTRL_CLOSE_EVENT:
return TRUE;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
void main(void)
{
BOOL fSuccess;
fSuccess = SetConsoleCtrlHandler(
(PHANDLER_ROUTINE) CtrlHandler, // handler function
TRUE); // add to list
if (! fSuccess)
MyErrorExit("Could not set control handler");
}
同意masterz() 另外可参考
http://www.programfan.net/showarticle.asp?id=2287
控制台程序的事件处理
我想要的是能够不弹出是否要强制关闭的对话框的处理方法。