HOWTO: Detect Closure of Command Window from a Console App

ID: Q102429


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT versions 3.1, 3.5, 4.0
    • Microsoft Windows 2000


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.

Additional query words:

Keywords : kbConsole kbKernBase kbWinOS2000 kbDSupport kbGrpKernBase
Version : winnt:3.1,3.5,4.0
Platform : winnt
Issue type : kbhowto


Last Reviewed: December 29, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.