Professional Documents
Culture Documents
Control Signal: How Control Signals Are Handled by Default?
Control Signal: How Control Signals Are Handled by Default?
if (!SetConsoleCtrlHandler(NULL, TRUE))
ReportError(_T("Error setting event
handler"), 1, TRUE);
HANDLE hIn;
hIn = CreateFile (_T("CONIN$"), GENERIC_READ |
GENERIC_WRITE, 0,NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
SetConsoleMode (hIn, ENABLE_LINE_INPUT |
ENABLE_ECHO_INPUT );// since ENABLE_PROCESSED_INPUT
is not present, ctrl-c is ignored. However, ctrl-
break is still working.
What we are doing in above snippet is the ctrl+c will become
the part of the console input buffer and it will not get handle by
the system. Hence, it will get ignored.