Last active
January 14, 2024 07:07
-
-
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
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> | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example on Win9x.