|
|
1.1 root 1: #include <windows.h>
2: #include <string.h>
3: #include "console.h"
4:
1.1.1.2 ! root 5: /* Microsoft Developer Support
! 6: Copyright (c) 1992 Microsoft Corporation */
! 7:
1.1 root 8: HANDLE hConsole; /* current console output handle */
9:
10: /*******************************************************************
11: * FUNCTION: handler_routine(DWORD dwCtrlType) *
12: * *
13: * PURPOSE: this is the control handler routine activated by ctrl+c *
14: * or ctrl+break keys *
15: * *
16: * INPUT: the type of control event *
17: *******************************************************************/
18:
1.1.1.2 ! root 19: BOOL WINAPI handler_routine(DWORD dwCtrlType)
1.1 root 20: {
21: CHAR szTemp[64];
22:
23: /* print out what control event was received to the current console */
24: switch(dwCtrlType)
25: {
26: case CTRL_C_EVENT:
27: strcpy(szTemp, "CTRL_C_EVENT");
28: break;
29: case CTRL_BREAK_EVENT:
30: strcpy(szTemp, "CTRL_BREAK_EVENT");
31: break;
32: default:
33: strcpy(szTemp, "unknown event");
34: break;
35: }
36: strcat(szTemp, " detected");
37: myPuts(hConsole, szTemp);
38: return(TRUE);
39: }
40:
41:
42: /*********************************************************************
43: * FUNCTION: demoSetCtrlHandler(HANDLE hConOut) *
44: * *
45: * PURPOSE: demonstrate SetConsoleCtrlHandler by setting a ctrl+break *
46: * and ctrl+c handler. When the user hits either one of *
47: * these keys, a message is printed to the console *
48: * indicating the event. *
49: * *
50: * INPUT: the output handle to write to *
51: *********************************************************************/
52:
53: void demoSetCtrlHandler(HANDLE hConOut)
54: {
55: BOOL bSuccess;
56:
57: setConTitle(__FILE__);
58: hConsole = hConOut; /* set global console output handle for handler */
59: myPuts(hConOut, "Let's install a ctrl+c and ctrl+break handler for this\n"
60: "process. Hit ctrl+c and ctrl+break a few times to test\n"
61: "the handler. Hit enter to return...");
62: /* set handler for this process */
63: bSuccess = SetConsoleCtrlHandler(handler_routine, TRUE);
64: PERR(bSuccess, "SetConsoleCtrlHandler");
65: /* wait for user to hit enter */
66: while (myGetchar() != 0xd)
67: ;
68: /* remove our handler from the list of handlers */
69: bSuccess = SetConsoleCtrlHandler(handler_routine, FALSE);
70: PERR(bSuccess, "SetConsoleCtrlHandler");
71: return;
72: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.