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

1.1     ! root        1: #include <windows.h>
        !             2: #include <stdio.h>
        !             3: #include "console.h"
        !             4: 
        !             5: /********************************************************************
        !             6: * FUNCTION: demoGetTitle(HANDLE hConOut)                            *
        !             7: *                                                                   *
        !             8: * PURPOSE: demonstrate GetConsoleTitle and SetConsoleTitle. Read and*
        !             9: *          display the console title, then set the console title.   *
        !            10: *                                                                   *
        !            11: * INPUT: handle to write to                                         *
        !            12: ********************************************************************/
        !            13: 
        !            14: void demoGetTitle(HANDLE hConOut)
        !            15: {
        !            16:   BOOL bSuccess;
        !            17:   CHAR szTitleBuf[256]; /* buffer for the current console title */
        !            18:   CHAR szTemp[256];
        !            19:   HANDLE hStdIn; /* standard input handle */
        !            20:   DWORD dwStdInMode; /* standard input handle mode */
        !            21:   DWORD dwBytesRead;
        !            22: 
        !            23:   setConTitle(__FILE__);
        !            24:   hStdIn = GetStdHandle(STD_INPUT_HANDLE);
        !            25:   PERR((int) hStdIn != -1,"GetStdHandle");
        !            26:   /* save the console mode */
        !            27:   bSuccess = GetConsoleMode(hStdIn, &dwStdInMode);
        !            28:   PERR(bSuccess, "GetConsoleMode");
        !            29:   /* turn on line input mode so we can enter a string. */
        !            30:   /* when turning on ENABLE_LINE_INPUT, you MUST also turn on */
        !            31:   /* ENABLE_ECHO_INPUT. */
        !            32:   bSuccess = SetConsoleMode(hStdIn, dwStdInMode | ENABLE_LINE_INPUT |
        !            33:       ENABLE_ECHO_INPUT);
        !            34:   PERR(bSuccess, "SetConsoleMode");
        !            35:   myPuts(hConOut, "Let's get the console title with GetConsoleTitle.");
        !            36:   /* get the console title */
        !            37:   dwBytesRead = GetConsoleTitle(szTitleBuf, sizeof(szTitleBuf));
        !            38:   PERR(dwBytesRead, "GetConsoleTitle");
        !            39:   sprintf(szTemp, "The console title is: %s", szTitleBuf);
        !            40:   myPuts(hConOut, szTemp);
        !            41:   myPuts(hConOut, "\nNow let's set a new console title with SetConsoleTitle.");
        !            42:   myPuts(hConOut, "\nEnter a new console title:");
        !            43:   bSuccess = ReadFile(hStdIn, szTitleBuf, 256, &dwBytesRead, NULL);
        !            44:   PERR(bSuccess, "ReadFile");
        !            45:   /* null terminate the string - less two for cr/lf */
        !            46:   szTitleBuf[dwBytesRead - 2] = 0;
        !            47:   bSuccess = SetConsoleTitle(szTitleBuf);
        !            48:   PERR(bSuccess, "SetConsoleTitle");
        !            49:   /* restore the console title to the original mode */
        !            50:   bSuccess = SetConsoleMode(hStdIn, dwStdInMode);
        !            51:   PERR(bSuccess, "SetConsoleMode");
        !            52:   myPuts(hConOut, "\nHit enter to return...");
        !            53:   myGetchar();
        !            54:   return;
        !            55: }

unix.superglobalmegacorp.com

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