Skip to content

Instantly share code, notes, and snippets.

@k-takata
Last active January 14, 2024 07:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-takata/a5a56b9904da48ef8ee2e04161055a14 to your computer and use it in GitHub Desktop.
Save k-takata/a5a56b9904da48ef8ee2e04161055a14 to your computer and use it in GitHub Desktop.
A sample program to draw graphics on a command prompt or a dos window
#include <windows.h>
BOOL IsWindows9x()
{
return (GetVersion() >= 0x80000000);
}
int main(int argc, char *argv[])
{
HWND hWnd;
HDC hdc;
char szOldText[80], szId[32], szTemp[32];
int x, y;
GetConsoleTitle(szOldText, sizeof(szOldText));
do {
wsprintf(szId, "grph%08X", GetTickCount());
SetConsoleTitle(szId);
do {
Sleep(100);
GetConsoleTitle(szTemp, sizeof(szTemp));
} while (lstrcmp(szId, szTemp));
if (IsWindows9x()) {
hWnd = FindWindowEx(NULL, NULL, "tty", szId);
} else {
hWnd = FindWindowEx(NULL, NULL, "ConsoleWindowClass", szId);
}
} while (hWnd == NULL);
SetConsoleTitle(szOldText);
if (IsWindows9x()) {
hWnd = FindWindowEx(hWnd, NULL, "ttyGrab", NULL);
}
hdc = GetDC(hWnd);
for(y = 0; y < 256; y++)
for(x = 0; x < 256; x++)
SetPixelV(hdc, x, y, RGB(x, y, (510 - x - y) / 2));
ReleaseDC(hWnd, hdc);
return 0;
}
@k-takata
Copy link
Author

k-takata commented Nov 2, 2016

Example on Win9x.

grph3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment