понедельник, 3 января 2011 г.

Код курсача

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, registry, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Button1: TButton;
    Show1: TMenuItem;
    All1: TMenuItem;
    N1: TMenuItem;
    PCname1: TMenuItem;
    Username1: TMenuItem;
    CPUinfo1: TMenuItem;
    RAMinfo1: TMenuItem;
    VSinfo1: TMenuItem;
    Systemdirectory1: TMenuItem;
    OSname1: TMenuItem;
    Options1: TMenuItem;
    Dynamicrefresh1: TMenuItem;
    Button2: TButton;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Image1: TImage;
    Information1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Dynamicrefresh1Click(Sender: TObject);
    procedure ClearLabels;
    procedure All1Click(Sender: TObject);
    procedure PCname1Click(Sender: TObject);
    procedure Username1Click(Sender: TObject);
    procedure CPUinfo1Click(Sender: TObject);
    procedure VSinfo1Click(Sender: TObject);
    procedure Systemdirectory1Click(Sender: TObject);
    procedure OSname1Click(Sender: TObject);
    procedure RAMinfo1Click(Sender: TObject);
    procedure Information1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  //===============================MyClasses====================================
  ComputerName = class(TObject)
    size: cardinal;
    PRes: pchar;
    BRes: boolean;
    Constructor Create();
    Destructor Destroy();
    Function GetName: string;
  end;

  UserName = class(Tobject)
    size: cardinal;
    PRes: pchar;
    BRes: boolean;
    Constructor Create();
    Destructor Destroy();
    Function GetName: string;
  end;

  ProcessorInfo = class(TObject)
    SI: TSystemInfo;
    Constructor Create();
    Destructor Destroy();
    Function GetType: string;
    Function GetNumber: string;
    Function GetAPMask: string;
  end;

  VideosystemInfo = class(TObject)
    Resolution: string;
    dc: hdc;
    colors: string;
    Constructor Create();
    Destructor Destroy();
    Function GetResolution: string;
    Function GetColors: string;
    Function GetPlanes: string;
    Function GetBitsPerPixel: string;
  end;

 MemoryInfo = class(TObject)
    TMS: TMemoryStatus;
    Constructor Create();
    Destructor Destroy();
    Function GetLoadPercent: string;
    Function GetTotalPhisical: string;
    Function GetAvailablePhisical: string;
    Function GetTotalPageFile: string;
    Function GetAvailablePageFile: string;
 end;

 WindowsFolder = class(TObject)
   PRes: PChar;
   Res: Word;
   Constructor Create();
   Destructor Destroy();
   Function GetWindowsFolder: string;
 end;

 OSName = class(TObject)
  OS,c:string;
  TOSVI: TOSVersionInfo;
  BRes: boolean;
  Constructor Create();
  Destructor Destroy();
  Function GetOSName: string;
 end;

 //====================EndOfMyClasses===========================================

var
  Form1: TForm1;
  OComputerName: ComputerName;
  OUserName: UserName;
  OProcessorInfo: ProcessorInfo;
  OVideosystemInfo: VideosystemInfo;
  OMemoryInfo: MemoryInfo;
  OWindowsFolder: WindowsFolder;
  OOSName: OSName;

implementation

uses Unit2;
//=========================MyClassMethods=======================================

//=========================ComputerName=========================================
Constructor ComputerName.Create();
begin
  Inherited Create;
end;

Destructor ComputerName.Destroy();
begin
  Inherited;
end;

Function ComputerName.GetName;
begin
  size:=max_computername_length+1;
  PRes:=StrAlloc(Size);
  BRes:=getComputerName(PRes,size);
  if bres then GetName:=StrPas(Pres)
  else GetName:='Unknown';
end;


//=========================UserName=============================================
Constructor UserName.Create();
begin
  Inherited Create;
end;

Destructor UserName.Destroy();
begin
  Inherited;
end;

Function UserName.GetName;
begin
  size:=max_computername_length+1;
  PRes:=StrAlloc(Size);
  BRes:=getUserName(PRes,size);
  if bres then GetName:=StrPas(Pres)
  else GetName:='Unknown';
end;


//==========================ProcessorInfo=======================================
Constructor ProcessorInfo.Create();
begin
  Inherited Create;
end;

Destructor ProcessorInfo.Destroy();
begin
  Inherited;
end;

Function ProcessorInfo.GetType: string;
begin
  GetSystemInfo(SI);
  GetType:='x'+inttostr(SI.dwProcessorType);
end;

Function ProcessorInfo.GetNumber: string;
begin
  GetSystemInfo(SI);
  GetNumber:=inttostr(SI.dwNumberOfProcessors);
end;

Function ProcessorInfo.GetAPMask: string;
begin
  GetSystemInfo(SI);
  GetAPMask:=inttostr(SI.dwActiveProcessorMask);
end;


//=============================VideosystemInfo==================================
Constructor VideosystemInfo.Create();
begin
  inherited create;
  DC:=CreateDC('Display',nil,nil,nil);
end;

Destructor VideosystemInfo.Destroy();
begin
  DeleteDC(DC);
  inherited;
