You are on page 1of 2

//định nghĩa các hàm liên quan đến đồ họa

#include"games.h"
int getx()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
return csbi.dwCursorPosition.X;
return -1;
}
int gety()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
return csbi.dwCursorPosition.Y;
return -1;
}
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD Cursor_an_Pos = { x, y };
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}
void setcolor(WORD color)
{
HANDLE hConsoleOutput;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);

WORD wAttributes = screen_buffer_info.wAttributes;


color &= 0x000f;
wAttributes &= 0xfff0;
wAttributes |= color;

SetConsoleTextAttribute(hConsoleOutput, wAttributes);
}
void showcur(bool CursorVisibility)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor = { 1, CursorVisibility };
SetConsoleCursorInfo(handle, &cursor);
}
int inputKey()
{
if (_kbhit())
{
int key = _getch();

if (key == 224)
{
key = _getch();
return key + 1000;
}

return key;
}
else
{
return KEY_NONE;
}
return KEY_NONE;
}
void textcolor(int x)
{
HANDLE mau;
mau = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(mau, x);
}
void SetWindowSize(SHORT width, SHORT height)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

SMALL_RECT WindowSize;
WindowSize.Top = 0;
WindowSize.Left = 0;
WindowSize.Right = width;
WindowSize.Bottom = height;

SetConsoleWindowInfo(hStdout, 1, &WindowSize);
}

You might also like