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