home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SYSINFO.PAK / SYSINFO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.3 KB  |  212 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/framewin.h>
  8. #include <owl/dialog.h>
  9. #include <owl/static.h>
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include "sysinfo.h"
  13.  
  14.  
  15. struct SysInfo16Record {
  16.   char InstanceNumber[31];
  17.   char WindowsVersion[31];
  18.   char OperationMode[31];
  19.   char CPUType[31];
  20.   char CoProcessor[31];
  21.   char Global[31];
  22.   char VersionDos[31];
  23. };
  24.  
  25. struct SysInfo32Record {
  26.   char WindowsVersion[31];
  27.   char OemId[31];
  28.   char PageSize[31];
  29.   char MinAppAddress[31];
  30.   char MaxAppAddress[31];
  31.   char ActiveProcessorMask[31];
  32.   char NumberOfProcessors[31];
  33.   char ProcessorType[31];
  34.   char AllocationGranularity[31];
  35.   char Reserved[31];
  36. };
  37.  
  38. #if defined(BI_PLAT_WIN32)
  39.   typedef SysInfo32Record SysInfoRecord;
  40.   #define IDD_SYSINFO     MAKEINTRESOURCE(IDD_SYSINFO32)
  41. #else
  42.   typedef SysInfo16Record SysInfoRecord;
  43.   #define IDD_SYSINFO     MAKEINTRESOURCE(IDD_SYSINFO16)
  44. #endif
  45.  
  46. class TSysInfoWindow : public TDialog {
  47.   public:
  48.     TSysInfoWindow(TWindow* parent, const char far* title);
  49.     void GetSysInformation();
  50.     void InitChildren();
  51.  
  52.   private:
  53.     SysInfoRecord TransferRecord;
  54. };
  55.  
  56. TSysInfoWindow::TSysInfoWindow(TWindow* parent, const char far* title)
  57.   : TWindow(parent),
  58.     TDialog(parent, title)
  59. {
  60.   InitChildren();
  61.   GetSysInformation();
  62.   TransferBuffer = &TransferRecord;
  63. }
  64.  
  65. void
  66. TSysInfoWindow::InitChildren()
  67. {
  68.   TStatic* ts;
  69.  
  70. #if defined(BI_PLAT_WIN32)
  71.   ts = new TStatic(this, IDC_WINDOWSVERSION, sizeof TransferRecord.WindowsVersion);
  72.   ts->EnableTransfer();
  73.  
  74.   ts = new TStatic(this, IDC_OEMID, sizeof TransferRecord.OemId);
  75.   ts->EnableTransfer();
  76.  
  77.   ts = new TStatic(this, IDC_PAGESIZE, sizeof TransferRecord.PageSize);
  78.   ts->EnableTransfer();
  79.  
  80.   ts = new TStatic(this, IDC_MINAPPADDRESS, sizeof TransferRecord.MinAppAddress);
  81.   ts->EnableTransfer();
  82.  
  83.   ts = new TStatic(this, IDC_MAXAPPADDRESS, sizeof TransferRecord.MaxAppAddress);
  84.   ts->EnableTransfer();
  85.  
  86.   ts = new TStatic(this, IDC_ACTIVEPROMASK, sizeof TransferRecord.ActiveProcessorMask);
  87.   ts->EnableTransfer();
  88.  
  89.   ts = new TStatic(this, IDC_NUMPROS, sizeof TransferRecord.NumberOfProcessors);
  90.   ts->EnableTransfer();
  91.  
  92.   ts = new TStatic(this, IDC_PROTYPE, sizeof TransferRecord.ProcessorType);
  93.   ts->EnableTransfer();
  94.  
  95.   ts = new TStatic(this, IDC_ALLOCGRAN, sizeof TransferRecord.AllocationGranularity);
  96.   ts->EnableTransfer();
  97.  
  98.   ts = new TStatic(this, IDC_RESERVED, sizeof TransferRecord.Reserved);
  99.   ts->EnableTransfer();
  100. #else
  101.   ts = new TStatic(this, IDC_INSTANCENUMBER, sizeof TransferRecord.InstanceNumber);
  102.   ts->EnableTransfer();
  103.  
  104.   ts = new TStatic(this, IDC_WINDOWSVERSION, sizeof TransferRecord.WindowsVersion);
  105.   ts->EnableTransfer();
  106.  
  107.   ts = new TStatic(this, IDC_OPERATIONMODE, sizeof TransferRecord.OperationMode);
  108.   ts->EnableTransfer();
  109.  
  110.   ts = new TStatic(this, IDC_CPUTYPE, sizeof TransferRecord.CPUType);
  111.   ts->EnableTransfer();
  112.  
  113.   ts = new TStatic(this, IDC_COPROCESSOR, sizeof TransferRecord.CoProcessor);
  114.   ts->EnableTransfer();
  115.  
  116.   ts = new TStatic(this, IDC_GLOBAL, sizeof TransferRecord.Global);
  117.   ts->EnableTransfer();
  118.  
  119.   ts = new TStatic(this, IDC_VERSIONDOS, sizeof TransferRecord.VersionDos);
  120.   ts->EnableTransfer();
  121. #endif
  122. }
  123.  
  124. void
  125. TSysInfoWindow::GetSysInformation()
  126. {
  127. #if defined(BI_PLAT_WIN32)
  128.   DWORD ver = ::GetVersion();
  129.   sprintf(TransferRecord.WindowsVersion, "%d.%d", (int)LOBYTE(ver), (int)HIBYTE(ver));
  130.  
  131.   SYSTEM_INFO systemInfo;
  132.   ::GetSystemInfo(&systemInfo);
  133.  
  134.   sprintf(TransferRecord.OemId, "%lX", systemInfo.dwOemId);
  135.   sprintf(TransferRecord.PageSize, "%lX", systemInfo.dwPageSize);
  136.   sprintf(TransferRecord.MinAppAddress, "%lX", systemInfo.lpMinimumApplicationAddress);
  137.   sprintf(TransferRecord.MaxAppAddress, "%lX", systemInfo.lpMaximumApplicationAddress);
  138.   sprintf(TransferRecord.ActiveProcessorMask, "%lX", systemInfo.dwActiveProcessorMask);
  139.   sprintf(TransferRecord.NumberOfProcessors, "%lX", systemInfo.dwNumberOfProcessors);
  140.   sprintf(TransferRecord.ProcessorType, "%ld", systemInfo.dwProcessorType);
  141.   sprintf(TransferRecord.AllocationGranularity, "%lX", systemInfo.dwAllocationGranularity);
  142.  
  143. # if (__BORLANDC__ >= 0x500)
  144.     sprintf(TransferRecord.Reserved, "%lX", 0L);
  145. # else
  146.     sprintf(TransferRecord.Reserved, "%lX", systemInfo.dwReserved);
  147. # endif
  148.  
  149. #else
  150.   char  tempstr[31];
  151.   UINT  strId;
  152.   DWORD SysFlags = GetWinFlags();
  153.  
  154.   sprintf(TransferRecord.InstanceNumber, "%d", GetApplication()->GetModuleUsage());
  155.  
  156.   DWORD ver = ::GetVersion();
  157.   sprintf(TransferRecord.WindowsVersion, "%d.%d", (int)LOBYTE(ver), (int)HIBYTE(ver));
  158.  
  159.   if (SysFlags & WF_ENHANCED)
  160.     strId = IDS_ENHANCED;
  161.   else if (SysFlags & WF_STANDARD)
  162.     strId = IDS_STANDARD;
  163.   else if (!(SysFlags & WF_PMODE))
  164.     strId = IDS_REAL;
  165.   else
  166.     strId = IDS_UNKNOWN;
  167.   GetApplication()->LoadString(strId, tempstr, sizeof(tempstr));
  168.   strcpy(TransferRecord.OperationMode, tempstr);
  169.  
  170.   if (SysFlags & WF_CPU086)
  171.     strId = IDS_CPU8086;
  172.   else if (SysFlags & WF_CPU186)
  173.     strId = IDS_CPU80186;
  174.   else if (SysFlags & WF_CPU286)
  175.     strId = IDS_CPU80286;
  176.   else if (SysFlags & WF_CPU386)
  177.     strId = IDS_CPU80386;
  178.   else if (SysFlags & WF_CPU486)
  179.     strId = IDS_CPU80486;
  180.   else
  181.     strId = IDS_UNKNOWN;
  182.   GetApplication()->LoadString(strId, tempstr, sizeof(tempstr));
  183.   strcpy(TransferRecord.CPUType, tempstr);
  184.  
  185.   strId = (SysFlags & WF_80x87) ? IDS_YES : IDS_NO;
  186.   GetApplication()->LoadString(strId, tempstr, sizeof(tempstr));
  187.   strcpy(TransferRecord.CoProcessor, tempstr);
  188.  
  189.   sprintf(TransferRecord.Global, "%lu", GetFreeSpace(0)/1024);
  190.  
  191.   sprintf(TransferRecord.VersionDos, "%d.%d", _osmajor, _osminor);
  192. #endif
  193. }
  194.  
  195. class TSysInfoApp : public TApplication {
  196.   public:
  197.     TSysInfoApp() : TApplication() {}
  198.     void InitMainWindow() {
  199.       EnableCtl3d();
  200.       SetMainWindow(new TFrameWindow(0, "Windows System Information",
  201.                                      new TSysInfoWindow(0, IDD_SYSINFO),
  202.                                      true));
  203.       GetMainWindow()->ModifyStyle(WS_MAXIMIZEBOX, 0);
  204.     }
  205. };
  206.  
  207. int
  208. OwlMain(int /*argc*/, char* /*argv*/ [])
  209. {
  210.   return TSysInfoApp().Run();
  211. }
  212.