• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

ascii graphics in Windows

DarkForceRising

Senior member
Several semesters ago, I programmed a very basic version of Space Invaders in C, using the ncurses ascii library in Ubuntu Linux. I am now in a class where I have Visual C++, and can easily program in Windows. What I would like to know is if there is a comparable ascii graphics library for Windows. If possible, I want to port my little program over, but I don't know how.

Any suggestions?
 
In "raw" Win32 you would create a window and a compatible offscreen bitmap buffer (for double-buffering), create a font (probably Courier New so it's fixed-width instead of proportional), then use TextOut to write the characters to the offscreen buffer.

Then you'd use a timer interrupt for triggering the screen updating.

I don't use .NET or Windows Forms at work, so I don't know what the equivalent logic would be for them.

There's also DirectX and XNA Game Studio (requires C#) if you wanted to get fancy.

CodeProject.com might have some sample code for animation / double-buffering and simple tutorials on win32 and forms text functions. Google can turn up more.

Petzold's Programming Windows is the bible of Win32 UI programming.
 
Here's some code my brother sent me. Look up the functions on msdn.microsoft.com to get details, but this is a "library" he uses to draw console graphics:
PT_CGUI:😛T_CGUI()
{
// Init the window stuff
hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
hConsoleIn = GetStdHandle( STD_INPUT_HANDLE );
GetConsoleScreenBufferInfo( hConsoleOut, &csbiInfo );

// Just cause
SetConsoleMode(hConsoleIn, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT);
}
int PT_CGUI::getWidth()
{
return csbiInfo.dwSize.X;
}

int PT_CGUI::getHeight()
{
return csbiInfo.dwSize.Y;
}
void PT_CGUI::clearScreen()
{
for (int x = 0; x <= csbiInfo.dwSize.X; x++)
for (int y = 0; y <= csbiInfo.dwSize.Y; y++)
draw(x, y, ' ', 0x00);
}
int PT_CGUI::getKeyPress(bool& specialKey)
{
if (_kbhit() == 0)
return -1;

int input = _getch();

specialKey = false;
if (input == 0xE0) // Special key, like arrows
{
specialKey = true;
input = _getch();
}
return input;
}
void PT_CGUI:😀raw(int x, int y, char c, WORD color)
{
COORD Coords;
DWORD Dummy;

Coords.X = x;
Coords.Y = y;

WriteConsoleOutputCharacter( hConsoleOut, &c, 1, Coords, &Dummy );
WriteConsoleOutputAttribute( hConsoleOut, &color, 1, Coords, &Dummy );
}
 
There's more, but I figured that would be enough to get you going, and my brother had to leave so he didn't send all the code. I thought I had a copy somewhere but couldn't find it.
 
Back
Top