-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCScreen.cpp
More file actions
70 lines (57 loc) · 1.67 KB
/
CScreen.cpp
File metadata and controls
70 lines (57 loc) · 1.67 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* (c) Cranium, aka Череп. 2014
* GNU GPL
*
*/
#include "CScreen.h"
#include <conio.h>
const char *msgs[] = {
"",
"Failed GetStdHandle(): INVALID_HANDLE_VALUE",
"Failed GetConsoleCursorInfo()",
"Failed SetConsoleCursorInfo()",
"Failed SetConsoleCursorPosition()"
};
const char *CSScreenException::what() {
return msgs[err];
}
CScreen::CScreen() {
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsoleOutput == INVALID_HANDLE_VALUE)
throw CSScreenException(1); // "INVALID_HANDLE_VALUE"
if (!GetConsoleCursorInfo(hConsoleOutput, &oldCursorInfo))
throw CSScreenException(2);
curCursorInfo.dwSize = oldCursorInfo.dwSize;
curCursorInfo.bVisible = oldCursorInfo.bVisible;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
oldTextAttr = csbi.wAttributes;
}
CScreen::~CScreen() {
SetConsoleCursorInfo(hConsoleOutput, &oldCursorInfo);
SetConsoleTextAttribute(hConsoleOutput, oldTextAttr);
}
void CScreen::cursor_show(bool visible) {
curCursorInfo.bVisible = visible;
if (!SetConsoleCursorInfo(hConsoleOutput, &curCursorInfo))
throw CSScreenException(3);
}
void CScreen::text_attr(WORD attr) {
SetConsoleTextAttribute(hConsoleOutput, attr);
}
void CScreen::pos(int x, int y, char ch) {
COORD point;
point.X = static_cast<SHORT>(x);
point.Y = static_cast<SHORT>(y);
if (!SetConsoleCursorPosition(hConsoleOutput, point))
throw CSScreenException(4);
if (ch > 0)
_putch(ch);
}
void CScreen::pos_str(int x, int y, const char *str) {
pos(x, y);
_cprintf("%s", str);
}
void CScreen::cls() {
system("cls");
}