|
|
1.1 root 1: #include <windows.h>
2: #include "console.h"
3:
1.1.1.2 ! root 4: /* Microsoft Developer Support
! 5: Copyright (c) 1992 Microsoft Corporation */
! 6:
1.1 root 7: /*******************************************************************
8: * FUNCTION: demoFillChar(HANDLE hConOut) *
9: * *
10: * PURPOSE: demonstrate FillConsoleOutputCharacter. Fill the entire *
11: * console with the character that the user hits *
12: * *
13: * INPUT: the output console to fill with characters *
14: ********************************************************************/
15:
16: void demoFillChar(HANDLE hConOut)
17: {
18: HANDLE hStdIn;
19: INPUT_RECORD inputBuf;
20: CHAR c; /* ascii character read from the console */
21: CONSOLE_SCREEN_BUFFER_INFO csbi;
22: COORD coordScreen = {0, 1}; /* location to start the attribute fill */
23: DWORD cCharsWritten;
24: BOOL bSuccess;
25: DWORD cInputEvents;
26:
27: setConTitle(__FILE__);
28: myPuts(hConOut, "Let's fill the console buffer with a given character by\n"
29: "using the FillConsoleOutputCharacter API. Hit a key to \n"
30: "fill the buffer with (hit ESC to return):");
31: hStdIn = GetStdHandle(STD_INPUT_HANDLE);
1.1.1.2 ! root 32: PERR(hStdIn != INVALID_HANDLE_VALUE, "GetStdHandle");
1.1 root 33: for(;;)
34: {
35: do
36: {
37: /* get input events until you get a key-down event */
38: bSuccess = ReadConsoleInput(hStdIn, &inputBuf, 1, &cInputEvents);
39: PERR(bSuccess, "ReadConsoleInput");
40: } while (inputBuf.EventType != KEY_EVENT ||
41: !inputBuf.Event.KeyEvent.bKeyDown);
42: c = (char) inputBuf.Event.KeyEvent.uChar.AsciiChar;
43: if (inputBuf.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
44: break;
45: /* we need to get the console buffer size */
46: bSuccess = GetConsoleScreenBufferInfo(hConOut, &csbi);
47: PERR(bSuccess, "GetConsoleScreenBufferInfo");
48: bSuccess = FillConsoleOutputCharacter(hConOut, /* screen buffer handle */
49: c, /* character to write */
50: (csbi.dwSize.X * csbi.dwSize.Y) - csbi.dwSize.X, /* number of chars */
51: coordScreen, /* x and y coordinates of first cell */
52: &cCharsWritten); /* receives number of cells written to */
53: PERR(bSuccess, "FillConsoleOutputCharacter");
54: }
55: return;
56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.