1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <iostream>
#include <signal.h>
BOOL WINAPI ConsoleHandler(
DWORD dwCtrlType // control signal type
);
int main(int argc, char *argv[])
{
if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
// unable to install handler...
// display message to the user
printf("Unable to install handler!\n");
return -1;
}
while(true)
{
}
}
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
char mesg[128];
switch(CEvent)
{
case CTRL_C_EVENT:
MessageBox(NULL,
_T("CTRL+C received!"),_T("CEvent"),MB_OK);
break;
case CTRL_BREAK_EVENT:
MessageBox(NULL,
_T("CTRL+BREAK received!"),_T("CEvent"),MB_OK);
break;
case CTRL_CLOSE_EVENT:
MessageBox(NULL,
_T("Program being closed!"),_T("CEvent"),MB_OK);
break;
case CTRL_LOGOFF_EVENT:
MessageBox(NULL,
_T("User is logging off!"),_T("CEvent"),MB_OK);
break;
case CTRL_SHUTDOWN_EVENT:
MessageBox(NULL,
_T("User is logging off!"),_T("CEvent"),MB_OK);
break;
}
return TRUE;
}
|