-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMainDlg.cpp
More file actions
403 lines (341 loc) · 10.6 KB
/
MainDlg.cpp
File metadata and controls
403 lines (341 loc) · 10.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// MainDlg.cpp : implementation file
//
// (c) 1996-99 Andy Whittaker, Chester, England.
// mail@andywhittaker.com
//
#include "MainDlg.h"
#include "StatusDlg.h"
#include "Supervisor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFreeScanDlg dialog
IMPLEMENT_DYNAMIC(CFreeScanDlg, CPropertySheet);
CFreeScanDlg::CFreeScanDlg(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
AllocateAndAddPages();
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CFreeScanDlg::CFreeScanDlg(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AllocateAndAddPages();
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CFreeScanDlg::~CFreeScanDlg()
{
delete m_pDetailDlg;
delete m_pEngineViewDlg;
delete m_pStatusBitsDlg;
delete m_pDashBoardDlg;
delete m_pTCodesDlg;
delete m_pSensorDlg;
delete m_pAdvancedDlg;
delete m_pAbout;
delete m_pStatusDlg;
#ifdef _DEBUG
delete m_pEngineDlg; // Old Engine Data View
delete m_pRawMode00Dlg;
delete m_pRawMode01Dlg;
#endif // _DEBUG
if (m_pSupervisor!=NULL)
delete m_pSupervisor;
}
// Creates storage space for the PropertyPages
// then adds them to the dialog
void CFreeScanDlg::AllocateAndAddPages(void) {
// Status Dialog
m_pStatusDlg = new CStatusDlg;
// Allocate all of the classes for the PropertyPages
m_pDetailDlg = new CDetailDlg(m_pStatusDlg);
m_pEngineViewDlg = new CEngineViewDlg; // new view
m_pStatusBitsDlg = new CStatusBitsDlg; // Status Bits
m_pDashBoardDlg = new CDashBoardDlg;
m_pSensorDlg = new CSensorDlg;
m_pAdvancedDlg = new CAdvancedDlg;
m_pTCodesDlg = new CTCodesDlg;
m_pAbout = new CAbout;
// Now Add the pages to the Dialog
AddPage(m_pDetailDlg);
AddPage(m_pEngineViewDlg); // new view
AddPage(m_pStatusBitsDlg); // Status Bits
AddPage(m_pDashBoardDlg);
AddPage(m_pTCodesDlg);
AddPage(m_pSensorDlg);
AddPage(m_pAdvancedDlg);
#ifdef _DEBUG // Add these only in Debug builds
m_pEngineDlg = new CEngineDlg; // Old Engine Data View
m_pRawMode00Dlg = new CRawMode00;
m_pRawMode01Dlg = new CRawMode01;
AddPage(m_pEngineDlg); // Old Engine Data View
AddPage(m_pRawMode00Dlg);
AddPage(m_pRawMode01Dlg);
#endif // _DEBUG
AddPage(m_pAbout);
}
BEGIN_MESSAGE_MAP(CFreeScanDlg, CPropertySheet)
//{{AFX_MSG_MAP(CFreeScanDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CFreeScanDlg::SetLogoText(CString Text)
{
m_LogoText = Text;
}
void CFreeScanDlg::SetLogoFont(CString Name, int nHeight/* = 24*/,
int nWeight/* = FW_BOLD*/, BYTE bItalic/* = true*/, BYTE bUnderline/* = false*/)
{
if(m_fontLogo.m_hObject)
m_fontLogo.Detach();
m_fontLogo.CreateFont(nHeight, 0, 0, 0, nWeight, bItalic, bUnderline,0,0,0,0,0,0, Name);
}
// Updates all property pages in this dialog
void CFreeScanDlg::Update(const CEcuData* const ecuData)
{
if (IsWindow(*m_pDetailDlg))
{
m_pDetailDlg->Refresh(ecuData);
}
if (IsWindow(*m_pEngineViewDlg))
{
m_pEngineViewDlg->Refresh(ecuData);
}
if (IsWindow(*m_pStatusBitsDlg))
{
m_pStatusBitsDlg->Refresh(ecuData);
}
if (IsWindow(*m_pDashBoardDlg))
{
m_pDashBoardDlg->Refresh(ecuData);
}
if (IsWindow(*m_pTCodesDlg))
{
m_pTCodesDlg->Refresh(ecuData);
}
if (IsWindow(*m_pSensorDlg))
{
m_pSensorDlg->Refresh(ecuData);
}
if (IsWindow(*m_pAdvancedDlg))
{
m_pAdvancedDlg->Refresh(ecuData);
}
#ifdef _DEBUG // Handle these only in Debug builds
if (IsWindow(*m_pEngineDlg))
{ // Old Engine Data View
m_pEngineDlg->Refresh(ecuData);
}
if (IsWindow(*m_pRawMode00Dlg))
{
m_pRawMode00Dlg->Refresh(ecuData);
}
if (IsWindow(*m_pRawMode01Dlg))
{
m_pRawMode01Dlg->Refresh(ecuData);
}
#endif // _DEBUG
// UpdateData(TRUE);
}
// Writes a line of ASCII to the spy window
void CFreeScanDlg::WriteStatus(CString csText) {
csText = "Main: " + csText;
m_pStatusDlg->WriteStatus(csText);
}
// Writes a line of binary as ASCII to the spy window
void CFreeScanDlg::WriteASCII(unsigned char * buffer, int ilength){
m_pStatusDlg->WriteASCII(buffer, ilength);
}
void CFreeScanDlg::WriteLogEntry(LPCTSTR pstrFormat, ...) {
va_list args;
va_start(args, pstrFormat);
m_pStatusDlg->WriteLogEntry(pstrFormat, args);
}
void CFreeScanDlg::WriteStatusLogged(CString csText) {
m_pStatusDlg->WriteStatusTimeLogged(csText);
}
/////////////////////////////////////////////////////////////////////////////
// CFreeScanDlg message handlers
BOOL CFreeScanDlg::OnInitDialog()
{
// hide the buttons we do not want to show.
CWnd *pWnd = GetDlgItem( IDCANCEL );
ASSERT_VALID(pWnd);
pWnd->DestroyWindow();
pWnd = GetDlgItem( ID_APPLY_NOW );
ASSERT_VALID(pWnd);
pWnd->DestroyWindow();
pWnd = GetDlgItem( IDHELP );
ASSERT_VALID(pWnd);
pWnd->EnableWindow(FALSE);
//move the OK button
pWnd = GetDlgItem( IDOK );
ASSERT_VALID(pWnd);
pWnd->SetWindowText("Exit"); // rename OK to Exit
CRect rcTemp(0, 0, 0, 0);
int nLeft = 0;
pWnd->GetWindowRect(rcTemp);
ScreenToClient(rcTemp);
nLeft -= -235 + rcTemp.Width();
pWnd->MoveWindow(nLeft, rcTemp.top, rcTemp.Width(), rcTemp.Height());
CString buf;
// Load the version string from our resource
buf.LoadString(IDS_VERSION);
// This is for the Logo Text on the property sheet
SetLogoFont("Arial");
SetLogoText(buf);
// Create the "spy" window
m_pStatusDlg->Create(NULL);
buf = buf + " by Andy Whittaker";
WriteStatus(buf);
WriteStatus(_T("Starting Up.."));
// Initialise the communications supervisor
m_pSupervisor = new CSupervisor(this, m_pStatusDlg);
m_pDetailDlg->RegisterSupervisor(m_pSupervisor);
m_pEngineViewDlg->RegisterSupervisor(m_pSupervisor);
m_pStatusBitsDlg->RegisterSupervisor(m_pSupervisor);
m_pDashBoardDlg->RegisterSupervisor(m_pSupervisor);
m_pSensorDlg->RegisterSupervisor(m_pSupervisor);
m_pAdvancedDlg->RegisterSupervisor(m_pSupervisor);
m_pTCodesDlg->RegisterSupervisor(m_pSupervisor);
#ifdef _DEBUG // Add these only in Debug builds
m_pEngineDlg->RegisterSupervisor(m_pSupervisor);
m_pRawMode00Dlg->RegisterSupervisor(m_pSupervisor);
m_pRawMode01Dlg->RegisterSupervisor(m_pSupervisor);
#endif // _DEBUG
// We now start creating our User Interface
CPropertySheet::OnInitDialog();
// Initialise the first dialog sheet. It is done this way because
// it's only now that the Protocol window has been created and able
// to receive and answer messages.
m_pDetailDlg->Init();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
WriteStatus(_T("Ready.."));
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFreeScanDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{ // Paint our logo in list box
CPaintDC dc(this); // device context for painting
if (m_LogoText.IsEmpty())
{
}
else
{ // Draw a logo on our property sheet
// Thanks to Frumento Enrico for modifications
// and Nikolay Sokratov for the original.
BOOL bWizMode;
// Get the current style from PROPSHEETHEADER structure
if( m_psh.dwFlags & PSH_WIZARD )
bWizMode = TRUE; // It's in wizard mode
else
bWizMode = FALSE; // It's in property sheet mode
// If this is a Wizard, cannot retrieve the tab control dimension.
// So Get the Dialog's Window Rect
CRect rectTabCtrl;
if( bWizMode )
{
GetWindowRect(rectTabCtrl);
rectTabCtrl.OffsetRect(14,0); // A little correction
}
else
{
GetTabControl()->GetWindowRect(rectTabCtrl);
}
ScreenToClient(rectTabCtrl);
CRect rectOk;
GetDlgItem(IDOK)->GetWindowRect(rectOk);
ScreenToClient(rectOk);
dc.SetBkMode(TRANSPARENT);
CRect rectText;
rectText.left = rectTabCtrl.left;
rectText.top = rectOk.top;
rectText.bottom = rectOk.bottom;
rectText.right = rectOk.left;
CFont * OldFont = dc.SelectObject(&m_fontLogo);
// draw text in DC
COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));
// before drawing calculate Rect size and if greater reduce font size
CRect RealrectText;
BOOL bOK=FALSE;
BOOL bShouldDrawText=TRUE;
LOGFONT LogFont;
TEXTMETRIC tmText;
CFont *resizedfontLogo=&m_fontLogo;
RealrectText=rectText;
while (!bOK) {
CFont newfontLogo;
dc.DrawText( m_LogoText, &RealrectText,
DT_CALCRECT | DT_SINGLELINE | DT_LEFT | DT_VCENTER);
dc.GetTextMetrics(&tmText);
//leave space for a char on the right
if (RealrectText.right < (rectText.right- tmText.tmMaxCharWidth) )
bOK=TRUE;
resizedfontLogo->GetLogFont(&LogFont);
//set lower bound if we can't draw even with the smallest font
if (LogFont.lfHeight<8 && bOK==FALSE) {
bShouldDrawText=FALSE;
bOK=TRUE;
}
LogFont.lfHeight--;
newfontLogo.CreateFontIndirect(&LogFont);
resizedfontLogo= dc.SelectObject(&newfontLogo);
}
//doesn't draw if the font results too much little
if (bShouldDrawText) {
dc.DrawText( m_LogoText, rectText + CPoint(1,1),
DT_SINGLELINE | DT_LEFT | DT_VCENTER);
dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
dc.DrawText( m_LogoText, rectText,
DT_SINGLELINE | DT_LEFT | DT_VCENTER);
}
// restore old text color
dc.SetTextColor( OldColor);
// restore old font
dc.SelectObject(OldFont);
// Do not call CPropertySheet::OnPaint() for painting messages
// CPropertySheet::OnPaint();
}
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFreeScanDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFreeScanDlg::OnClose()
{
// Close the communications Supervisor
m_pSupervisor->ShutDown();
// Close the spy window
m_pStatusDlg->DestroyWindow();
}