zoukankan      html  css  js  c++  java
  • C++ Win32控制台应用程序捕捉关闭事件(转)

    按语:

       ctrl+c 产生CTRL_C_EVENT

       ctrl+Break :CTRL_BREAK_EVENT

        点x : CTRL_CLOSE_EVENT:

    #include <windows.h>
    #include <stdio.h>

    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");
    }

    https://bbs.csdn.net/topics/370126796

  • 相关阅读:
    我的黑客偶像
    2020-2021-1学期 学号20201222 《信息安全专业导论》第5周学习总结
    XOR加密
    pep/9
    我的黑客偶像
    学年2020-2021,1 学号:20201222《信息安全专业导论》第4周学习总结”
    IEEE754浮点数转换
    师生关系
    罗马数字转阿拉伯数字
    第三周总结
  • 原文地址:https://www.cnblogs.com/xihong2014/p/15118281.html
Copyright © 2011-2022 走看看