CONSOLE_CURSOR_INFO cl_curinfo;
CONSOLE_SCREEN_BUFFER_INFO cl_bufinfo;
SECURITY_ATTRIBUTES SecAttribs = {sizeof(SECURITY_ATTRIBUTES), 0, 1};
HANDLE cl_conout = 0;
short CCsrlin(void);
short CPos(void);
int32 CInp (int32 toggle);
void CLocate (int x, int y);
void CColor (int fg, int bg);
void CSize (int width, int height);
void CFont(char* FontName, int FontSize);
void CHideCursor();
void CShowCursor();
WORD CScreen(short l, short c, BOOL f){
COORD cp = {--c, --l};
DWORD t;
WORD a;
if (f){
ReadConsoleOutputAttribute(cl_conout, & a, 1, cp, & t) ;
return a;
} else {
ReadConsoleOutputCharacterA(cl_conout, (char *) & a, 1, cp, & t) ;
return a & 0xff;
}
}
short CCsrlin(void)
{
cl_conout = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, & SecAttribs, OPEN_EXISTING, 0, 0);
GetConsoleScreenBufferInfo(cl_conout, & cl_bufinfo);
return cl_bufinfo.dwCursorPosition.Y + 1;
}
short CPos(void)
{
cl_conout = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, & SecAttribs, OPEN_EXISTING, 0, 0);
GetConsoleScreenBufferInfo(cl_conout, & cl_bufinfo);
return cl_bufinfo.dwCursorPosition.X + 1;
}
int32 CInp (int32 toggle)
{
HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD irInputRecord;
DWORD dwEventsRead;
INT32 cChar;
while(ReadConsoleInputA (hStdin, &irInputRecord, 1, &dwEventsRead)) /* Read key press */
if (irInputRecord.EventType == KEY_EVENT)
{
cChar = irInputRecord.Event.KeyEvent.wVirtualScanCode;
if (toggle) {
if (!irInputRecord.Event.KeyEvent.bKeyDown) cChar = -cChar;
}else{
if (!irInputRecord.Event.KeyEvent.bKeyDown) cChar = cChar +128;
}
return cChar;
}
return EOF;
}
void CLocate (int x, int y)
{
COORD pos = {x-1, y-1};
HANDLE output = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output, pos);
}
void CColor (int fg, int bg)
{
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
int color = bg * 16 + fg;
SetConsoleTextAttribute(output, color);
}
void CSize (int width, int height)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD bufferSize = {width, height};
SMALL_RECT rect = {0,0, width-1, height-1};
SetConsoleScreenBufferSize(hConsole, bufferSize);
SetConsoleWindowInfo(hConsole, TRUE, &rect);
}
void CFont(char* FontName, int FontSize)
{
CONSOLE_FONT_INFOEX info = {0};
info.cbSize = sizeof(info);
info.dwFontSize.Y = FontSize; // leave X as zero
info.FontWeight = FW_NORMAL;
const size_t cSize = strlen(FontName)+1;
wchar_t* wc = new wchar_t[32];
mbstowcs (wc, FontName, cSize);
wcscpy(info.FaceName, wc);
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, &info);
}
void CHideCursor()
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
void CShowCursor()
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = TRUE;
SetConsoleCursorInfo(consoleHandle, &info);
}