-
Notifications
You must be signed in to change notification settings - Fork 1
/
screen.cpp
54 lines (44 loc) · 1.27 KB
/
screen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <windows.h>
static int g_nScreenIndex;
static HANDLE g_hScreen[2];
void ScreenInit()
{
CONSOLE_CURSOR_INFO cci;
// 가상의 콘솔창 2개룰 만든다.
g_hScreen[0] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
g_hScreen[1] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
// 커서 숨기기
cci.dwSize = 1;
cci.bVisible = FALSE;
SetConsoleCursorInfo(g_hScreen[0], &cci);
SetConsoleCursorInfo(g_hScreen[1], &cci);
}
void ScreenFlipping()
{
Sleep(10);
SetConsoleActiveScreenBuffer(g_hScreen[g_nScreenIndex]);
g_nScreenIndex = !g_nScreenIndex;
}
void ScreenClear()
{
COORD Coor = { 0, 0 };
DWORD dw;
FillConsoleOutputCharacter(g_hScreen[g_nScreenIndex], ' ', 80 * 25, Coor, &dw);
}
void ScreenRelease()
{
CloseHandle(g_hScreen[0]);
CloseHandle(g_hScreen[1]);
}
void ScreenPrint(int x, int y, char *string)
{
DWORD dw;
COORD CursorPosition = { x, y };
SetConsoleCursorPosition(g_hScreen[g_nScreenIndex], CursorPosition);
WriteFile(g_hScreen[g_nScreenIndex], string, strlen(string), &dw, NULL);
}
// 1 ~ 15 까지 색상 설정 가능
void SetColor(unsigned short color)
{
SetConsoleTextAttribute(g_hScreen[g_nScreenIndex], color);
}