-
Notifications
You must be signed in to change notification settings - Fork 4
/
Debug.cpp
232 lines (175 loc) · 4.77 KB
/
Debug.cpp
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Debug.cpp: implementation of the CDebug class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "audtest.h"
#include "Debug.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CString ctDebug = "Debug";
CString ctLevel = "Level";
CString ctWindow = "Window";
int cdID = 12323;
static CTopDebug m_DebugObj;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDebug::CDebug()
{
m_nLine = 0;
}
CDebug::~CDebug()
{
}
BEGIN_MESSAGE_MAP(CDebug, CEdit)
//{{AFX_MSG_MAP(CDebug)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDebug message handlers
/////////////////////////////////////////////////////////////////////////////
// CTopDebug
CTopDebug::CTopDebug() : m_wDebug()
{
m_nDebugLevel = 0;
}
CTopDebug::~CTopDebug()
{
}
BEGIN_MESSAGE_MAP(CTopDebug, CWnd)
//{{AFX_MSG_MAP(CTopDebug)
ON_WM_WINDOWPOSCHANGED()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTopDebug message handlers
CTopDebug * CTopDebug::GetDebugObj()
{
return &m_DebugObj;
}
void CTopDebug::Init(CWnd *pParent)
{
CRect crbuild;
CString csw;
WINDOWPLACEMENT wndpl;
// don't call SetDebugLevel, use the direct = assignment
// we don't want the 0->Non-zero processing of the function
m_nDebugLevel = AfxGetApp()->GetProfileInt( ctDebug, ctLevel, 0);
m_pParent = pParent;
if ( 0 == GetDebugLevel()) // are we debugging??
return; // nope, do nothing
crbuild.SetRect( 0,0,100,100);
if ( ! GetSafeHwnd())
{
Create( NULL, _T("Debugger"), WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
crbuild, pParent, cdID);
m_wDebug.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL,
crbuild, this, cdID+1);
}
csw = AfxGetApp()->GetProfileString( ctDebug, ctWindow, _T(""));
if ( csw && csw.GetLength()) // we have some
{
if ( 11 == swscanf_s( csw, _T("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"),
&wndpl.flags, &wndpl.length,
&wndpl.ptMinPosition.x, &wndpl.ptMinPosition.y,
&wndpl.ptMaxPosition.x, &wndpl.ptMaxPosition.y,
&wndpl.rcNormalPosition.bottom, &wndpl.rcNormalPosition.top,
&wndpl.rcNormalPosition.left, &wndpl.rcNormalPosition.right,
&wndpl.showCmd))
{
wndpl.showCmd = SW_SHOWNORMAL;
SetWindowPlacement( &wndpl);
}
}
SetWindowText(_T("Debug output"));
m_wDebug.SetWindowText(_T(""));
BringWindowToTop();
}
int CTopDebug::GetDebugLevel()
{
return m_nDebugLevel;
}
void CTopDebug::SetDebugLevel(int nNewLevel)
{
AfxGetApp()->WriteProfileInt( ctDebug, ctLevel, nNewLevel);
if ( m_nDebugLevel && !nNewLevel)
DestroyWindow(); // we're gone
else
if ( nNewLevel && !m_nDebugLevel)
Init( m_pParent); // re init
m_nDebugLevel = nNewLevel;
}
void CTopDebug::PrintString(LPCTSTR lpcsOut)
{
CString csout;
if ( ! GetSafeHwnd())
return; // no window to print to
m_wDebug.AddLine( lpcsOut);
}
void CTopDebug::PrintTwo(LPCTSTR lpcsOut, LPCTSTR lpcsO2)
{
CString csout;
CString css;
if ( ! GetSafeHwnd())
return; // no window to print to
css.Format(lpcsOut, lpcsO2);
m_wDebug.AddLine( css); // print it
}
void CTopDebug::PrintInt(LPCTSTR lpcsOut, int nOut)
{
CString csout;
CString css;
if ( ! GetSafeHwnd())
return; // no window to print to
css.Format(lpcsOut, nOut);
m_wDebug.AddLine( css); // print it
}
void CTopDebug::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CRect crc;
CWnd::OnWindowPosChanged(lpwndpos);
if ( ! m_wDebug.GetSafeHwnd())
return;
// TODO: Add your message handler code here
GetClientRect( crc);
m_wDebug.SetWindowPos( &wndTop, 0, 0, crc.right, crc.bottom, SWP_SHOWWINDOW);
}
void CDebug::AddLine(LPCTSTR lpNew)
{
CString csout;
CString csnew;
int nlength;
if ( ! GetSafeHwnd())
return;
m_nLine++;
GetWindowText( csout); // get current text
csnew.Format(_T("\r\n%5d: %s"), m_nLine, lpNew);
csout += csnew;
SetWindowText( csout);
nlength = csout.GetLength() - 1;
UpdateWindow();
SetSel( nlength-1, nlength, FALSE);
// SetSel( nlength-1, nlength, FALSE);
}
void CTopDebug::OnDestroy()
{
if ( GetSafeHwnd())
{
CString csout;
WINDOWPLACEMENT wndpl;
GetWindowPlacement( &wndpl);
csout.Format(_T("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"),
wndpl.flags, wndpl.length,
wndpl.ptMinPosition.x, wndpl.ptMinPosition.y,
wndpl.ptMaxPosition.x, wndpl.ptMaxPosition.y,
wndpl.rcNormalPosition.bottom, wndpl.rcNormalPosition.top,
wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.right,
wndpl.showCmd);
AfxGetApp()->WriteProfileString( ctDebug, ctWindow, csout);
}
CWnd::OnDestroy();
}