/
Barlist.cpp
482 lines (398 loc) · 15 KB
/
Barlist.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
///////////////////////////////////////////////////////////////////////
// Barlist - Barlist Extensible Application Framework
// Copyright © 1999-2024 Washington State Department of Transportation
// Bridge and Structures Office
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Alternate Route Open Source License as
// published by the Washington State Department of Transportation,
// Bridge and Structures Office.
//
// This program is distributed in the hope that it will be useful, but
// distribution is AS IS, WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the Alternate Route Open Source License for more details.
//
// You should have received a copy of the Alternate Route Open Source
// License along with this program; if not, write to the Washington
// State Department of Transportation, Bridge and Structures Office,
// P.O. Box 47340, Olympia, WA 98503, USA or e-mail
// Bridge_Support@wsdot.wa.gov
///////////////////////////////////////////////////////////////////////
// Barlist.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Resource.h"
#include <initguid.h>
#include "Barlist.h"
#include "AboutDlg.h"
#include "BarlistCATID.h"
#include "BarlistCommandIDs.h"
#include "MainFrm.h"
// This is the range of command IDs for all plug-in commands... all means all commands added
// to the menus of the Barlist executable program, the AppPlugin document and view menus,
// and plugin supplied menus, toolbars, and accelerator tables. This is the range of commands
// that non-unique command IDs, provide by external components, get mapped into.
#define BARLIST_FIRST_PLUGIN_COMMAND 0xADFF // the first plugin command will map to this command ID
#define BARLIST_LAST_PLUGIN_COMMAND 0xDFFF // this is the end of the command range that MFC lets us use
#define BARLIST_TOTAL_PLUGIN_COMMAND_COUNT (BARLIST_LAST_PLUGIN_COMMAND-BARLIST_FIRST_PLUGIN_COMMAND) // this is the total number of plug in commands that we will support
// we are reserving 12,800 command IDs for plug-in commands. Assuming each plugin reserves 256 (0x0100) commands, we can support a total of 50 plugins
// Barlist itself can accept plug-in commands. We have to carve out a little bit of the range defined above for our use.
#define BARLIST_PLUGIN_COMMAND_COUNT 0x0100 // we'll reserve 256 command IDs for direct Barlist plug-in commands
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBarlistApp
BEGIN_MESSAGE_MAP(CBarlistApp, CEAFPluginApp)
//{{AFX_MSG_MAP(CBarlistApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_JOINARPLIST, OnHelpJoinArpList)
ON_COMMAND(ID_HELP_INET_WSDOT, OnHelpInetWsdot)
ON_COMMAND(ID_HELP_INET_BARLIST, OnHelpInetBarlist)
ON_COMMAND(ID_HELP_INET_ARP, OnHelpInetARP)
ON_COMMAND(ID_HELP,OnHelp)
//}}AFX_MSG_MAP
// Standard file based document commands
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBarlistApp construction
CBarlistApp::CBarlistApp()
{
}
CBarlistApp::~CBarlistApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CBarlistApp object
CBarlistApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBarlistApp initialization
CString CBarlistApp::GetProductCode()
{
// Return the Product Code from InstallShield
// This code uniquely identifies Barlist so do not change it
#if defined _WIN64
return "{EABF062C-C2F8-4CEB-8CCF-E53B538F067F}";
#else
return "{92B7294A-DB06-4B6F-A337-F7964DB57760}";
#endif
}
CString CBarlistApp::GetDocumentationRootLocation()
{
if ( UseOnlineDocumentation() )
{
// NOTE: The following approach allows third party distributers to use their own server for documentation.
// Their installer should write the documentation root location to HKLM\Settings\DocumentationRoot.
// This value will be the default when the documentation root setting is read for a specific user from HKCU\Settings\DocumentationRoot
// If the HKCU value isn't found, the default from HKLM is used.
// Get the default location for the documentation root from the local machine registry hive
// If not present, use the WSDOT location
CString strDefaultDocumentationRootLocation = GetLocalMachineString(_T("Settings"),_T("DocumentationRoot"), _T("http://www.wsdot.wa.gov/eesc/bridge/software/Documentation/"));
// Get the user's setting, using the local machine setting as the default if not present
CString strDocumentationRootLocation = GetProfileString(_T("Settings"),_T("DocumentationRoot"),strDefaultDocumentationRootLocation);
return strDocumentationRootLocation;
}
else
{
CString str(GetAppLocation());
#if defined _DEBUG
#if defined _WIN64
str.Replace(_T("RegFreeCOM\\x64\\Debug\\"),_T(""));
#else
str.Replace(_T("RegFreeCOM\\Win32\\Debug\\"),_T(""));
#endif
#else
// in a real release, the path doesn't contain RegFreeCOM\\Release, but that's
// ok... the replace will fail and the string wont be altered.
#if defined _WIN64
str.Replace(_T("RegFreeCOM\\x64\\Release\\"),_T(""));
#else
str.Replace(_T("RegFreeCOM\\Win32\\Release\\"),_T(""));
#endif
#endif
CString strLocation;
strLocation.Format(_T("%sDocs\\"),str);
return strLocation;
}
}
LPCTSTR CBarlistApp::GetRegistryKey()
{
return _T("Washington State Department of Transportation");
}
LPCTSTR CBarlistApp::GetAppPluginCategoryName()
{
return _T("Barlist Application Plugin");
}
CATID CBarlistApp::GetAppPluginCategoryID()
{
return CATID_BarlistAppPlugin;
}
LPCTSTR CBarlistApp::GetPluginCategoryName()
{
return _T("Barlist Plugin");
}
CATID CBarlistApp::GetPluginCategoryID()
{
return CATID_BarlistPlugin;
}
CEAFSplashScreenInfo CBarlistApp::GetSplashScreenInfo()
{
CBitmap bmp;
CEAFSplashScreenInfo info;
VERIFY(bmp.LoadBitmap(IDB_SPLASH));
info.m_hBitmap = bmp;
info.m_TextColor = WHITE; // color of the information text drawn onto the splash screen
info.m_TextFormat = DT_TOP | DT_LEFT | DT_SINGLELINE | DT_MODIFYSTRING | DT_END_ELLIPSIS | DT_WORDBREAK;
info.m_TextRect = CRect(120,135,515,315); // rectangle on the splash screen bitmap where text is written
bmp.Detach();
return info;
}
CMDIFrameWnd* CBarlistApp::CreateMainFrame()
{
// don't call base class, the functionality is being replaced
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
{
delete pMainFrame;
return nullptr;
}
// files can be opened with drag and drop
pMainFrame->DragAcceptFiles(TRUE);
return pMainFrame;
}
CATID CBarlistApp::GetComponentInfoCategoryID()
{
return CATID_BarlistComponentInfo;
}
BOOL CBarlistApp::InitInstance()
{
#if defined _DEBUG
//_crtBreakAlloc = 31589; // causes program to break at a specific memory allocation
#endif
// // Tip of the Day
// // Get the names of all the *.tip files in the application folder
// std::vector<CString> strTipFiles;
// CFileFind finder;
// CString str(GetAppLocation());
//#if defined _DEBUG
//#if defined _WIN64
// str.Replace(_T("RegFreeCOM\\x64\\Debug\\"),_T(""));
//#else
// str.Replace(_T("RegFreeCOM\\Win32\\Debug\\"),_T(""));
//#endif
//#else
// // in a real release, the path doesn't contain RegFreeCOM\\Release, but that's
// // ok... the replace will fail and the string wont be altered.
//#if defined _WIN64
// str.Replace(_T("RegFreeCOM\\x64\\Release\\"),_T(""));
//#else
// str.Replace(_T("RegFreeCOM\\Win32\\Release\\"),_T(""));
//#endif
//#endif
// str += CString(_T("*.tip"));
// BOOL bWorking = finder.FindFile(str);
// while ( bWorking )
// {
// bWorking = finder.FindNextFile();
// CString strTipFile = finder.GetFilePath();
// strTipFiles.push_back(strTipFile);
// }
// EnableTipOfTheDay(strTipFiles);
// Reserve the total range of command IDs that can be used for ALL Barlist App Plugins.
// ALL means all commands added to the menus of the main executable, the
// EAFAppPlugin document and view menus, and plugin supplied menus,
// toolbars, and accelerator tables
CEAFPluginCommandManager::ReserveTotalCommandIDRange(BARLIST_FIRST_PLUGIN_COMMAND,BARLIST_LAST_PLUGIN_COMMAND);
// Reserve BARLIST_PLUGIN_COMMAND_COUNT command IDs for commands that get added
// to the main application
UINT nCommands = GetPluginCommandManager()->ReserveCommandIDRange(BARLIST_PLUGIN_COMMAND_COUNT);
ATLASSERT(nCommands == BARLIST_PLUGIN_COMMAND_COUNT);
// user can dbl-click on a file to open
EnableShellOpen();
if ( !CEAFPluginApp::InitInstance() )
{
return FALSE;
}
// Must be done after call to base class InitInstance because OLE has not been
// initialized yet.
//WBFL::System::ComCatMgr::CreateCategory(_T("Barlist Application Plugin"),CATID_BarlistAppPlugin); // this is done by the base class
WBFL::System::ComCatMgr::CreateCategory(_T("Barlist Components"),CATID_BarlistComponentInfo);
// Need to let drag and drop messages through
// See http://helgeklein.com/blog/2010/03/how-to-enable-drag-and-drop-for-an-elevated-mfc-application-on-vistawindows-7/
::ChangeWindowMessageFilter(WM_DROPFILES,MSGFLT_ADD);
::ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
::ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
return TRUE;
}
int CBarlistApp::ExitInstance()
{
return CEAFApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// CBarlistApp message handlers
/////////////////////////////////////////////////////////////////////////////
// CBarlistApp commands
CString CBarlistApp::GetVersion(bool bIncludeBuildNumber) const
{
CString strExe( m_pszExeName );
strExe += _T(".exe");
CVersionInfo verInfo;
verInfo.Load(strExe);
#if defined _DEBUG || defined _BETA_VERSION
// always include the build number in debug and beta versions
bIncludeBuildNumber = true;
#endif
CString strVersion = verInfo.GetProductVersionAsString(bIncludeBuildNumber);
return strVersion;
}
CString CBarlistApp::GetVersionString(bool bIncludeBuildNumber) const
{
CString str(_T("Version "));
str += GetVersion(bIncludeBuildNumber);
#if defined _BETA_VERSION
str += CString(_T(" BETA"));
#endif
str += CString(_T(" - Built on "));
str += CString(__DATE__);
return str;
}
void CBarlistApp::RegistryInit()
{
// Application wide settings go under Barlist
// Each application plug in will create it's own hive in the registry
// We need to tweek the name here because this is actually the Barlist.exe
free((void*)m_pszProfileName);
m_pszProfileName = _tcsdup(_T("Barlist"));
CEAFPluginApp::RegistryInit();
}
void CBarlistApp::RegistryExit()
{
CEAFPluginApp::RegistryExit();
}
void CBarlistApp::OnHelp()
{
// do nothing... just need this so MFC doesn't hide help buttons
}
CString CBarlistApp::GetWsdotUrl()
{
// CString url = GetProfileString(_T("Settings"), _T("WsdotUrl"), _T("http://www.wsdot.wa.gov"));
CString strDefault(_T("http://www.wsdot.wa.gov"));
HKEY key;
Int32 result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Washington State Department of Transportation\\Barlist\\Settings"),0,KEY_QUERY_VALUE,&key);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
TCHAR url[MAX_PATH];
DWORD size = MAX_PATH;
DWORD type;
result = ::RegQueryValueEx(key,_T("WsdotUrl"),0,&type,(LPBYTE)&url[0],&size);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
::RegCloseKey(key);
return url;
}
CString CBarlistApp::GetWsdotBridgeUrl()
{
// CString url = GetProfileString(_T("Settings"), _T("WsdotBridgeUrl"), _T("http://www.wsdot.wa.gov/eesc/bridge"));
CString strDefault(_T("http://www.wsdot.wa.gov/eesc/bridge"));
HKEY key;
Int32 result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Washington State Department of Transportation\\Barlist\\Settings"),0,KEY_QUERY_VALUE,&key);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
TCHAR url[MAX_PATH];
DWORD size = MAX_PATH;
DWORD type;
result = ::RegQueryValueEx(key,_T("WsdotBridgeUrl"),0,&type,(LPBYTE)&url[0],&size);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
::RegCloseKey(key);
return url;
}
CString CBarlistApp::GetBarlistUrl()
{
CString strDefault(_T("http://www.wsdot.wa.gov/eesc/bridge/software/index.cfm?fuseaction=software_detail&software_id=69"));
HKEY key;
Int32 result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Washington State Department of Transportation\\Barlist\\Settings"),0,KEY_QUERY_VALUE,&key);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
TCHAR url[MAX_PATH];
DWORD size = MAX_PATH;
DWORD type;
result = ::RegQueryValueEx(key,_T("BarlistUrl"),0,&type,(LPBYTE)&url[0],&size);
if ( result != ERROR_SUCCESS )
{
return strDefault;
}
::RegCloseKey(key);
return url;
}
void CBarlistApp::OnHelpInetWsdot()
{
HINSTANCE hInstance = ::ShellExecute(m_pMainWnd->GetSafeHwnd(),
_T("open"),
GetWsdotUrl(),
0,0,SW_SHOWDEFAULT);
if ( hInstance <= (HINSTANCE)HINSTANCE_ERROR )
{
AfxMessageBox(IDS_E_ONLINERESOURCES);
}
}
void CBarlistApp::OnHelpJoinArpList()
{
HINSTANCE hInstance = ::ShellExecute(m_pMainWnd->GetSafeHwnd(),
_T("open"),
_T("http://www.pgsuper.com/drupal/forum"),
0,0,SW_SHOWDEFAULT);
if ( hInstance <= (HINSTANCE)HINSTANCE_ERROR)
{
AfxMessageBox(IDS_E_ONLINERESOURCES);
}
}
void CBarlistApp::OnHelpInetARP()
{
HINSTANCE hInstance = ::ShellExecute(m_pMainWnd->GetSafeHwnd(),
_T("open"),
_T("http://wsdot.wa.gov/eesc/bridge/alternateroute"),
0,0,SW_SHOWDEFAULT);
if ( hInstance <= (HINSTANCE)HINSTANCE_ERROR )
{
AfxMessageBox(IDS_E_ONLINERESOURCES);
}
}
void CBarlistApp::OnHelpInetBarlist()
{
HINSTANCE hInstance = ::ShellExecute(m_pMainWnd->GetSafeHwnd(),
_T("open"),
GetBarlistUrl(),
0,0,SW_SHOWDEFAULT);
if ( hInstance <= (HINSTANCE)HINSTANCE_ERROR )
{
AfxMessageBox(IDS_E_ONLINERESOURCES);
}
}
// App command to run the dialog
void CBarlistApp::OnAppAbout()
{
CAboutDlg dlg;
dlg.DoModal();
}
BOOL CBarlistApp::OnCmdMsg(UINT nID,int nCode,void* pExtra,AFX_CMDHANDLERINFO* pHandlerInfo)
{
// For some reason, this method is needed otherwise the base class version
// doesn't get called... even though the base class method is virtual
return CEAFPluginApp::OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
}