end;

Function VideosystemInfo.GetResolution: string;
var
w,h:integer;
begin
  w:=Screen.Width;
  h:=Screen.Height;
  GetResolution:=inttostr(w)+'x'+inttostr(h);
end;

Function VideosystemInfo.GetColors: string;
begin
  Case GetDeviceCaps(dc, bitspixel) of
    8 : Colors:='256';
    15 : Colors:='32768';
    16 : Colors:='65536';
    24 : Colors:='16 mln';
    32 : Colors:='24 mln';
  End;
  GetColors:=Colors+' colors';
end;

Function VideosystemInfo.GetPlanes: string;
begin
  GetPlanes:=inttostr(GetDeviceCaps(DC,planes));
end;

Function VideosystemInfo.GetBitsPerPixel: string;
begin
  GetBitsPerPixel:=inttostr(GetDeviceCaps(DC,bitspixel));
end;


//==============================MemoryInfo======================================
Constructor MemoryInfo.Create;
begin
  inherited Create;
end;

Destructor MemoryInfo.Destroy;
begin
  inherited;
end;

Function MemoryInfo.GetLoadPercent;
begin
  GetLoadPercent:=inttostr(tms.dwMemoryLoad)+'%';
end;

Function MemoryInfo.GetTotalPhisical;
begin
  GetTotalPhisical:=format('%0.0f Mb',[tms.dwtotalphys div 1024 / 1024]);
end;

Function MemoryInfo.GetAvailablePhisical;
begin
  GetAvailablePhisical:=format('%0.3f Mb',[tms.dwavailphys div 1024 / 1024]);
end;

Function MemoryInfo.GetTotalPageFile;
begin
  GetTotalPageFile:=format('%0.0f Mb',[tms.dwtotalpagefile div 1024 / 1024]);
end;

Function MemoryInfo.GetAvailablePageFile;
begin
  GetAvailablePageFile:=format('%0.0f Mb',[tms.dwavailpagefile div 1024 / 1024]);
end;
//=============================WindowsFolder====================================
Constructor WindowsFolder.Create();
begin
  inherited Create;
  PRes:= StrAlloc(255);
  Res:= GetWindowsDirectory(PRes,225);
end;

Destructor WindowsFolder.Destroy;
begin
  inherited;
end;

Function WindowsFolder.GetWindowsFolder;
begin
   if Res>0 then GetWindowsFolder:=StrPas(PRes)
   else GetWindowsFolder:='Unknown';
end;


//===========================OSName=============================================
Constructor OSName.Create();
begin
  inherited Create;
  TOSVI.dwOSVersionInfoSize:=SizeOf(TOSVersionInfo);
  BRes:= GetVersionEx(TOSVI);
end;

Destructor OSName.Destroy;
begin
  inherited;
end;

Function OSName.GetOSName;
begin
  if BRes then begin
  with TOSVI do
    case DWPlatformID of
      ver_platform_win32_windows : if dwMinorVersion=0 then OS:='Windows 95'
                                   else OS:='Windows 98';
      ver_platform_win32_NT : OS:='Windows NT';
      ver_platform_win32S : OS:='Windows 3.11 with Win32S';
    end;
    GetOSName:=OS; end
  else GetOSName:='Unknown';
end;

//=========================EndOfMyClassMethods==================================
{$R *.dfm}
procedure TForm1.ClearLabels;
begin
  Label1.Caption:='';
  Label2.Caption:='';
  Label3.Caption:='';
  Label4.Caption:='';
  Label5.Caption:='';
  Label6.Caption:='';
  Label7.Caption:='';
  Label8.Caption:='';
  Label9.Caption:='';
  Label10.Caption:='';
  Label11.Caption:='';
  Label12.Caption:='';
  Label13.Caption:='';
  Label14.Caption:='';
  Label15.Caption:='';
  Label16.Caption:='';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form1.ClearLabels;
  Label1.Caption:='Computer name: '+OComputerName.GetName;
  Label2.Caption:='User name: '+OUserName.GetName;
  Label3.Caption:='Processor type: '+OProcessorInfo.GetType;
  Label4.Caption:='Number of processors: '+OProcessorInfo.GetNumber;
  Label5.Caption:='Processor AP mask: '+OProcessorInfo.GetAPMask;
  Label6.Caption:='Screen resolution: '+OVideosystemInfo.GetResolution;
  Label7.Caption:='Number of colors: '+OVideosystemInfo.GetColors;
  Label8.Caption:='Number of planes: '+OVideosystemInfo.GetPlanes;
  Label9.Caption:='Bits per pixel: '+OVideosystemInfo.GetBitsPerPixel;
  Label10.Caption:='System folder: '+OWindowsFolder.GetWindowsFolder;
  Label11.Caption:='Operating system: '+OOSName.GetOSName;
  Label12.Caption:='Total physical memory: '+OMemoryInfo.GetTotalPhisical;
  Label13.Caption:='Total page file: '+OMemoryInfo.GetTotalPageFile;
  Label14.Caption:='Memory load: '+OMemoryInfo.GetLoadPercent;
  Label15.Caption:='Available of physical memory: '+OMemoryInfo.GetAvailablePhisical;
  Label16.Caption:='Available of page file: '+OMemoryInfo.GetAvailablePageFile;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Dynamicrefresh1Click(Sender: TObject);
