|
/////////////////////////////////////////////////////////////////
class VFileVersion : public WObject
{
private:
//
// Version information strings
//
WString companyName;
WString fileDescription;
WString fileVersion;
WString internalName;
WString legalCopyright;
WString originalFilename;
WString productName;
WString productVersion;
protected:
//
// Version information structures
//
void *versionData;
WByte *translationTable;
public:
WString GetCompanyName() const;
WString GetFileDescription() const;
WString GetFileVersion() const;
WString GetInternalName() const;
WString GetLegalCopyright() const;
WString GetOriginalFilename() const;
WString GetProductName() const;
WString GetProductVersion() const;
VFileVersion();
~VFileVersion();
};
// Code added here will be included at the top of the .CPP file
// Include definitions for resources.
#include "WRes.h"
//
// CompanyName Property
//
WString VFileVersion::GetCompanyName() const
{
return companyName;
}
.
. Add the rest of your Get... property methods
.
//
// Constructor
//
VFileVersion::VFileVersion()
: versionData( 0 ), translationTable( 0 )
{
try {
// We'll use application's filename to identify the module
// to get the version resource from.
//
char filename[255];
strcpy(filename, WAppObject.GetExecutableModule().GetName().GetText());
// We need the size of the version information to allocate
memory
// for the version resource data
//
DWORD versionHandle; // this var is ignored by GetFileVersionInfo
DWORD versionSize = ::GetFileVersionInfoSize(filename,
&versionHandle);
WASSERT (versionSize);
if (!versionSize)
throw;
versionData = (void *) new char[(UINT)versionSize];
if (!::GetFileVersionInfo( filename, versionHandle,
versionSize, versionData) )
throw;
// Initialize the class members with the values retreived
// from the version data.
// The Win32 API contains the following predefined version
// information strings:
// CompanyName FileDescription FileVersion InternalName
// LegalCopyright OriginalFilename ProductName ProductVersion
//
char subBlockName[ 255 ];
UINT querySize;
// Get a pointer to the language and character-set identifiers.
if (!::VerQueryValue(versionData, "\\VarFileInfo\\Translation",
(void **)&translationTable, &querySize))
throw;
// Swap the words so wsprintf will print the lang-charset
// in the correct format.
*(DWORD *)translationTable = MAKELONG(
HIWORD( *(DWORD*)translationTable ),
LOWORD( *(DWORD*)translationTable ));
// Pointer to a buffer that receives a pointer
// to the version-information value.
void *queryData;
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"CompanyName");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
companyName.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"FileDescription");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
fileDescription.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"FileVersion");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
fileVersion.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"InternalName");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
internalName.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"LegalCopyright");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
legalCopyright.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"OriginalFilename");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
originalFilename.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"ProductName");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
productName.SetText( (char *)queryData );
wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s",
*(DWORD *)translationTable, (LPSTR)"ProductVersion");
if (::VerQueryValue(versionData, subBlockName, &queryData, &querySize))
productVersion.SetText( (char *)queryData );
}
catch (...) {
if (versionData) {
delete[] versionData;
versionData = 0;
}
}
}
VFileVersion::~VFileVersion()
{
if (versionData) {
delete[] versionData;
versionData = 0;
}
}
typedef unsigned long DWORD;
typedef unsigned short WORD;
#define LOWORD(l) ((WORD)(l))
#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
And in the form's Create event handler, you would add code such as the following:
// The tab control doesn't support access keys for the individual WAcceleratorTable accelTable = GetAcceleratorTable();
accelTable.Add( WKAltPressed, WKeyT, 1 ); // &Testing SetAcceleratorTable( accelTable );
// tabs, so we'll setup an accelerator table to simulate the behavior.
// The tab's ordinal page number is stored in the command id param
// and will be used to select the page in Command event handler.
// We use the ordinal number instead of the page's array index
// because we can't store a '0' in the accel table.
accelTable.Add( WKAltPressed, WKeyW, 2 ); // &Wow
accelTable.Add( WKAltPressed, WKeyZ, 3 ); // &Zowie
Finally, in the form's Command event handler, you would add the folliwing code:
// Activate the tab page associated with the accelerator. if( HIWORD(event->wParam) == 1 ) { // 1 == accelerator
// The event->wParam member has ordinal page# stored in it.
WInt currentPage = tabctrl_1->GetSelected();
WInt selectedPage = LOWORD( event->wParam ) - 1;
if( currentPage != selectedPage )
tabctrl_1->SetSelected( selectedPage );
}