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