-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cpp
More file actions
106 lines (87 loc) · 4.6 KB
/
Copy pathConsole.cpp
File metadata and controls
106 lines (87 loc) · 4.6 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
// ********************************************************************************
/// <summary>
/// the searched and confronted ways for manipulation of Windows's console screen by the code itself in runtime.
/// </summary>
/// <created>ʆϒʅ,02.10.2018</created>
/// <changed>ʆϒʅ,13.10.2019</changed>
// ********************************************************************************
#include "Packers.h"
#include "Console.h"
// console screen properties
HANDLE consoleOutput = GetStdHandle ( STD_OUTPUT_HANDLE ); // for simplification
CONSOLE_SCREEN_BUFFER_INFOEX screenBinfoEX;
CONSOLE_SCREEN_BUFFER_INFOEX screenBinfoEXstorage;
CONSOLE_FONT_INFOEX fontInfoEX;
CONSOLE_CURSOR_INFO cursorInfo;
HWND consoleWindow = GetConsoleWindow (); // for simplification
void ConsoleFont ( const LPCWSTR& fontName )
{
fontInfoEX.cbSize = sizeof ( fontInfoEX ); // getting the right size (important for many structures in the windows API)
GetCurrentConsoleFontEx ( consoleOutput, false, &fontInfoEX );
lstrcpyW ( fontInfoEX.FaceName, fontName ); // copies a specific number of characters from a source string to a buffer
// in this case the properties of the wished font to the suitable field
SetCurrentConsoleFontEx ( consoleOutput, false, &fontInfoEX );
}
void ConsoleFontSize ( const COORD& fontSize )
{
fontInfoEX.cbSize = sizeof ( fontInfoEX ); // getting the right size (important for many structures in the windows API)
GetCurrentConsoleFontEx ( consoleOutput, false, &fontInfoEX );
fontInfoEX.dwFontSize.X = fontSize.X; // for not true type fonts
fontInfoEX.dwFontSize.Y = fontSize.Y; // Y is enough for the size of true type fonts
SetCurrentConsoleFontEx ( consoleOutput, false, &fontInfoEX );
}
void ConsoleFontColour ( const WORD& fontColour )
{
SetConsoleTextAttribute ( consoleOutput, fontColour );
}
void ConsoleScreenPosition ( const COORD& screenPosition )
{
// draw the window from the coordinate argument
// and ignore the new width, height in pixels (cx, cy) i.e. (0, 0) by setting the SWP_NOSIZE flag
// for other flags check MSDN
SetWindowPos ( consoleWindow, HWND_TOP, screenPosition.X, screenPosition.Y, 0, 0, SWP_NOSIZE );
}
void ConsoleScreenSize ( const COORD& ColRowCount )
{
// setting the new console screen size in pixels:
// converting needed columns and rows numbers to needed screen size in pixel (the numbers are reckoned by trying different numbers)
RECT consoleScreen;
GetWindowRect ( consoleWindow, &consoleScreen );
MoveWindow ( consoleWindow, consoleScreen.top, consoleScreen.left, static_cast<int> ( ColRowCount.X * 9.3 ), ColRowCount.Y * 22, true );
screenBinfoEX.cbSize = sizeof ( screenBinfoEX ); // getting the right size (important for many structures in the windows API)
GetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
screenBinfoEX.srWindow.Left = 0; // width 0 to
screenBinfoEX.srWindow.Right = ColRowCount.X; // the number of columns (doesn't work: need legacy console tick)
screenBinfoEX.srWindow.Top = 0; // height 0 to
screenBinfoEX.srWindow.Bottom = ColRowCount.Y; // the number of rows
SetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
SetConsoleWindowInfo ( consoleOutput, false, &screenBinfoEX.srWindow );
}
void ConsoleScreenColour ( const COLORREF& BGcolour )
{
screenBinfoEX.cbSize = sizeof ( screenBinfoEX ); // getting the right size (important for many structures in the windows API)
GetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
//screenBinfoEX.srWindow.Left = 0; // width 0 to
//screenBinfoEX.srWindow.Right = ColRowCount.X; // the number of columns (doesn't work: need legacy console tick)
//screenBinfoEX.srWindow.Top = 0; // height 0 to
//screenBinfoEX.srWindow.Bottom = ColRowCount.Y; // the number of rows
screenBinfoEX.ColorTable [0] = BGcolour; // background colour
SetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
SetConsoleWindowInfo ( consoleOutput, false, &screenBinfoEX.srWindow );
}
void ConsoleCursorState ( const bool& CursorVisible )
{
GetConsoleCursorInfo ( consoleOutput, &cursorInfo );
cursorInfo.bVisible = CursorVisible;
//cursorInfo.dwSize = _int;
SetConsoleCursorInfo ( consoleOutput, &cursorInfo );
}
void ColourCouter ( const std::string& strCharacter, const WORD& Colour )
{
GetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
screenBinfoEXstorage = screenBinfoEX;
SetConsoleTextAttribute ( consoleOutput, Colour );
std::cout << strCharacter;
SetConsoleTextAttribute ( consoleOutput, screenBinfoEXstorage.wAttributes );
GetConsoleScreenBufferInfoEx ( consoleOutput, &screenBinfoEX );
}