Skip to content
Navigation Menu
{{ message }}
forked from wyrover/book-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbout.cpp
More file actions
492 lines (401 loc) · 18.1 KB
/
Copy pathAbout.cpp
File metadata and controls
492 lines (401 loc) · 18.1 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
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
483
484
485
486
487
488
489
490
491
492
// About.cpp : implementation file
//
#include "stdafx.h"
#include "GDIExplorer.h"
#include "About.h"
#include "winver.h"
#include "WinReg.h"
#define DIM(x) (sizeof(x) / sizeof(x[0]))
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static DWORD aContextIds [] = {
#if 0
IDC_ABOUT_FILEDESCRIPTION, IDH_ABOUT_FILEDESCRIPTION,
IDC_ABOUT_VERSION, IDH_ABOUT_VERSION,
IDC_ABOUT_LEGALCOPYRIGHT, IDH_ABOUT_LEGALCOPYRIGHT,
IDC_ABOUT_COMMENTS, IDH_ABOUT_COMMENTS,
IDC_ABOUT_OSVERSION, IDH_ABOUT_OSVERSION,
IDC_ABOUT_PROCESSORVERSION, IDH_ABOUT_PROCESSORVERSION,
IDC_ABOUT_LEGALTRADEMARKS, IDH_ABOUT_LEGALTRADEMARKS,
#endif
0, 0
} ;
/////////////////////////////////////////////////////////////////////////////
// CAbout dialog
CAbout::CAbout(CWnd* pParent /*=NULL*/)
: CDialog(CAbout::IDD, pParent)
{
//{{AFX_DATA_INIT(CAbout)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CAbout::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAbout)
DDX_Control(pDX, IDC_ABOUT_LEGALCOPYRIGHT, c_LegalCopyright);
DDX_Control(pDX, IDC_ABOUT_FILEDESCRIPTION, c_FileDescription);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAbout, CDialog)
//{{AFX_MSG_MAP(CAbout)
ON_WM_CONTEXTMENU()
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAbout message handlers
void CAbout::OnContextMenu(CWnd* pWnd, CPoint point)
{
AfxGetApp()->WinHelp (HELP_CONTEXTMENU, (DWORD) (LPVOID) aContextIds) ;
}
BOOL CAbout::OnHelpInfo(HELPINFO* pHelpInfo)
{
ASSERT (HELPINFO_WINDOW == pHelpInfo->iContextType) ;
if (HELPINFO_WINDOW == pHelpInfo->iContextType) { // Must be for a control!
int nID ;
int nIndex ;
// Get the control's window handle
HWND hwndCtl = (HWND)pHelpInfo->hItemHandle ;
ASSERT (NULL != hwndCtl) ;
ASSERT (::IsWindow (hwndCtl)) ;
// Get this control's ID
nID = ::GetDlgCtrlID (hwndCtl) ;
// Don't bother running WinHelp unless we have help for the control
for (nIndex = 0 ; nIndex < DIM (aContextIds) - 2; nIndex += 2) {
if (aContextIds [nIndex] == (DWORD) nID) {
AfxGetApp()->WinHelp (HELP_WM_HELP,
(DWORD) (LPVOID) aContextIds) ;
return TRUE ;
}
}
}
return CDialog::OnHelpInfo(pHelpInfo);
}
static const TCHAR szValueNameBase [] = TEXT("\\StringFileInfo\\040904E4\\") ;
static const TCHAR szProductName [] = TEXT("ProductName") ;
// Number of characters in the base portion of the value name string
#define BASECHARS (DIM(szValueNameBase) - 1)
void CAbout::DisplayExecutableVersionInfo ()
{
BOOL bResult ; // Result of Boolean functions
DWORD dwVerInfoSize ; // Size of version information
DWORD dwHandle ; // Extraneous but required parameter
HMODULE hmod ; // Application's module handle
LPVOID pVerInfo ; // File version info pointer
LPVOID pValue ; // Value from version info
TCHAR szFullPath [_MAX_PATH] ;// Application executable path
TCHAR szValueName [256] ; // Name of value to retrieve
UINT uLength ; // Length of retrieved value
CWnd * Ctl; // Control
// Get the full path to this executable file
hmod = ::GetModuleHandle (NULL) ;
::GetModuleFileName (hmod, szFullPath, DIM(szFullPath)) ;
// Determine the size buffer needed to store the version information:
dwVerInfoSize = ::GetFileVersionInfoSize (szFullPath, &dwHandle) ;
if (0 == dwVerInfoSize)
return ;
// Allocate a buffer for the version info block
pVerInfo = malloc (dwVerInfoSize) ;
ASSERT (NULL != pVerInfo) ;
if (NULL == pVerInfo)
return ;
// Read the version info block into the buffer
VERIFY(::GetFileVersionInfo (szFullPath, dwHandle, dwVerInfoSize, pVerInfo)) ;
// Build value name base string...
lstrcpy (szValueName, szValueNameBase) ;
// Build the \StringFileInfo\040904E4\ProductName value name
lstrcpy (szValueName + BASECHARS, szProductName) ;
// Retrieve the value
bResult = ::VerQueryValue (pVerInfo, szValueName, &pValue, &uLength) ;
// Format the output for the dialog caption
// Get the current caption then append to it the ProductName value
GetWindowText (szValueName, sizeof (szValueName) / sizeof(TCHAR)) ;
lstrcat (szValueName, (LPCTSTR)pValue) ;
// Change the dialog caption - normally "About <ProductName>"
SetWindowText (szValueName) ;
// For each control in the dialog...
// fetch the version info name from the control's initial window text.
// retrieve the value with that name,
// change the control's window text to the retrieved value.
// Technique derived from GENERIC.C.
Ctl = GetWindow (GW_CHILD) ;
while (NULL != Ctl)
{
// Build value name base string...
lstrcpy (szValueName, szValueNameBase) ;
// Build the \StringFileInfo\040904E4\<ControlText> value name
// The Win32 API contains the following predefined version information strings:
// CompanyName LegalCopyright
// FileDescription OriginalFilename
// FileVersion ProductName
// InternalName ProductVersion
// Get the control's text...
Ctl->GetWindowText ( szValueName + BASECHARS,
DIM(szValueName) - BASECHARS) ;
// Retrieve the value
bResult = ::VerQueryValue (pVerInfo, szValueName, &pValue, &uLength) ;
// If version information is available and the version information name exists...
if (bResult)
// If a value exists for the version information name...
if (0 != uLength && NULL != pValue)
// Change the control's text to the version information value
Ctl->SetWindowText ((LPCTSTR)pValue) ;
Ctl = Ctl->GetWindow (GW_HWNDNEXT) ;
}
// Free the memory for the version information block
free (pVerInfo) ;
}
void CAbout::DisplayOperatingSystemVersionInfo ()
{
BOOL bResult ;
NTTYPE NtOsType ;
TCHAR OSVer [256] ;
CString FormatString ;
// Get OS version information
OSVERSIONINFO osver ;
osver.dwOSVersionInfoSize = sizeof (osver) ; // Must initialize size member!
bResult = ::GetVersionEx (&osver) ; // Retrieve version info
ASSERT (FALSE != bResult) ;
if (FALSE == bResult)
return ;
switch (osver.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT: // Windows NT
NtOsType = GetNTVersion () ;
FormatString.LoadString (IDS_PLATFORM_WIN32_NT + NtOsType);
break ;
case VER_PLATFORM_WIN32s: // Win32s on Windows 3.1
FormatString.LoadString (IDS_PLATFORM_WIN32s);
break ;
case VER_PLATFORM_WIN32_WINDOWS: // Windows 95
FormatString.LoadString(IDS_PLATFORM_WIN32_WINDOWS);
// Windows 95 encodes extra info in HIWORD(dwBuildNumber)
// Remove unwanted junk
osver.dwBuildNumber = LOWORD (osver.dwBuildNumber) ;
break ;
default: // Unknown operating system
FormatString.LoadString(IDS_PLATFORM_UNKNOWN);
break ;
}
wsprintf (OSVer, FormatString,
osver.dwMajorVersion,
osver.dwMinorVersion,
osver.dwBuildNumber) ;
SetDlgItemText (IDC_ABOUT_OSVERSION, OSVer) ;
}
//
// void CAbout::DisplayProcessorVersionInfo (DWORD dwPlatformId)
//
// dwPlatformId Hardware platform ID returned by GetVersionEx
//
// PURPOSE: Displays the processor's version
//
// COMMENTS:
//
void CAbout::DisplayProcessorVersionInfo ()
{
BOOL bRecognized ;
SYSTEM_INFO si ;
CString Buffer;
CString Format;
// Get current system information
// Zero the structure as Windows 95 and older versions of Windows NT
// do not initialize *all* fields of the structure (specifically,
// wProcessorLevel and wProcessorRevision. Unfortunately, the
// documentation does not say *which* versions of Windows NT do not
// support setting these fields. Therefore use the new fields if
// they seem to have been set. otherwise use the "obsolete" fields.
ZeroMemory (&si, sizeof (si)) ;
::GetSystemInfo (&si) ;
// Determine processor architecture
bRecognized = TRUE ;
switch (si.wProcessorArchitecture) {
default:
bRecognized = FALSE ;
Buffer.LoadString (IDS_PROCESSOR_ARCHITECTURE_UNKNOWN );
break ;
case PROCESSOR_ARCHITECTURE_INTEL: // Intel
switch (si.wProcessorLevel) {
default:
bRecognized = FALSE ;
Buffer.LoadString ( IDS_PROCESSOR_LEVEL_INTEL_UNKNOWN) ;
break ;
case 3: // Intel 80386
Format.LoadString (
IDS_PROCESSOR_ARCHITECTURE_INTEL_386_486);
Buffer.FormatMessage ( Format,
TEXT ("80386"),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 4: // Intel 80486
Format.LoadString (
IDS_PROCESSOR_ARCHITECTURE_INTEL_386_486);
Buffer.FormatMessage ( Format,
TEXT ("80486"),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 5: // Intel Pentium
Format.LoadString (
IDS_PROCESSOR_ARCHITECTURE_INTEL_PENTIUM);
Buffer.FormatMessage ( Format,
TEXT ("Pentium"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
}
break ;
case PROCESSOR_ARCHITECTURE_MIPS: // MIPS
switch (si.wProcessorLevel) { // 00xx - xx is 8-bit implementation #
Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_MIPS);
default:
bRecognized = FALSE ;
Buffer.LoadString (IDS_PROCESSOR_LEVEL_MIPS_UNKNOWN);
break ;
case 0x0004: // MIPS R4000
Buffer.FormatMessage (Format,
TEXT ("R4000"),
LOBYTE (si.wProcessorRevision)) ;
break ;
}
break ;
case PROCESSOR_ARCHITECTURE_ALPHA: // Alpha
Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_ALPHA);
switch (si.wProcessorLevel) { // xxxx - 16-bit processor version #
default:
bRecognized = FALSE ;
Buffer.LoadString (IDS_PROCESSOR_LEVEL_ALPHA_UNKNOWN);
break ;
case 21064: // Alpha 21064
Buffer.FormatMessage (Format,
TEXT ("21064"),
(TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 21066: // Alpha 21066
Buffer.FormatMessage ( Format,
TEXT ("21066"),
(TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 21164: // Alpha 21164
Buffer.FormatMessage ( Format,
TEXT ("21164"),
(TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
LOBYTE (si.wProcessorRevision)) ;
break ;
}
break ;
case PROCESSOR_ARCHITECTURE_PPC: // Power PC
Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_PPC);
switch (si.wProcessorLevel) { // xxxx - 16-bit processor version #
default:
bRecognized = FALSE ;
Buffer.LoadString (IDS_PROCESSOR_LEVEL_PPC_UNKNOWN);
break ;
case 1: // Power PC 601
Buffer.FormatMessage (Format,
TEXT ("601"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 3: // Power PC 603
Buffer.FormatMessage (Format,
TEXT ("603"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 4: // Power PC 604
Buffer.FormatMessage (Format,
TEXT ("604"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 6: // Power PC 603+
Buffer.FormatMessage (Format,
TEXT ("603+"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 9: // Power PC 604+
Buffer.FormatMessage (Format,
TEXT ("604+"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
case 20: // Power PC 620
Buffer.FormatMessage (Format,
TEXT ("620"),
HIBYTE (si.wProcessorRevision),
LOBYTE (si.wProcessorRevision)) ;
break ;
}
break ;
}
// If the processor type isn't yet recognized, check the, supposedly,
// "obsolete" dwProcessorType field of the SYSTEM_INFO structure for
// a reasonable value and use it.
if (!bRecognized) {
switch (si.dwProcessorType) {
case PROCESSOR_INTEL_386:
Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_386);
break ;
case PROCESSOR_INTEL_486:
Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_486);
break ;
case PROCESSOR_INTEL_PENTIUM:
Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_PENTIUM);
break ;
case PROCESSOR_MIPS_R4000:
Buffer.LoadString (IDS_PROCESSOR_NOREV_MIPS_R4000);
break ;
case PROCESSOR_ALPHA_21064:
Buffer.LoadString (IDS_PROCESSOR_NOREV_ALPHA_21064);
break ;
}
}
SetDlgItemText (IDC_ABOUT_PROCESSORVERSION, Buffer) ;
}
BOOL CAbout::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow (NULL) ;
// Update controls with application version info
DisplayExecutableVersionInfo () ;
// Update controls with operating system version info
DisplayOperatingSystemVersionInfo () ;
// Update controls with processor version info
DisplayProcessorVersionInfo () ;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
NTTYPE CAbout::GetNTVersion ()
{
TCHAR szValue [256] ;
DWORD dwType = 0;
DWORD dwSize = sizeof (szValue) ;
HKEY hKey = NULL ;
LONG lStatus ;
static const TCHAR szProductOptions [] = TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions") ;
static const TCHAR szProductType [] = TEXT("ProductType") ;
static const TCHAR szWinNT [] = TEXT("WINNT") ; // Windows NT Workstation is running
static const TCHAR szServerNT [] = TEXT("SERVERNT") ; // Windows NT Server (3.5 or later) is running
static const TCHAR szAdvancedServerNT [] = TEXT("LANMANNT") ; // Windows NT Advanced Server (3.1) is running
lStatus = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE,szProductOptions, 0, KEY_QUERY_VALUE, &hKey) ;
if (ERROR_SUCCESS != lStatus)
return typeDefault ; // Windows NT
lStatus = ::RegQueryValueEx (hKey, szProductType, NULL, &dwType, (LPBYTE)szValue, &dwSize) ;
::RegCloseKey (hKey) ;
if (ERROR_SUCCESS != lStatus)
return typeDefault ; // Windows NT
if (0 == _tcsicmp (szWinNT, szValue))
return typeWorkstation ; // Windows NT Workstation
else if (0 == _tcsicmp (szServerNT, szValue))
return typeServer ; // Windows NT Server
else if (0 == _tcsicmp (szAdvancedServerNT, szValue))
return typeAdvancedServer ; // Windows NT Advanced Server (3.1)
return typeDefault ; // Windows NT
}
You can’t perform that action at this time.
