--- mstools/samples/console/handler.c 2018/08/09 18:21:18 1.1.1.2 +++ mstools/samples/console/handler.c 2018/08/09 18:23:14 1.1.1.3 @@ -1,10 +1,18 @@ + +/******************************************************************************\ +* 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" -/* Microsoft Developer Support - Copyright (c) 1992 Microsoft Corporation */ - HANDLE hConsole; /* current console output handle */ /******************************************************************* @@ -29,6 +37,15 @@ BOOL WINAPI handler_routine(DWORD dwCtrl 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; @@ -65,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");