zoukankan      html  css  js  c++  java
  • 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
    
    " );
            return( true );
        // ctrl-close: confirm that the user wants to exit.
        case CTRL_CLOSE_EVENT:
            printf( "ctrl-close event
    
    " );
            return( true );
        // pass other signals to the next handler.
        case CTRL_BREAK_EVENT:
            printf( "ctrl-break event
    
    " );
            return false;
        case CTRL_LOGOFF_EVENT:
            printf( "ctrl-logoff event
    
    " );
            return false;
        case CTRL_SHUTDOWN_EVENT:
            printf( "ctrl-shutdown event
    
    " );
            return false;
        default:
            return false;
        }
    }
    void main( void )
    {
        if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ctrlhandler, true ) )
        {
            printf( "
    the control handler is installed.
    " );
            printf( "
     -- now try pressing ctrl+c or ctrl+break, or" );
            printf( "
     try logging off or closing the console...
    " );
            printf( "
    (...waiting in a loop for events...)
    
    " );
           while( 1 ){ Sleep(100);}
        }
    else
        printf( "
    error: could not set control handler");
    }
  • 相关阅读:
    12-单表查询
    11-数据的增删改
    10-外键的变种 三种关系
    09-完整性约束
    08-数据类型(2)
    07-数据类型
    06-表的操作
    05-库的操作
    Spring:(六) 代理模式
    Spring:(五) 注解
  • 原文地址:https://www.cnblogs.com/aliblogs/p/6918758.html
Copyright © 2011-2022 走看看