-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cpp
More file actions
205 lines (181 loc) · 6.01 KB
/
Console.cpp
File metadata and controls
205 lines (181 loc) · 6.01 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "Console.h"
#include<iostream>
using namespace std;
HANDLE hConsoleOutput;
HANDLE hConsoleInput;
// Ham thay doi kich co man hinh console.
// Ham xoa man hinh khong bi dut(lag).
void clrscr(void)
{
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
COORD Home = { 0, 0 };
DWORD dummy;
hConsoleOutput = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
FillConsoleOutputCharacter(hConsoleOutput, ' ', screen_buffer_info.dwSize.X * screen_buffer_info.dwSize.Y, Home, &dummy);
screen_buffer_info.dwCursorPosition.X = 0;
screen_buffer_info.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(hConsoleOutput, screen_buffer_info.dwCursorPosition);
}
// Ham dich chuyen con tro den toa do x, y.
void gotoXY(SHORT x, SHORT y)
{
COORD Cursor_an_Pos = { x, y };
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}
// Tra ve vi tri x hien tai.
SHORT wherex()
{
CONSOLE_SCREEN_BUFFER_INFO coninfo;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOutput, &coninfo);
return coninfo.dwCursorPosition.X;
}
// Tra ve vi tri y hien tai.
SHORT wherey()
{
CONSOLE_SCREEN_BUFFER_INFO coninfo;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOutput, &coninfo);
return coninfo.dwCursorPosition.Y;
}
// Ham to mau.
void setColor(WORD color)
{
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);
}
// Ham thay doi mau nen hien thi.
void setBackgroundColor(WORD color)
{
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;
color <<= 4; // Dich trai 3 bit de phu hop voi mau nen
wAttributes &= 0xff0f; // Cai 0 cho 1 bit chu nhay va 3 bit mau nen
wAttributes |= color;
SetConsoleTextAttribute(hConsoleOutput, wAttributes);
}
WORD textattr()
{
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleInfo);
return ConsoleInfo.wAttributes;
}
void resettextattr()
{
DWORD Mau_Mac_Dinh = textattr();
SetConsoleTextAttribute(hConsoleOutput, Mau_Mac_Dinh);
}
// Ham in mau chu va thay doi mai nen hien thi theo vi tri x, y.
void setColorBGTextXY(SHORT x, SHORT y, WORD color, WORD background, LPSTR str, ...)
{
gotoXY(x, y);
setBackgroundColor(background);
setColor(color);
/*In duoc nhieu chu hon*/
va_list args;
va_start(args, str);
vprintf(str, args);
va_end(args);
/*In duoc nhieu chu hon*/
resettextattr();
//setColor(7);
}
// Ham an hien con tro.
void Cursor(BOOL bVisible, DWORD dwSize)
{
CONSOLE_CURSOR_INFO ConsoleCursorInfo;
ConsoleCursorInfo.bVisible = bVisible;
ConsoleCursorInfo.dwSize = dwSize; // Phan tram bao trum o cua con tro chuot
SetConsoleCursorInfo(hConsoleOutput, &ConsoleCursorInfo);
}
// Xoa so luong dong, SStartPos - Vi tri bat dau xoa, SNumberRow so luong dong can xoa.
void deleteRow(SHORT SStartPos, SHORT SNumberRow)
{
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
COORD Pos = { 0, SStartPos };
DWORD Tmp;
GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleInfo);
FillConsoleOutputCharacter(hConsoleOutput, ' ', ConsoleInfo.dwSize.X * SNumberRow, Pos, &Tmp);
FillConsoleOutputAttribute(hConsoleOutput, 15, ConsoleInfo.dwSize.X * SNumberRow, Pos, &Tmp);
SetConsoleCursorPosition(hConsoleOutput, Pos);
}
// ham ve hộp
void P_box(int x, int y, int w, int h, int rim_color, int num){
// vẽ viền khung
// setBackgroundColor(237);
setColor(rim_color);
for (int i = 0; i < num; i++)
{
for (int ix = x; ix < x + w; ix++)
{
gotoXY(ix, y);
cout << char(196);
gotoXY(ix, y + h);
cout << char(196);
}
for (int iy = y; iy < y + h; iy++)
{
gotoXY(x, iy);
cout << char(179);
gotoXY(x + w, iy);
cout << char(179);
}
y += h;
}
// vẽ các góc ở trên và dưới
gotoXY(x, y - h * num);
cout << char(218);
gotoXY(x + w, y - h * num);
cout << char(191);
gotoXY(x, y);
cout << char(192);
gotoXY(x + w, y);
cout << char(217);
}
void xoathongtin()
{ int x1 = 50,y=21;
gotoXY(x1 + 38, y + 1); cout<<" ";
gotoXY(x1+ 1, y + 5);
cout << " ";
gotoXY(x1+ 1, y + 7);
cout << " ";
gotoXY(x1+ 1, y + 9);
cout << " ";
gotoXY(x1+ 1, y + 11);
cout << " ";
gotoXY(x1+ 28, y + 6);
cout << " ";
gotoXY(x1+ 28, y + 8);
cout << " ";
gotoXY(x1+ 28, y + 10);
cout << " ";
gotoXY(x1+ 49, y + 6);
cout << " ";
gotoXY(x1+ 49, y + 9);
cout << " ";
gotoXY(x1+ 65, y + 4);
cout << " ";
gotoXY(x1+ 65, y + 5);
cout << " ";
gotoXY(x1+ 61, y + 7);
cout << " ";
gotoXY(x1+ 61, y + 9);
cout << " ";
gotoXY(x1+ 70, y + 10);
cout << " ";
gotoXY(x1+ 71, y + 11);
cout << " ";
gotoXY(x1+ 67, y + 12);
cout << " ";
}