#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, exiting\n\n" );
ExitProcess(0);
return( TRUE );
default:
return FALSE;
}
}
void main( void )
{
if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
{
printf( "\nThe Control Handler is installed.\n" );
while( 1 ){ }
}
else
printf( "\nERROR: Could not set control handler");
}
// other thread:
GenerateConsoleCtrlEvent(CTRL_C_EVENT,0);
|