首页 > 代码库 > C++ Win32控制台应用程序捕捉关闭事件
C++ Win32控制台应用程序捕捉关闭事件
C++ Win32控制台应用程序捕捉关闭事件
#include #include bool ctrlhandler( DWORD fdwctrltype ) { switch( fdwctrltype ) { // handle the ctrl-c signal. case CTRL_C_EVENT: printf( "ctrl-c event\n\n" ); return( true ); // ctrl-close: confirm that the user wants to exit. case CTRL_CLOSE_EVENT: printf( "ctrl-close event\n\n" ); return( true ); // pass other signals to the next handler. case CTRL_BREAK_EVENT: printf( "ctrl-break event\n\n" ); return false; case CTRL_LOGOFF_EVENT: printf( "ctrl-logoff event\n\n" ); return false; case CTRL_SHUTDOWN_EVENT: printf( "ctrl-shutdown event\n\n" ); return false; default: return false; } } void main( void ) { if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ctrlhandler, true ) ) { printf( "\nthe control handler is installed.\n" ); printf( "\n -- now try pressing ctrl+c or ctrl+break, or" ); printf( "\n try logging off or closing the console...\n" ); printf( "\n(...waiting in a loop for events...)\n\n" ); while( 1 ){ Sleep(100);} } else printf( "\nerror: could not set control handler"); }
C++ Win32控制台应用程序捕捉关闭事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。