begin
  if not (dynamicrefresh1.Checked) then dynamicrefresh1.Checked:=true
  else dynamicrefresh1.Checked:=false;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if OComputerName<>NIL then OComputerName.Destroy;
  if OUserName<>NIL then OUserName.Destroy;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  dynamicrefresh1.Checked:=false;
  OComputerName:= ComputerName.Create;
  OUserName:= UserName.Create;
  OProcessorInfo:= ProcessorInfo.Create;
  OVideosystemInfo:= VideosystemInfo.Create;
  OMemoryInfo:= MemoryInfo.Create;
  OWindowsFolder:= WindowsFolder.Create;
  OOSName:= OSName.Create;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if dynamicrefresh1.Checked then begin
  Label14.Caption:='Memory load: '+OMemoryInfo.GetLoadPercent;
  Label15.Caption:='Available of physical memory: '+OMemoryInfo.GetAvailablePhisical;
  Label16.Caption:='Available of page file: '+OMemoryInfo.GetAvailablePageFile;
end;
end;
procedure TForm1.All1Click(Sender: TObject);
begin
  Form1.ClearLabels;
  Label1.Caption:='Computer name: '+OComputerName.GetName;
  Label2.Caption:='User name: '+OUserName.GetName;
  Label3.Caption:='Processor type: '+OProcessorInfo.GetType;
  Label4.Caption:='Number of processors: '+OProcessorInfo.GetNumber;
  Label5.Caption:='Processor AP mask: '+OProcessorInfo.GetAPMask;
  Label6.Caption:='Screen resolution: '+OVideosystemInfo.GetResolution;
  Label7.Caption:='Number of colors: '+OVideosystemInfo.GetColors;
  Label8.Caption:='Number of planes: '+OVideosystemInfo.GetPlanes;
  Label9.Caption:='Bits per pixel: '+OVideosystemInfo.GetBitsPerPixel;
  Label10.Caption:='System folder: '+OWindowsFolder.GetWindowsFolder;
  Label11.Caption:='Operating system: '+OOSName.GetOSName;
  Label12.Caption:='Total physical memory: '+OMemoryInfo.GetTotalPhisical;
  Label13.Caption:='Total page file: '+OMemoryInfo.GetTotalPageFile;
  Label14.Caption:='Memory load: '+OMemoryInfo.GetLoadPercent;
  Label15.Caption:='Available of physical memory: '+OMemoryInfo.GetAvailablePhisical;
  Label16.Caption:='Available of page file: '+OMemoryInfo.GetAvailablePageFile;
end;

procedure TForm1.PCname1Click(Sender: TObject);
begin
  Label1.Caption:='Computer name: '+OComputerName.GetName;
end;

procedure TForm1.Username1Click(Sender: TObject);
begin
  Label2.Caption:='User name: '+OUserName.GetName;
end;

procedure TForm1.CPUinfo1Click(Sender: TObject);
begin
  Label3.Caption:='Processor type: '+OProcessorInfo.GetType;
  Label4.Caption:='Number of processors: '+OProcessorInfo.GetNumber;
  Label5.Caption:='Processor AP mask: '+OProcessorInfo.GetAPMask;
end;

procedure TForm1.VSinfo1Click(Sender: TObject);
begin
  Label6.Caption:='Screen resolution: '+OVideosystemInfo.GetResolution;
  Label7.Caption:='Number of colors: '+OVideosystemInfo.GetColors;
  Label8.Caption:='Number of planes: '+OVideosystemInfo.GetPlanes;
  Label9.Caption:='Bits per pixel: '+OVideosystemInfo.GetBitsPerPixel;
end;

procedure TForm1.Systemdirectory1Click(Sender: TObject);
begin
  Label10.Caption:='System folder: '+OWindowsFolder.GetWindowsFolder;
end;

procedure TForm1.OSname1Click(Sender: TObject);
begin
  Label11.Caption:='Operating system: '+OOSName.GetOSName;
end;

procedure TForm1.RAMinfo1Click(Sender: TObject);
begin
  Label12.Caption:='Total physical memory: '+OMemoryInfo.GetTotalPhisical;
  Label13.Caption:='Total page file: '+OMemoryInfo.GetTotalPageFile;
  Label14.Caption:='Memory load: '+OMemoryInfo.GetLoadPercent;
  Label15.Caption:='Available of physical memory: '+OMemoryInfo.GetAvailablePhisical;
  Label16.Caption:='Available of page file: '+OMemoryInfo.GetAvailablePageFile;
end;

procedure TForm1.Information1Click(Sender: TObject);
begin
  Form2.ShowModal;
end;
end.


/////////////////////////////////////////////////////////////////////////////////////
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, jpeg, ExtCtrls;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Image1: TImage;
    Image2: TImage;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Form2.Close;
end;

end.