Here's a few functions that I've cobbled together.
Code:
void GotoXY(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void GetXY(int *x, int *y)
{
CONSOLE_SCREEN_BUFFER_INFO csbInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbInfo);
*x = csbInfo.dwCursorPosition.X;
*y = csbInfo.dwCursorPosition.Y;
}
...
void ClrEol()
{
int i;
int x, y;
COORD a = { 80, 1 };
COORD b;
SMALL_RECT r;
DWORD len;
CHAR_INFO str[81];
for(i = 0; i < 80; i++) {
str[i].Char.AsciiChar = ' ';
str[i].Attributes = 0x07;
}
GetXY(&x, &y);
len = 80 - x;
b.X = 0;
b.Y = 0;
r.Top = y;
r.Left = x;
r.Bottom = y+1;
r.Right = (SHORT)(x + len);
WriteConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE), str, a, b, &r);
}
void ClrLine(int y)
{
GotoXY(0, y);
ClrEol();
}
void ClrScr(void)
{
COORD a = {0,0};
DWORD nwrite;
FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07, 2000, a, &nwrite);
}
Not saying that these are the best way to do things, but as far as I can tell, it works.
Obviously, it's an ugly hack to use constant 2000 in ClrScr.
--
Mats