#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
BOOL WINAPI XHandler (DWORD what)
{
ofstream whatHappened("WhatHappened.txt"

;
switch (what)
{
case CTRL_C_EVENT:
/* A CTRL+c signal was received, either from keyboard input or
from a signal generated by the GenerateConsoleCtrlEvent
function.
*/
whatHappened << "Got Ctrl-Ced" << endl;
break;
case CTRL_BREAK_EVENT:
/* A CTRL+BREAK signal was received, either from keyboard input or
from a signal generated by GenerateConsoleCtrlEvent.
*/
whatHappened << "Got broken" << endl;
break;
case CTRL_CLOSE_EVENT:
/* A signal that the system sends to all processes attached to a
console when the user closes the console (either by choosing the
Close command from the console window's System menu, or by
choosing the End Task command from the Task List).
*/
whatHappened << "Got closed" << endl;
break;
case CTRL_LOGOFF_EVENT:
/* A signal that the system sends to all console processes when
a user is logging off. This signal does not indicate which user
is logging off, so no assumptions can be made.
*/
whatHappened << "Got logged off" << endl;
break;
case CTRL_SHUTDOWN_EVENT:
/* A signal that the system sends to all console processes when
the system is shutting down.
*/
whatHappened << "Got shut down" << endl;
break;
}
/* If true is returned, a dialog box indicating that the process
needs more time to terminate will pop up
*/
return FALSE;
}
int main ()
{
int cupid;
SetConsoleCtrlHandler (XHandler, true);
// Wait for something to happen
cin >> cupid;
return 0;
}