--- mstools/samples/console/handler.c 2018/08/09 18:20:36 1.1 +++ mstools/samples/console/handler.c 2018/08/09 18:23:14 1.1.1.3 @@ -1,3 +1,14 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + #include #include #include "console.h" @@ -13,7 +24,7 @@ HANDLE hConsole; /* current console outp * INPUT: the type of control event * *******************************************************************/ -BOOL handler_routine(DWORD dwCtrlType) +BOOL WINAPI handler_routine(DWORD dwCtrlType) { CHAR szTemp[64]; @@ -26,6 +37,15 @@ BOOL handler_routine(DWORD dwCtrlType) case CTRL_BREAK_EVENT: strcpy(szTemp, "CTRL_BREAK_EVENT"); break; + case CTRL_CLOSE_EVENT: + strcpy(szTemp, "CTRL_CLOSE_EVENT"); + break; + case CTRL_LOGOFF_EVENT: + strcpy(szTemp, "CTRL_LOGOFF_EVENT"); + break; + case CTRL_SHUTDOWN_EVENT: + strcpy(szTemp, "CTRL_SHUTDOWN_EVENT"); + break; default: strcpy(szTemp, "unknown event"); break; @@ -62,6 +82,19 @@ void demoSetCtrlHandler(HANDLE hConOut) /* wait for user to hit enter */ while (myGetchar() != 0xd) ; + /* now let's generate some control events */ + myPuts(hConOut, "Now we'll use GenerateConsoleCtrlEvent to generate a\n" + "ctrl+c and a ctrl+break event...\n"); + bSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); + PERR(bSuccess, "GenerateConsoleCtrlEvent"); + bSuccess = GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0); + PERR(bSuccess, "GenerateConsoleCtrlEvent"); + Sleep(1000); /* give ctrl handle time to output messages */ + myPuts(hConOut, "\nNow choose 'Close' then 'Cancel' from the system\n" + "menu of this console and note that we receive a\n" + "CTRL_CLOSE_EVENT...\n"); + myPuts(hConOut, "\nHit enter to continue..."); + myGetchar(); /* remove our handler from the list of handlers */ bSuccess = SetConsoleCtrlHandler(handler_routine, FALSE); PERR(bSuccess, "SetConsoleCtrlHandler");