-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDebug.cpp
More file actions
91 lines (70 loc) · 1.96 KB
/
PDebug.cpp
File metadata and controls
91 lines (70 loc) · 1.96 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
// ---------------------------------------------------------------------
// PDebug Implementation
// ---------------------------------------------------------------------
#include "PDebug.h"
#include <iostream>
using namespace std;
// ---------------------------------------------------------------------
// PRIVATE
// ---------------------------------------------------------------------
// Console Creation
// Precondition: N/A
// Postcondition: Debug window allocated/Standard output redirected
bool PDebug::Create()
{
// Allocate a new console
// If creation fails,
if(AllocConsole())
{
// Redirect Standard output to the console
freopen("CONOUT$", "w", stdout);
// Return creation success
return 1;
}
// Return creation failure
return 0;
}
// ---------------------------------------------------------------------
// PUBLIC
// ---------------------------------------------------------------------
// Constructor
PDebug::PDebug()
{
// Initialise attributes
initComplete = 0;
}
// Deconstructor
PDebug::~PDebug()
{
// Free the console
FreeConsole();
}
// Initialise
// Precondition: N/A
// Postcondition: Debug Window setup
void PDebug::Initialise()
{
// If the window has not been create
if(!initComplete)
{
// Console info structure
CONSOLE_SCREEN_BUFFER_INFO coninfo;
// Console handle
HANDLE console = GetConsoleWindow();
// Console Mode
DWORD lpMode;
// Create window
initComplete = Create();
// Set console title
SetConsoleTitle(TEXT("Debug Console"));
// Set larger buffer size
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = 2500; // Large enough to remain useful
coninfo.dwSize.X = 237; // Full HD Max buffer width
// Set the size of the output buffer
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
// Allow Console scrolling
GetConsoleMode(console, &lpMode);
SetConsoleMode(console, lpMode & ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT);
}
}