Archived from groups: rec.games.roguelike.development (
More info?)
I have actually used the windows console functions myself. They work
fairly well if you can work out which functions to use. So for anyone
interested, here are a few of the functions I wrote...
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
typedef unsigned char uchar;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
COORD cZero = {0, 0};
string next;
void initText()
{
AllocConsole();
SetConsoleMode(hStdIn, ENABLE_PROCESSED_INPUT);
}
void cls()
{
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOut, &csbi);
FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X *
csbi.dwSize.Y, cZero, &count);
SetConsoleCursorPosition(hStdOut, cZero);
}
void setPos(uchar xpos, uchar ypos)
{
COORD c = {xpos, ypos};
SetConsoleCursorPosition(hStdOut, c);
}
void resetPos()
{
SetConsoleCursorPosition(hStdOut, cZero);
}
void putStr(string s, uchar xpos, uchar ypos)
{
COORD c = {xpos, ypos};
SetConsoleCursorPosition(hStdOut, c);
cout << s;
}
void putStr(string s, uchar xpos, uchar ypos, uchar col)
{
COORD c = {xpos, ypos};
SetConsoleTextAttribute(hStdOut, col);
SetConsoleCursorPosition(hStdOut, c);
cout << s;
}
void putChar(char ch, uchar xpos, uchar ypos)
{
COORD c = {xpos, ypos};
SetConsoleCursorPosition(hStdOut, c);
cout << ch;
}
void putChar(char ch, uchar xpos, uchar ypos, uchar col)
{
COORD c = {xpos, ypos};
SetConsoleTextAttribute(hStdOut, col);
SetConsoleCursorPosition(hStdOut, c);
cout << ch;
}
void putStr(string s, uchar col)
{
SetConsoleTextAttribute(hStdOut, col);
cout << s;
}
INPUT_RECORD readKeyboard()
{
INPUT_RECORD input;
DWORD count;
ReadConsoleInput(hStdIn, &input, 1, &count);
FlushConsoleInputBuffer(hStdIn);
return input;
}
uchar readKey()
{
INPUT_RECORD input;
DWORD count;
ReadConsoleInput(hStdIn, &input, 1, &count);
FlushConsoleInputBuffer(hStdIn);
if(input.Event.KeyEvent.bKeyDown)
return input.Event.KeyEvent.uChar.AsciiChar;
else
return 0;
}
void setTextColor(uchar col)
{
SetConsoleTextAttribute(hStdOut, col);
}