c++控制台关闭响应事件

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:
        Close_Exit = true ;
        Sleep(200);
        printf( "ctrl-close event\n\n" );
        return( true );
    // pass other signals to the next handler.
    case CTRL_BREAK_EVENT:
        Close_Exit = true ;
        Sleep(200);
        printf( "ctrl-break event\n\n" );
        return false;
    case CTRL_LOGOFF_EVENT:
        Close_Exit = true ;
        Sleep(200);
        printf( "ctrl-logoff event\n\n" );
        return false;
    case CTRL_SHUTDOWN_EVENT:
        Close_Exit = true ;
        Sleep(200);
        printf( "ctrl-shutdown event\n\n" );
        return false;
    default:
        return false;
    }
}

//在Min函数中调用

if(SetConsoleCtrlHandler( (PHANDLER_ROUTINE)Ctrlhandler, true ))

 

你可能感兴趣的:(c++)