HOWTO: Detect Closure of Command Window from a Console App

ID: Q102429

The information in this article applies to:

SUMMARY

Win32 console applications run in a command window. So that the console application can detect when the console is closing, register a console control handler and look for the following values in your case statement:

   CTRL_CLOSE_EVENT     User closes the console
   CTRL_LOGOFF_EVENT    User logs off
   CTRL_SHUTDOWN_EVENT  User shuts down the system

For an example, see the CONSOLE sample. For more information, see the entry for SetConsoleCtrlhandler() in the Win32 application programming interface (API) reference.
Keywords          : kbConsole kbKernBase kbGrpKernBase 
Issue type        : kbhowto

Last Reviewed: January 8, 1998