Automatically Closing QuickWin Exec Window at Completion

Last reviewed: July 17, 1997
Article ID: Q93661
1.00 1.50 1.51 1.52 WINDOWS kbprg

The information in this article applies to:

  • Microsoft Visual C++ for Windows, version 1.0, 1.5, 1.51, and 1.52

In Visual C++, when a QuickWin program completes execution, its window remains open by default so the user can view its output or any other messages that the program displays.

To automatically close the window for a QuickWin program upon completion, call two Windows functions. The first function retrieves the window handle and the second function destroys the window. The following code example demonstrates this technique.

Sample Code

/*
 * Compiler options required: None
 */

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

void main()
{
   int hWnd;
   int nChar;

   printf("Generic");
   nChar = getchar();
   if (toupper(nChar) == (int)'C')
      {
      // GetActiveWindow() works only when
      // the QuickWin Exec window is active
      hWnd = GetActiveWindow();

      // Other option: Use FindWindow(). "TEST" is the default
      // QuickWin Exec application name, which is used as the
      // window title.
      // hWnd = FindWindow(NULL, "TEST");
      DestroyWindow(hWnd) ;
      }
   exit(1);
}


Additional reference words: kbinf 1.00 1.50 1.51 1.52
KBCategory: kbprg
KBSubcategory: VCGenIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.