home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SHELL.PAK / ABOUTDLG.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  187 lines

  1. //----------------------------------------------------------------------------
  2. //  Project Shell
  3. //  Borland International
  4. //  Copyright ⌐ 1995, 1996 Borland International. All Rights Reserved.
  5. //
  6. //  SUBSYSTEM:    shell.exe Application
  7. //  FILE:         aboutdlg.cpp
  8. //  AUTHOR:       The OWL Team
  9. //
  10. //  OVERVIEW
  11. //  ~~~~~~~~
  12. //  Source file for implementation of TShellAboutDlg (TDialog).
  13. //
  14. //----------------------------------------------------------------------------
  15.  
  16. #include <owl/pch.h>
  17. #include <owl/static.h>
  18. #include <stdio.h>
  19. #if defined(BI_PLAT_WIN16)
  20. # include <ver.h>
  21. #endif
  22.  
  23. #include "shellapp.h"
  24. #include "aboutdlg.h"
  25.  
  26.  
  27. TProjectRCVersion::TProjectRCVersion(TModule* module)
  28. {
  29.   char    appFName[255];
  30.   char    subBlockName[255];
  31.   uint32  fvHandle;
  32.   uint    vSize;
  33.  
  34.   FVData = 0;
  35.  
  36.   module->GetModuleFileName(appFName, sizeof appFName);
  37.   OemToAnsi(appFName, appFName);
  38.   uint32 dwSize = ::GetFileVersionInfoSize(appFName, &fvHandle);
  39.   if (dwSize) {
  40.     FVData  = (void far *)new char[(uint)dwSize];
  41.     if (::GetFileVersionInfo(appFName, fvHandle, dwSize, FVData)) {
  42.       // Copy string to buffer so if the -dc compiler switch(Put constant strings in code segments)
  43.       // is on VerQueryValue will work under Win16.  This works around a problem in Microsoft's ver.dll
  44.       // which writes to the string pointed to by subBlockName.
  45.       //
  46.       strcpy(subBlockName, "\\VarFileInfo\\Translation"); 
  47.       if (!::VerQueryValue(FVData, subBlockName,(void far* far*)&TransBlock, &vSize)) {
  48.         delete[] FVData;
  49.         FVData = 0;
  50.       }
  51.       else
  52.         // Swap the words so sprintf will print the lang-charset in the correct format.
  53.         //
  54.         *(uint32 *)TransBlock = MAKELONG(HIWORD(*(uint32 *)TransBlock), LOWORD(*(uint32 *)TransBlock));
  55.     }
  56.   }
  57. }
  58.  
  59.  
  60. TProjectRCVersion::~TProjectRCVersion()
  61. {
  62.   if (FVData)
  63.     delete[] FVData;
  64. }
  65.  
  66.  
  67. bool TProjectRCVersion::GetProductName(LPSTR& prodName)
  68. {
  69.   uint    vSize;
  70.   char    subBlockName[255];
  71.  
  72.   if (FVData) {
  73.     sprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(uint32 *)TransBlock,(LPSTR)"ProductName");
  74.     return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*)&prodName, &vSize) : false;
  75.   } else
  76.     return false;
  77. }
  78.  
  79.  
  80. bool TProjectRCVersion::GetProductVersion(LPSTR& prodVersion)
  81. {
  82.   uint    vSize;
  83.   char    subBlockName[255];
  84.  
  85.   if (FVData) {
  86.     sprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(uint32 *)TransBlock,(LPSTR)"ProductVersion");
  87.     return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*)&prodVersion, &vSize) : false;
  88.   } else
  89.     return false;
  90. }
  91.  
  92.  
  93. bool TProjectRCVersion::GetCopyright(LPSTR& copyright)
  94. {
  95.   uint    vSize;
  96.   char    subBlockName[255];
  97.  
  98.   if (FVData) {
  99.     sprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(uint32 *)TransBlock,(LPSTR)"LegalCopyright");
  100.     return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*)©right, &vSize) : false;
  101.   } else
  102.     return false;
  103. }
  104.  
  105.  
  106. bool TProjectRCVersion::GetDebug(LPSTR& debug)
  107. {
  108.   uint    vSize;
  109.   char    subBlockName[255];
  110.  
  111.   if (FVData) {
  112.     sprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(uint32 *)TransBlock,(LPSTR)"SpecialBuild");
  113.     return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*)&debug, &vSize) : false;
  114.   } else
  115.     return false;
  116. }
  117.  
  118.  
  119. //{{TShellAboutDlg Implementation}}
  120.  
  121.  
  122. //--------------------------------------------------------
  123. // TShellAboutDlg
  124. // ~~~~~~~~~~
  125. // Construction/Destruction handling.
  126. //
  127. TShellAboutDlg::TShellAboutDlg(TWindow* parent, TResId resId, TModule* module)
  128. :
  129.   TDialog(parent, resId, module)
  130. {
  131.   // INSERT>> Your constructor code here.
  132. }
  133.  
  134.  
  135. TShellAboutDlg::~TShellAboutDlg()
  136. {
  137.   Destroy();
  138.  
  139.   // INSERT>> Your destructor code here.
  140. }
  141.  
  142.  
  143. void TShellAboutDlg::SetupWindow()
  144. {
  145.   LPSTR prodName = 0, prodVersion = 0, copyright = 0, debug = 0;
  146.  
  147.   // Get the static text for the value based on VERSIONINFO.
  148.   //
  149.   TStatic* versionCtrl = new TStatic(this, IDC_VERSION, 255);
  150.   TStatic* copyrightCtrl = new TStatic(this, IDC_COPYRIGHT, 255);
  151.   TStatic* debugCtrl = new TStatic(this, IDC_DEBUG, 255);
  152.  
  153.   TDialog::SetupWindow();
  154.  
  155.   // Process the VERSIONINFO.
  156.   //
  157.   TProjectRCVersion applVersion(GetModule());
  158.  
  159.   // Get the product name and product version strings.
  160.   //
  161.   if (applVersion.GetProductName(prodName) && applVersion.GetProductVersion(prodVersion)) {
  162.     // IDC_VERSION is the product name and version number, the initial value of IDC_VERSION is
  163.     // the word Version(in whatever language) product name VERSION product version.
  164.     //
  165.     char    buffer[255];
  166.     char    versionName[128];
  167.  
  168.     buffer[0] = '\0';
  169.     versionName[0] = '\0';
  170.  
  171.     versionCtrl->GetText(versionName, sizeof versionName);
  172.     sprintf(buffer, "%s %s %s", prodName, versionName, prodVersion);
  173.  
  174.     versionCtrl->SetText(buffer);
  175.   }
  176.  
  177.   // Get the legal copyright string.
  178.   //
  179.   if (applVersion.GetCopyright(copyright))
  180.     copyrightCtrl->SetText(copyright);
  181.  
  182.   // Only get the SpecialBuild text if the VERSIONINFO resource is there.
  183.   //
  184.   if (applVersion.GetDebug(debug))
  185.     debugCtrl->SetText(debug);
  186. }
  187.