Annotation of mstools/samples/console/contitle.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 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: 
1.1       root       12: #include <windows.h>
                     13: #include <stdio.h>
                     14: #include "console.h"
                     15: 
                     16: /********************************************************************
                     17: * FUNCTION: demoGetTitle(HANDLE hConOut)                            *
                     18: *                                                                   *
                     19: * PURPOSE: demonstrate GetConsoleTitle and SetConsoleTitle. Read and*
                     20: *          display the console title, then set the console title.   *
                     21: *                                                                   *
                     22: * INPUT: handle to write to                                         *
                     23: ********************************************************************/
                     24: 
                     25: void demoGetTitle(HANDLE hConOut)
                     26: {
                     27:   BOOL bSuccess;
                     28:   CHAR szTitleBuf[256]; /* buffer for the current console title */
                     29:   CHAR szTemp[256];
                     30:   HANDLE hStdIn; /* standard input handle */
                     31:   DWORD dwStdInMode; /* standard input handle mode */
                     32:   DWORD dwBytesRead;
                     33: 
                     34:   setConTitle(__FILE__);
                     35:   hStdIn = GetStdHandle(STD_INPUT_HANDLE);
1.1.1.2   root       36:   PERR(hStdIn != INVALID_HANDLE_VALUE, "GetStdHandle");
1.1       root       37:   /* save the console mode */
                     38:   bSuccess = GetConsoleMode(hStdIn, &dwStdInMode);
                     39:   PERR(bSuccess, "GetConsoleMode");
                     40:   /* turn on line input mode so we can enter a string. */
                     41:   /* when turning on ENABLE_LINE_INPUT, you MUST also turn on */
                     42:   /* ENABLE_ECHO_INPUT. */
                     43:   bSuccess = SetConsoleMode(hStdIn, dwStdInMode | ENABLE_LINE_INPUT |
                     44:       ENABLE_ECHO_INPUT);
                     45:   PERR(bSuccess, "SetConsoleMode");
                     46:   myPuts(hConOut, "Let's get the console title with GetConsoleTitle.");
                     47:   /* get the console title */
                     48:   dwBytesRead = GetConsoleTitle(szTitleBuf, sizeof(szTitleBuf));
                     49:   PERR(dwBytesRead, "GetConsoleTitle");
                     50:   sprintf(szTemp, "The console title is: %s", szTitleBuf);
                     51:   myPuts(hConOut, szTemp);
                     52:   myPuts(hConOut, "\nNow let's set a new console title with SetConsoleTitle.");
                     53:   myPuts(hConOut, "\nEnter a new console title:");
                     54:   bSuccess = ReadFile(hStdIn, szTitleBuf, 256, &dwBytesRead, NULL);
                     55:   PERR(bSuccess, "ReadFile");
1.1.1.2   root       56:   if (dwBytesRead > 2) /* did the user type any chars before hitting return? */
                     57:     {
                     58:     /* null terminate the string - less two for cr/lf */
                     59:     szTitleBuf[dwBytesRead - 2] = 0;
                     60:     bSuccess = SetConsoleTitle(szTitleBuf);
                     61:     PERR(bSuccess, "SetConsoleTitle");
                     62:     }
1.1       root       63:   /* restore the console title to the original mode */
                     64:   bSuccess = SetConsoleMode(hStdIn, dwStdInMode);
                     65:   PERR(bSuccess, "SetConsoleMode");
                     66:   myPuts(hConOut, "\nHit enter to return...");
                     67:   myGetchar();
                     68:   return;
                     69: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.