home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / SRDVID / DATA.Z / aboutbox.cpp next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  4.2 KB  |  147 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // about.cpp - CAboutBox dialog
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. //  (C) Copyright Black Diamond Consulting, Inc 1996. All rights reserved.
  8. //
  9. //    You have a royalty-free right to use, modify, reproduce and 
  10. //    distribute the Sample Files (and/or any modified version) in 
  11. //    any way you find useful, provided that you agree that Black 
  12. //    Diamond Consulting has no warranty obligations or liability
  13. //    for any Sample Application Files which are modified. 
  14. //
  15. //    Revision History:
  16. //   6/22/95 - Initial version - DAS
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. // This general purpose About Box assumes the following:
  20. //
  21. // 1) There is a resource templage called IDD_ABOUTBOX
  22. // 2) There is a static control called IDC_VERSIONINFO that
  23. //    has room for 4 lines of text
  24. //
  25. // CAboutBox reads the Version resource from the application and
  26. // displays it in the static text field. The only thing you need
  27. // to provide in your dialog resource is an OK button and an ICON.
  28. //
  29. /////////////////////////////////////////////////////////////////////////////
  30. #include "stdafx.h"
  31. #include <windowsx.h>
  32.  
  33. #ifndef __ABOUTBOX_H__
  34.     #include "AboutBox.h"
  35. #endif
  36.  
  37. #ifdef _DEBUG
  38.     #undef THIS_FILE
  39.     static char BASED_CODE THIS_FILE[] = __FILE__;
  40. #endif
  41.  
  42. CAboutBox::CAboutBox() : CDialog(CAboutBox::IDD)
  43. {
  44.     //{{AFX_DATA_INIT(CAboutBox)
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48. BOOL CAboutBox::OnInitDialog()
  49. {
  50.     CStatic *pStatic;
  51.     CHAR szFilename[MAX_PATH];
  52.     CHAR buffer[128];
  53.     DWORD versionInfoSize;
  54.     LPVOID versionInfo;
  55.     DWORD* translation;
  56.     UINT translationLength;
  57.     DWORD dwTemp1, dwTemp2;
  58.     CHAR verStringHeader[80];
  59.     CString AboutText;
  60.     CHAR* string;
  61.     UINT stringLength;
  62.  
  63.     // Get our EXE name
  64.     GetModuleFileName( AfxGetInstanceHandle(), szFilename, sizeof( szFilename ) - 1 );
  65.     
  66.     // Init about text
  67.     AboutText.Empty();
  68.  
  69.     // Get the version info block
  70.     versionInfoSize = GetFileVersionInfoSize( szFilename , 0 );
  71.     if( versionInfoSize != 0 )
  72.     {
  73.         versionInfo = GlobalAllocPtr( GMEM_MOVEABLE, versionInfoSize );
  74.         if( versionInfo != NULL )
  75.         {
  76.             GetFileVersionInfo( szFilename, 0, versionInfoSize, versionInfo );
  77.  
  78.             // Get the translation value
  79.             VerQueryValue( versionInfo, "\\VarFileInfo\\Translation",
  80.                            (LPVOID*)&translation, &translationLength ); 
  81.             dwTemp1 = *translation;
  82.             dwTemp2 = MAKELONG( HIWORD(dwTemp1), LOWORD(dwTemp1) ); 
  83.             sprintf( verStringHeader, "\\StringFileInfo\\%08LX\\", dwTemp2 );
  84.     
  85.             // Get the Product Name
  86.             strcpy( buffer, verStringHeader );
  87.             strcat( buffer, "ProductName" );
  88.             if( VerQueryValue( versionInfo, buffer, (LPVOID*)&string, &stringLength ) )
  89.             {
  90.                 AboutText += string;
  91.                 AboutText += "\n";
  92.             } 
  93.  
  94.             // Get the file version
  95.             strcpy( buffer, verStringHeader );
  96.             strcat( buffer, "FileVersion" );
  97.             if( VerQueryValue( versionInfo, buffer, (LPVOID*)&string, &stringLength ) )
  98.             {
  99.                 AboutText += "Version ";
  100.                 AboutText += string;
  101.                 AboutText += "\n";
  102.             }
  103.     
  104.             // Get the Legal Copyright
  105.             strcpy( buffer, verStringHeader );
  106.             strcat( buffer, "LegalCopyright" );
  107.             if( VerQueryValue( versionInfo, buffer, (LPVOID*)&string, &stringLength ) )
  108.             {
  109.                 AboutText += string;
  110.                 AboutText += "\n";
  111.             }
  112.  
  113.             // Get the Comments
  114.             strcpy( buffer, verStringHeader );
  115.             strcat( buffer, "Comments" );
  116.             if( VerQueryValue( versionInfo, buffer, (LPVOID*)&string, &stringLength ) )
  117.             {
  118.                 AboutText += string;
  119.             }
  120.         }
  121.         else AboutText = "Memory allocation failed";
  122.     }
  123.     else AboutText = "No version information found";
  124.  
  125.     if( (pStatic = (CStatic *)GetDlgItem( IDC_VERSIONINFO )) != NULL )
  126.     {
  127.         pStatic->SetWindowText( AboutText );
  128.     }
  129.     CDialog::OnInitDialog();
  130.  
  131.     return TRUE;  // return TRUE unless you set the focus to a control
  132. }
  133.  
  134. void CAboutBox::DoDataExchange(CDataExchange* pDX)
  135. {
  136.     CDialog::DoDataExchange(pDX);
  137.     //{{AFX_DATA_MAP(CAboutBox)
  138.     //}}AFX_DATA_MAP
  139. }
  140.  
  141. BEGIN_MESSAGE_MAP(CAboutBox, CDialog)
  142.     //{{AFX_MSG_MAP(CAboutBox)
  143.         // No message handlers
  144.     //}}AFX_MSG_MAP
  145. END_MESSAGE_MAP()
  146.  
  147.