home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kompon / d56 / MSYSINFO.ZIP / Demos / 1 / Main.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-03-05  |  11.9 KB  |  387 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, MSI_GUI, ExtCtrls, ImgList, ComCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MSystemInfo: TMSystemInfo;
  12.     Panel1: TPanel;
  13.     TitlePanel: TPanel;
  14.     Image3: TImage;
  15.     Image4: TImage;
  16.     Image1: TImage;
  17.     Image2: TImage;
  18.     Panel2: TPanel;
  19.     List: TListView;
  20.     ProcList: TListView;
  21.     Panel3: TPanel;
  22.     Panel4: TPanel;
  23.     img: TImageList;
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure cmMoveForm(Sender: TObject; Button: TMouseButton;
  26.       Shift: TShiftState; X, Y: Integer);
  27.     procedure cmMinimize(Sender: TObject);
  28.     procedure cmClose(Sender: TObject);
  29.     procedure Image2Click(Sender: TObject);
  30.     procedure cmMaximize(Sender: TObject);
  31.   private
  32.     { Private declarations }
  33.   public
  34.     { Public declarations }
  35.   end;
  36.  
  37. var
  38.   Form1: TForm1;
  39.  
  40. implementation
  41.  
  42. uses MiTeC_Datetime, MiTeC_Routines, MiTeC_CtrlRtns, MiTeC_PerfLibNT,
  43.   MiTeC_EnumsNT, MiTeC_Enums9x, MSI_SMBIOS, MSI_Devices;
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. var
  49.   PLNT: TPerfLibNT;
  50.   ProcessList: TStringList;
  51.   i,c,n,p: Integer;
  52.   s: string;
  53.   k: TSlotType;
  54. begin
  55.   Form_HideCaption(Self);
  56.   with MSystemInfo do begin
  57.     Refresh;
  58.     TitlePanel.Caption:=About;
  59.     with List.Items.Add do begin
  60.       Caption:='System';
  61.       SubItems.Add(Format('%s %s',[Machine.SMBIOS.SystemManufacturer,
  62.                                        Machine.SMBIOS.SystemModel]));
  63.       ImageIndex:=0;
  64.     end;
  65.     with List.Items.Add do begin
  66.       Caption:='Up Time';
  67.       SubItems.Add(Format('%s',[formatseconds(Machine.SystemUpTime,true,false,False)]));
  68.       ImageIndex:=12;
  69.     end;
  70.     with List.Items.Add do ImageIndex:=-1;
  71.     with List.Items.Add do begin
  72.       Caption:='CPU';
  73.       SubItems.Add(Format('%d %s %s',[CPU.Count,CPU.Vendor,CPU.VendorID]));
  74.       ImageIndex:=9;
  75.     end;
  76.     with List.Items.Add do begin
  77.       Caption:='Frequency';
  78.       SubItems.Add(Format('%d Mhz',[CPU.Frequency]));
  79.       ImageIndex:=13;
  80.     end;
  81.     with List.Items.Add do begin
  82.       Caption:='Voltage';
  83.       SubItems.Add(Format('%1.1fV',[Machine.SMBIOS.CPUVoltage]));
  84.       ImageIndex:=11;
  85.     end;
  86.     with List.Items.Add do begin
  87.       Caption:='Socket';
  88.       SubItems.Add(Format('%s (%s)',[Machine.SMBIOS.CPUSocket,Machine.SMBIOS.CPUUpgrade]));
  89.       ImageIndex:=14;
  90.     end;
  91.     with List.Items.Add do ImageIndex:=-1;
  92.     with List.Items.Add do begin
  93.       Caption:='Mainboard';
  94.       SubItems.Add(Format('%s %s',[Machine.SMBIOS.MainboardManufacturer,Machine.SMBIOS.MainboardModel]));
  95.       ImageIndex:=10;
  96.     end;
  97.     c:=0;
  98.     n:=0;
  99.     p:=0;
  100.     s:='';
  101.     for i:=0 to Machine.SMBIOS.MemorySlotCount-1 do
  102.       if Machine.SMBIOS.MemoryBank[i].Size>0 then begin
  103.         Inc(c);
  104.         n:=Machine.SMBIOS.MemoryBank[i].Size;
  105.         s:=Machine.SMBIOS.GetMemoryTypeStr(Machine.SMBIOS.MemoryBank[i].Types);
  106.         p:=Machine.SMBIOS.MemoryBank[i].Speed;
  107.       end;
  108.     with List.Items.Add do begin
  109.       Caption:='Memory';
  110.       SubItems.Add(Format('%d MB (%d KB free)',[Memory.PhysicalTotal div 1024 div 1024,Memory.PhysicalFree div 1024]));
  111.       ImageIndex:=8;
  112.     end;
  113.     with List.Items.Add do begin
  114.       Caption:='Type';
  115.       SubItems.Add(Format('%d x %d %s',[c,n,s]));
  116.       ImageIndex:=8;
  117.     end;
  118.     with List.Items.Add do begin
  119.       Caption:='Speed';
  120.       SubItems.Add(Format('%d ns',[p]));
  121.       ImageIndex:=8;
  122.     end;
  123.     with List.Items.Add do begin
  124.       Caption:='Memory';
  125.       SubItems.Add(Format('%d x %d %s (%d ns) - %d MB (%d KB free)',[c,n,s,p,Memory.PhysicalTotal div 1024 div 1024,Memory.PhysicalFree div 1024]));
  126.       ImageIndex:=8;
  127.     end;
  128.     for i:=0 to Machine.SMBIOS.PortCount-1 do
  129.       with List.Items.Add do begin
  130.         Caption:=Machine.SMBIOS.Port[i].Designator;
  131.         SubItems.Add(Format('%s (%s)',[PortTypes[Machine.SMBIOS.Port[i].Typ],
  132.                                       ConnectorTypes[Machine.SMBIOS.Port[i].Connector]]));
  133.         ImageIndex:=2;
  134.       end;
  135.     for k:=Low(TSlotType) to High(TSlotType) do begin
  136.       c:=0;
  137.       for i:=0 to Machine.SMBIOS.SystemSlotCount-1 do
  138.         if Machine.SMBIOS.SystemSlot[i].Typ=k then begin
  139.           Inc(c);
  140.           s:=Format('%s',[DataBusTypes[Machine.SMBIOS.SystemSlot[i].DataBus]]);
  141.         end;
  142.       if c>0 then
  143.         with List.Items.Add do begin
  144.           Caption:=Format('%d x %s',[c,SlotTypes[k]]);
  145.           SubItems.Add(Format('%s',[s]));
  146.           ImageIndex:=3;
  147.         end;
  148.     end;
  149.     with List.Items.Add do ImageIndex:=-1;
  150.     with List.Items.Add do begin
  151.       Caption:=Format('%s %s',[OSVersion,OS.CSD]);
  152.       SubItems.Add(Format('%d.%d.%d',[OS.MajorVersion,OS.MinorVersion,OS.BuildNumber]));
  153.       ImageIndex:=15;
  154.     end;
  155.     with List.Items.Add do begin
  156.       Caption:='Logged User';
  157.       SubItems.Add(Machine.User);
  158.       ImageIndex:=16;
  159.     end;
  160.     with List.Items.Add do ImageIndex:=-1;
  161.     with List.Items.Add do begin
  162.       Caption:='Display Adapter';
  163.       SubItems.Add(Display.Adapter);
  164.       ImageIndex:=1;
  165.     end;
  166.     with List.Items.Add do begin
  167.       Caption:='Resolution';
  168.       SubItems.Add(Format('Resolution: %d x %d - %d bit',[Display.HorzRes,
  169.                                                      Display.VertRes,
  170.                                                      Display.ColorDepth]));
  171.       ImageIndex:=12;
  172.     end;
  173.     with List.Items.Add do ImageIndex:=-1;
  174.     if Media.Devices.Count>0 then begin
  175.       with List.Items.Add do begin
  176.         Caption:='Sound Adapter';
  177.         if Media.SoundCardIndex>-1 then
  178.           SubItems.Add(Media.Devices[Media.SoundCardIndex])
  179.         else
  180.           SubItems.Add(Media.Devices[0]);
  181.         ImageIndex:=4;
  182.       end;
  183.       if Media.GamePortIndex>-1 then
  184.         with List.Items.Add do begin
  185.           Caption:='Game Adapter';
  186.           SubItems.Add(Media.Devices[Media.GamePortIndex]);
  187.           ImageIndex:=5;
  188.         end;
  189.     end;
  190.     with List.Items.Add do ImageIndex:=-1;
  191.     if Network.Adapters.Count>0 then begin
  192.       with List.Items.Add do begin
  193.         Caption:='Network Adapter';
  194.          if Network.CardAdapterIndex>-1 then
  195.            SubItems.Add(Network.Adapters[Network.CardAdapterIndex])
  196.          else
  197.            SubItems.Add(Network.Adapters[0]);
  198.          ImageIndex:=17;
  199.       end;
  200.       with List.Items.Add do begin
  201.         Caption:='Local Host Name';
  202.         SubItems.Add(Machine.Name);
  203.         ImageIndex:=12;
  204.       end;
  205.       with List.Items.Add do begin
  206.         Caption:='IP Address';
  207.         SubItems.Add(Network.IPAddresses[0]);
  208.         ImageIndex:=12;
  209.       end;
  210.       with List.Items.Add do begin
  211.         Caption:='MAC Address';
  212.         SubItems.Add(Network.MACAddresses[0]);
  213.         ImageIndex:=12;
  214.       end;
  215.     end;
  216.  
  217.  
  218.     with List.Items.Add do ImageIndex:=-1;
  219.     c:=0;
  220.     for i:=0 to Devices.DeviceCount-1 do
  221.       if Devices.Devices[i].DeviceClass=dcFloppyDisk then
  222.         with List.Items.Add do begin
  223.           Caption:=Format('Floppy Disk %d:',[c]);
  224.           if Trim(Devices.Devices[i].FriendlyName)='' then
  225.             SubItems.Add(Devices.Devices[i].Description)
  226.           else
  227.             SubItems.Add(Devices.Devices[i].FriendlyName);
  228.           ImageIndex:=18;
  229.           Inc(c);
  230.         end;
  231.     c:=0;
  232.     for i:=0 to Devices.DeviceCount-1 do
  233.       if Devices.Devices[i].DeviceClass=dcDiskDrive then
  234.         with List.Items.Add do begin
  235.           Caption:=Format('Hard Disk %d:',[c]);
  236.           if Trim(Devices.Devices[i].FriendlyName)='' then
  237.             SubItems.Add(Devices.Devices[i].Description)
  238.           else
  239.             SubItems.Add(Devices.Devices[i].FriendlyName);
  240.           Inc(c);
  241.           ImageIndex:=19;
  242.         end;
  243.  
  244.     c:=0;
  245.     for i:=0 to Devices.DeviceCount-1 do
  246.       if Devices.Devices[i].DeviceClass=dcCDROM then
  247.         with List.Items.Add do begin
  248.           Caption:=Format('CDROM %d:',[c]);
  249.           if Trim(Devices.Devices[i].FriendlyName)='' then
  250.             SubItems.Add(Devices.Devices[i].Description)
  251.           else
  252.             SubItems.Add(Devices.Devices[i].FriendlyName);
  253.           Inc(c);
  254.           ImageIndex:=20;
  255.         end;
  256.  
  257.     c:=0;
  258.     for i:=0 to Devices.DeviceCount-1 do
  259.       if Devices.Devices[i].DeviceClass=dcTapeDrive then
  260.         with List.Items.Add do begin
  261.           Caption:=Format('Tape Drive %d:',[c]);
  262.           if Trim(Devices.Devices[i].FriendlyName)='' then
  263.             SubItems.Add(Devices.Devices[i].Description)
  264.           else
  265.             SubItems.Add(Devices.Devices[i].FriendlyName);
  266.           Inc(c);
  267.           ImageIndex:=21;
  268.         end;
  269.  
  270.       with List.Items.Add do ImageIndex:=-1;
  271.       s:='<none>';
  272.       for i:=0 to Devices.DeviceCount-1 do
  273.         if Devices.Devices[i].DeviceClass=dcModem then begin
  274.           if Trim(Devices.Devices[i].FriendlyName)='' then
  275.             s:=Devices.Devices[i].Description
  276.           else
  277.             s:=Devices.Devices[i].FriendlyName;
  278.           Break;
  279.         end;
  280.  
  281.       with List.Items.Add do begin
  282.         Caption:='Modem';
  283.         SubItems.Add(s);
  284.         Inc(c);
  285.         ImageIndex:=24;
  286.       end;
  287.  
  288.       with List.Items.Add do ImageIndex:=-1;
  289.       s:='<none>';
  290.       for i:=0 to Devices.DeviceCount-1 do
  291.         if Devices.Devices[i].DeviceClass=dcMouse then begin
  292.           if Trim(Devices.Devices[i].FriendlyName)='' then
  293.             s:=Devices.Devices[i].Description
  294.           else
  295.             s:=Devices.Devices[i].FriendlyName;
  296.           Break;
  297.         end;
  298.       with List.Items.Add do begin
  299.         Caption:='Mouse';
  300.         SubItems.Add(s);
  301.         Inc(c);
  302.         ImageIndex:=23;
  303.       end;
  304.  
  305.       with List.Items.Add do ImageIndex:=-1;
  306.       s:='<none>';
  307.       for i:=0 to Devices.DeviceCount-1 do
  308.         if Devices.Devices[i].DeviceClass=dcKeyboard then begin
  309.           if Trim(Devices.Devices[i].FriendlyName)='' then
  310.             s:=Devices.Devices[i].Description
  311.           else
  312.             s:=Devices.Devices[i].FriendlyName;
  313.           Break;
  314.         end;
  315.       with List.Items.Add do begin
  316.         Caption:='Keyboard';
  317.         SubItems.Add(s);
  318.         Inc(c);
  319.         ImageIndex:=22;
  320.       end;
  321.  
  322.     with List.Items.Add do ImageIndex:=-1;
  323.     if Printers.Names.Count>0 then
  324.       with List.Items.Add do begin
  325.         Caption:=Printers.Names[Printers.DefaultIndex];
  326.         SubItems.Add(Printers.Ports[Printers.DefaultIndex]);
  327.         ImageIndex:=7;
  328.       end;
  329.  
  330.     ProcessList:=TStringList.Create;
  331.     if IsNT then begin
  332.       PLNT:=TPerfLibNT.Create;
  333.       PLNT.Refresh;
  334.       GetNTProcessList(PLNT,ProcessList);
  335.       for i:=0 to ProcessList.Count-1 do
  336.         with ProcList.Items.Add do begin
  337.           Caption:=PNTProcess(ProcessList.objects[i])^.Name;
  338.           SubItems.Add(Format('%d',[PNTProcess(ProcessList.objects[i])^.PID]));
  339.           SubItems.Add(Format('%d',[PNTProcess(ProcessList.objects[i])^.PriorityBase]));
  340.           ImageIndex:=6;
  341.         end;
  342.       PLNT.Free;
  343.     end else begin
  344.       Get95ProcessList(ProcessList);
  345.       for i:=0 to ProcessList.Count-1 do
  346.         with ProcList.Items.Add do begin
  347.           Caption:=P95Process(ProcessList.objects[i])^.Name;
  348.           SubItems.Add(Format('%d',[P95Process(ProcessList.objects[i])^.PID]));
  349.           SubItems.Add(Format('%d',[P95Process(ProcessList.objects[i])^.Priority]));
  350.           ImageIndex:=6;
  351.         end;
  352.     end;
  353.     ProcessList.Free;
  354.   end;
  355. end;
  356.  
  357. procedure TForm1.cmMoveForm(Sender: TObject; Button: TMouseButton;
  358.   Shift: TShiftState; X, Y: Integer);
  359. begin
  360.   Form_Move(Self);
  361. end;
  362.  
  363. procedure TForm1.cmMinimize(Sender: TObject);
  364. begin
  365.   Application.Minimize;
  366. end;
  367.  
  368. procedure TForm1.cmClose(Sender: TObject);
  369. begin
  370.   Close;
  371. end;
  372.  
  373. procedure TForm1.Image2Click(Sender: TObject);
  374. begin
  375.   MSystemInfo.ShowModalOverviewWithAbout;
  376. end;
  377.  
  378. procedure TForm1.cmMaximize(Sender: TObject);
  379. begin
  380.   if WindowState=wsNormal then
  381.     WindowState:=wsMaximized
  382.   else
  383.     WindowState:=wsNormal;
  384. end;
  385.  
  386. end.
  387.