![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Note that most of the information is in a block named 040904b0, which indicates that the information is in U.S. English. For international programmers, here are all the options: 0×0401 Arabic 0×0402 Bulgarian 0×0403 Catalan 0×0404 Traditional Chinese 0×0405 Czech 0×0406 Danish 0×0407 German 0×0408 Greek 0×0409 U.S. English 0×040A Castilian Spanish 0×040B Finnish 0×040C French 0×040D Hebrew 0×040E Hungarian 0×040F Icelandic 0×0410 Italian 0×0411 Japanese 0×0412 Korean 0×0413 Dutch 0×0414 Norwegian - Bokml 0×0810 Swiss Italian 0×0813 Belgian Dutch 0×0814 Norwegian - Nynorsk 0×0415 Polish 0×0416 Brazilian Portuguese 0×0417 Rhaeto-Romanic 0×0418 Romanian 0×0419 Russian 0×041A Croato-Serbian (Latin) 0×041B Slovak 0×041C Albanian 0×041D Swedish 0×041E Thai 0×041F Turkish 0×0420 Urdu 0×0421 Bahasa 0×0804 Simplified Chinese 0×0807 Swiss German 0×0809 U.K. English 0×080A Mexican Spanish 0×080C Belgian French 0×0C0C Canadian French 0×100C Swiss French 0×0816 Portuguese 0×081A Serbo-Croatian (Cyrillic) The information in this resource is what we read when the user opens the About dialog box. Lets design that dialog box now.
Designing the About BoxOur projects Help menu has an About About item in it; this somewhat awkwardly named item opens the About box that describes the application. Open the About dialog box now for editing, as shown in Figure 14.4. We place the information we fetch from the Version resource in a new label control. Create that now, add it to the About box, and give it the ID IDC_STATIC1. In addition, use ClassWizard to add a CString member variable to the text in IDC_STATIC1 named m_text. This is the member variable that holds the version information we want to display. Thats all we do here. When the user selects the About About item in the Help menu, the following code is currently executed in the application object: void CAboutApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } This is there we read our Version information, and were now ready to write some code. Getting Version InformationPrograms read the Version resource with GetFileVersionInfo(), which fills a buffer with version data. Its up to us to create that buffer, so first we call GetFileVersionInfoSize(), passing it the name of our program and a pointer to a value that is always set to 0. (Note that we must use double backwards slashes in text string parameters so they are not interpreted as escape characters.) void CAboutApp::OnAppAbout() { CAboutDlg aboutDlg; DWORD Zero, Size; ⇐ Size = GetFileVersionInfoSize(c:\\avc\\About\\debug\\About.exe, &Zero); ⇐ . . . Now we set aside a data buffer and call GetFileVersionInfo() to fill that buffer with data. Heres how you use GetFileVersionInfo() in general: BOOL GetFileVersionInfo( LPTSTR lptstrFilename, // pointer to filename string DWORD dwHandle, // ignored DWORD dwLen, // size of buffer LPVOID lpData // pointer to buffer to get file-version info. ) and heres how we use it in our code: void CAboutApp::OnAppAbout() { CAboutDlg aboutDlg; DWORD Zero, Size; Size = GetFileVersionInfoSize(c:\\avc\\About\\debug\\About.exe, &Zero); LPVOID VersionData = new char[Size]; ⇐ GetFileVersionInfo(c:\\avc\\About\\debug\\About.exe, Zero, Size, VersionData); ⇐ . . . Now weve read in the version data, and were ready to start reading data from the VersionData buffer. We begin with the ProductName entry. Getting Version Resource ValuesYou use VerQueryValue() to retrieve individual values from the Version resource data. BOOL VerQueryValue( const LPVOID pBlock, // buffer for version resource LPTSTR lpSubBlock, // value to retrieve LPVOID * lplpBuffer, // buffer for version pointer PUINT puLen // version-value length buffer ) Here are the formats of the lpSubBlock parameter: \ VerQueryValue() retrieves a pointer to a VS_FIXEDFILEINFO structure for the version resource \VarFileInfo\Translation Gets the translation table, an array of language and character-set identifiers. \StringFileInfo\lang-charset\string-name Gets a value from the version resource For example, we get the ProductName entry from the Version resource and place the product name, which is About Application for us, in a new CString object named FormattedString. This is the string we display in the About box. void CAboutApp::OnAppAbout() { CAboutDlg aboutDlg; DWORD Zero, Size; char Text[40]; Size = GetFileVersionInfoSize(c:\\avc\\About\\debug\\About.exe, &Zero); LPVOID VersionData = new char[Size]; GetFileVersionInfo(c:\\avc\\About\\debug\\About.exe, Zero, Size, VersionData); LPVOID TextData; ⇐ UINT TextSize = 0; ⇐ VerQueryValue(VersionData, \\StringFileInfo\\040904b0\\ProductName, &TextData, &TextSize); ⇐ CString FormattedString = (char *) TextData; ⇐ . . . This stores the name of the program in the CString object FormattedString, ready to display. Weve retrieved the product name for our application; we get the major and minor version numbers next. Getting the Major and Minor Version NumbersWe get the major and minor versions of the program (for example, if this is About 1.2, the major version is 1, the minor version is 2) by filling a VS_FIXEDFILEINFO structure. typedef struct _VS_FIXEDFILEINFO { DWORD dwSignature; DWORD dwStrucVersion; DWORD dwFileVersionMS; DWORD dwFileVersionLS; DWORD dwProductVersionMS; DWORD dwProductVersionLS; DWORD dwFileFlagsMask; DWORD dwFileFlags; DWORD dwFileOS; DWORD dwFileType; DWORD dwFileSubtype; DWORD dwFileDateMS; DWORD dwFileDateLS; } VS_FIXEDFILEINFO;
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |