Last active
September 30, 2015 09:53
-
-
Save k-takata/4564ae4deca758420514 to your computer and use it in GitHub Desktop.
Test of CreateConsoleScreenBuffer and SetConsoleActiveScreenBuffer (Doesn't work on winpty)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <conio.h> | |
#include <io.h> | |
int main() | |
{ | |
HANDLE hScr, hConOut; | |
DWORD written; | |
int c; | |
char buf[10]; | |
hConOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
hScr = CreateConsoleScreenBuffer( | |
GENERIC_READ | GENERIC_WRITE, | |
FILE_SHARE_READ | FILE_SHARE_WRITE, | |
NULL, CONSOLE_TEXTMODE_BUFFER, NULL); | |
SetConsoleActiveScreenBuffer(hScr); | |
while (1) { | |
c = getch(); | |
sprintf(buf, "%02x ", c); | |
WriteFile(hScr, buf, strlen(buf), &written, NULL); | |
if (c == 0x1b || c == 0x03) | |
break; | |
} | |
SetConsoleActiveScreenBuffer(hConOut); | |
CloseHandle(hScr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment