home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / console / alocfree.c next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  2.1 KB  |  50 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples. 
  4. *       Copyright (C) 1993-1997 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include "console.h"
  15.  
  16. /*********************************************************************
  17. * FUNCTION: demoAllocFree(HANDLE hConOld, HANDLE *hConOut)           *
  18. *                                                                    *
  19. * PURPOSE: demonstrate FreeConsole & AllocConsole. Free the console  *
  20. *          and allocate a new one                                    *
  21. *                                                                    *
  22. * INPUT: the current console output handle and a temporary 'scratch' *
  23. *        console handle                                              *
  24. *********************************************************************/
  25.  
  26. void demoAllocFree(HANDLE hConOld, HANDLE *hConOut)
  27. {
  28.   BOOL bSuccess;
  29.  
  30.   setConTitle(__FILE__);
  31.   myPuts(hConOld, "Let's free the current console with FreeConsole. It will\n"
  32.                   "disappear for 3 seconds, then we'll allocate a new one.\n"
  33.                   "with AllocConsole. Hit return to continue...");
  34.   myGetchar();
  35.   bSuccess = FreeConsole();
  36.   PERR(bSuccess, "FreeConsole");
  37.   Sleep(3000);
  38.   bSuccess = AllocConsole();
  39.   PERR(bSuccess, "AllocConsole");
  40.   *hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
  41.   /* set our console text attribute */
  42.   bSuccess = SetConsoleTextAttribute(*hConOut, FOREGROUND_CYAN);
  43.   PERR(bSuccess, "SetConsoleTextAttribute");
  44.   myPuts(*hConOut, "This is a new console that we've allocated with AllocConsole.");
  45.   Sleep(2000);
  46.   /* must refresh the screen since we've replaced the console */
  47.   showConAPIs(*hConOut);
  48.   return;
  49. }
  50.