-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.cpp
More file actions
150 lines (118 loc) · 3.75 KB
/
Copy pathdebug.cpp
File metadata and controls
150 lines (118 loc) · 3.75 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
/*
* debug.cpp
* Creates a second window that prints out debug information
* similar to printf utility. This routine will need
* significant development.
*/
#include "stdafx.h"
#include "debug.h"
#include "resource.h"
// Internal Use Only
LRESULT CALLBACK WndProcDebug(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
#if (DEBUG == TRUE) // Debug Code
// Global variables:
HWND hWnd;
int line;
LRESULT CALLBACK WndProcDebug(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
ATOM debugInit(HINSTANCE hInstance, int nCmdShow,
TCHAR szWindowClass[MAX_LOADSTRING]) {
WNDCLASSEX wcex;
HWND dWnd;
ATOM retClassX;
HBRUSH hbrush = CreateSolidBrush(RGB(0,0,0));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_SAVEBITS;
wcex.lpfnWndProc = (WNDPROC)WndProcDebug;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SOLITAIRE);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = hbrush;
wcex.lpszMenuName = (LPCTSTR)NULL;
wcex.lpszClassName = "Debug Output";
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
retClassX = RegisterClassEx(&wcex);
dWnd = CreateWindow("Debug Output", "Debug Output",
WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VSCROLL,
50, 50, 500, 300, NULL, NULL, hInstance, NULL);
ShowWindow(dWnd, nCmdShow);
UpdateWindow(dWnd);
hWnd = dWnd; // Store our window handel so we draw here and not on the main window.
line = 0; // Reset global line location
return retClassX;
}
/*
* Compatible with printf syntax. We use an sprintf to concatenate the arguments
* and then output the text to the debug screen. We try to keep track of where the
* Text goes, but this is still somewhat buggy.
*/
_CRTIMP int __cdecl dprintf(char *output, ...) {
va_list marker;
int count, len;
HDC hdc = GetDC(hWnd);
HGDIOBJ hfnt, hOldFont;
char *outString;
va_start(marker, output);
count = vprintf(output, marker) + 1;
outString = (char*)malloc((size_t)count);
vsprintf(outString, output, marker);
len = (int)strlen(outString);
hfnt = GetStockObject(ANSI_VAR_FONT);
if (hOldFont = SelectObject(hdc, hfnt)) {
// White on black theme
SetBkColor(hdc, RGB(0, 0, 0));
SetTextColor(hdc, RGB(255, 255, 255));
TextOut(hdc, 0, line, outString, len);
SelectObject(hdc, hOldFont);
}
line += 15;
DeleteObject(hfnt);
ReleaseDC(hWnd, hdc);
free((void*)outString);
va_end(marker);
return count - 1; // For Compatibility
}
#else // Non Debug Code
LRESULT CALLBACK WndProcDebug(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, message, wParam, lParam); // Just return handel to the OS
}
ATOM debugInit(HINSTANCE hInstance, int nCmdShow,
TCHAR szWindowClass[MAX_LOADSTRING]) {
return NULL; // No Class will be registered, hopefully will throw an exception
// I don't think that I use the return anywhere anyways.
// It's more for compatibility than anything else.
}
/*
* Compatible with printf syntax. We use an sprintf to concatenate the arguments
* and then output the text to the debug screen. We try to keep track of where the
* Text goes, but this is still somewhat buggy.
*/
_CRTIMP int __cdecl dprintf(char *output, ...) {
va_list marker;
int count;
va_start(marker, output);
count = vprintf(output, marker);
return count; // For Compatibility
// Even though we do nothing, we still have to return the byte count.
}
#endif