Skip to content

Instantly share code, notes, and snippets.

@k-takata
Last active September 30, 2015 09:53
Show Gist options
  • Save k-takata/4564ae4deca758420514 to your computer and use it in GitHub Desktop.
Save k-takata/4564ae4deca758420514 to your computer and use it in GitHub Desktop.
Test of CreateConsoleScreenBuffer and SetConsoleActiveScreenBuffer (Doesn't work on winpty)
#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