home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / SYSINFO.PAK / SYSINFO.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  203 lines

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