sigtest.cpp

来自「VC源代码大全(精华版)」· C++ 代码 · 共 37 行

CPP
37
字号
#include    <windows.h>
#include    <stdio.h>
#include    <signal.h>
//
//  sigtest.cpp. Test program for signal handling.
//  compile this program with the following command line
//
//            cl -GX sigtest.cpp user32.lib
//
//  The -GX enables exception handling. The user32.lib
//  provides the MessageBox function.
//

//
//  Prototype for signal handler
//
void _cdecl HandleAbort (int sig);

//
//  Save the old signal function if any
//
void (*func)(int sig);

main ()
{
    func = signal (SIGABRT, HandleAbort);
    throw;
    MessageBox (NULL, "Abort handled", "Abort", MB_OK);
}

void _cdecl HandleAbort (int sig)
{
    MessageBox (NULL, "Handling abort", "Abort", MB_OK);
    if (func != NULL)
         func(sig);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?