[출처] : http://blog.daum.net/aswip/6585109
#include <windows.h>
#include <stdio.h>
BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL+C signal.
case CTRL_C_EVENT:
printf("\nctrl+c\n");
Beep(1000, 100);
exit(1);
return TRUE;
// CTRL+CLOSE: confirm! that the user wants to exit.
case CTRL_CLOSE_EVENT:
printf("\nctrl+close\n");
Beep(1500, 100);
exit(1);
return TRUE;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
void main(void)
{
BOOL fSuccess;
fSuccess = SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE);
if ( !fSuccess )
{
printf("Could not set control handler");
}
while ( true )
{
putchar('.');
Sleep(1000);
}
}
#include <windows.h>
#include <stdio.h>
BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL+C signal.
case CTRL_C_EVENT:
printf("\nctrl+c\n");
Beep(1000, 100);
exit(1);
return TRUE;
// CTRL+CLOSE: confirm! that the user wants to exit.
case CTRL_CLOSE_EVENT:
printf("\nctrl+close\n");
Beep(1500, 100);
exit(1);
return TRUE;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
void main(void)
{
BOOL fSuccess;
fSuccess = SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE);
if ( !fSuccess )
{
printf("Could not set control handler");
}
while ( true )
{
putchar('.');
Sleep(1000);
}
}
'DEV-Language > Win32 API & MFC' 카테고리의 다른 글
Windows 메모리 관련 함수 (0) | 2009.01.27 |
---|