UNPKG

1.66 kBtext/x-cView Raw
1// A test program for CreateConsoleScreenBuffer / SetConsoleActiveScreenBuffer
2//
3
4#include <windows.h>
5#include <stdio.h>
6#include <conio.h>
7#include <io.h>
8#include <cassert>
9
10#include "TestUtil.cc"
11
12int main()
13{
14 HANDLE origBuffer = GetStdHandle(STD_OUTPUT_HANDLE);
15 HANDLE childBuffer = CreateConsoleScreenBuffer(
16 GENERIC_READ | GENERIC_WRITE,
17 FILE_SHARE_READ | FILE_SHARE_WRITE,
18 NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
19
20 SetConsoleActiveScreenBuffer(childBuffer);
21
22 while (true) {
23 char buf[1024];
24 CONSOLE_SCREEN_BUFFER_INFO info;
25
26 assert(GetConsoleScreenBufferInfo(origBuffer, &info));
27 trace("child.size=(%d,%d)", (int)info.dwSize.X, (int)info.dwSize.Y);
28 trace("child.cursor=(%d,%d)", (int)info.dwCursorPosition.X, (int)info.dwCursorPosition.Y);
29 trace("child.window=(%d,%d,%d,%d)",
30 (int)info.srWindow.Left, (int)info.srWindow.Top,
31 (int)info.srWindow.Right, (int)info.srWindow.Bottom);
32 trace("child.maxSize=(%d,%d)", (int)info.dwMaximumWindowSize.X, (int)info.dwMaximumWindowSize.Y);
33
34 int ch = getch();
35 sprintf(buf, "%02x\n", ch);
36 DWORD actual = 0;
37 WriteFile(childBuffer, buf, strlen(buf), &actual, NULL);
38 if (ch == 0x1b/*ESC*/ || ch == 0x03/*CTRL-C*/)
39 break;
40
41 if (ch == 'b') {
42 setBufferSize(origBuffer, 40, 25);
43 } else if (ch == 'w') {
44 setWindowPos(origBuffer, 1, 1, 38, 23);
45 } else if (ch == 'c') {
46 setCursorPos(origBuffer, 10, 10);
47 }
48 }
49
50 SetConsoleActiveScreenBuffer(origBuffer);
51
52 return 0;
53}