(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
Unit AHMTInformationLabel;

Interface

Uses
  Windows, Messages, SysUtils, Classes, StdCtrls,AHMStdClass;

Type
  TROInfo  = string;
  TAHMInformation =
  (iOrganisationName,iOwnerName,iProgramFilesDir,iSystemRoot,iProcessorType,iPlatformName,
   iPlatformVersion,iBuildNumber,iTotalPhysicalMemory,iCurrentDiskSize,iScreenHeight,iScreenWidth,
   iUserName,iComputerName,iMemoryLoad,iAvailablePhysicalMemory,iUsedPhysicalMemory,iNumLock,
   iCapsLock,iScrollLock,iCurrentDiskFree,iCurrentTime,iCurrentDate,iSwapFileSettings,iSwapFileSize,
   iSwapFileUsage);
  TAHMInformationLabel = class(TLabel)
  private
    finfotype : TAHMInformation;
    FAboutStr : TAHMAboutSControlStr;
    fcaplab : string;
    fcapval : TROInfo;
    procedure SetCap(value : TROInfo);
    procedure SetCapVal(value : TROInfo);
    procedure SetCaplab(value : String);
    procedure SetInfoType(value : TAHMInformation);
  protected
  public
    procedure Loaded; override;
    procedure UpdateInfo;
  published
    property Caption;
    property About : TAHMAboutSControlStr read FAboutStr write FAboutStr;
    property InfoType : TAHMInformation read finfotype write SetInfoType;
    property CaptionValue : TROInfo read fcapval write SetCapval;
    property CaptionLabel : String read fcaplab write SetCapLab;
  end;

implementation
uses Registry,Forms;

Function AHMGetUsrName:String;
Var
  lpBuffer: lpstr;
  success: Boolean;
  nSize: DWord;
begin
  nSize := 255; Result := '';
  GetMem(lpBuffer, 255);
  try
    success := GetUserName(lpBuffer, nSize);
    if (not success) then result:='';
    Result := StrPas(lpBuffer);
  finally
    FreeMem(lpBuffer);
  end;
end;

Function AHMGetPCName:String;
Var
  lpBuffer: lpstr;
  success: Boolean;
  nSize: DWord;
begin
  nSize := 255; Result := '';
  GetMem(lpBuffer, 255);
  try
    success := GetComputerName(lpBuffer, nSize);
    if (not success) then result:='';
    result := StrPas(lpBuffer);
  finally
    FreeMem(lpBuffer);
  end;
end;


Function AHMGetInformationNo(No : Integer):String;
var
  RegIni : TRegIniFile;
  SI : TSystemInfo;
  OS : TOSVersionInfo;
  MemStat : TMemoryStatus;
  PathArray : array [0..255] of char;
begin
  GetSystemInfo(SI);
  OS.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
  GetVersionEx(OS);
  MemStat.dwLength := sizeof(TMemoryStatus);
  GlobalMemoryStatus(MemStat);
  RegIni := TRegIniFile.Create('\SOFTWARE\Microsoft\Windows');
  RegIni.RootKey := HKEY_LOCAL_MACHINE;
  RegIni.OpenKey('\SOFTWARE\Microsoft\Windows',False);
  result:='';
  case No of
    1 : result := RegIni.ReadString('CurrentVersion','RegisteredOrganization','');
    2 : result := RegIni.ReadString('CurrentVersion','RegisteredOwner','');
    3 : result := RegIni.ReadString('CurrentVersion','ProgramFilesDir','');
    4 : result := RegIni.ReadString('CurrentVersion','SystemRoot','');
    5 : begin
          case Si.dwProcessorType of
            386 : result := 'Intel 386';
            486 : result := 'Intel 486';
            586 : result := 'Intel Pentium';
            686 : result := 'Intel Pentium II';
            786 : result := 'Intel Pentium III';
          end;
        end;
    6 : begin
          case OS.dwPlatformId of
            VER_PLATFORM_WIN32s        : result := 'Windows 3.1';
            VER_PLATFORM_WIN32_WINDOWS : result := 'Windows 95';
            VER_PLATFORM_WIN32_NT      : result := 'Windows NT';
          end;
        end;
    7 : result := format('%d.%d',[OS.dwMajorVersion,OS.dwMinorVersion]);
    8 : result := format('%d',[LOWORD(OS.dwBuildNumber)]);
    9 : result := format('%d KB',[Trunc(MemStat.dwTotalPhys/1024)]);
   10 : if DiskSize(0) <> -1 then
        result := format('%d MB', [Trunc(DiskSize(0)/1024/1024)]) else result := '';
   11 : result := Inttostr(Screen.height);
   12 : result := Inttostr(Screen.width);
   13 : result := AHMGetUsrName;
   14 : result := AHMGetPCName;
   15 : result := format('%d Percent',[Trunc(MemStat.dwMemoryLoad)]);
   16 : result := format('%d KB',[Trunc(MemStat.dwAvailPhys/1024)]);
   17 : result := format('%d KB',[Trunc(MemStat.dwTotalVirtual/1024-MemStat.dwAvailVirtual/1024)]);
   18 : if (GetKeyState(VK_NUMLOCK) and $01) <> 0 then result:='On' else result:='Off';
   19 : if (GetKeyState(VK_CAPITAL) and $01) <> 0 then result:='On' else result:='Off';
   20 : if (GetKeyState(VK_SCROLL) and $01) <> 0 then result:='On' else result:='Off';
   21 : if DiskFree(0) <> -1 then
        result := format('%d MB', [Trunc(DiskFree(0)/1024/1024)]) else result := '';
   22 : result := TimeToStr(Time);
   23 : result := DateToStr(Date);
   24 : result := Format('%d KB',[Trunc(MemStat.dwTotalPageFile/1024)]);
   25 : result := Format('%d KB',[Trunc((MemStat.dwTotalPageFile-MemStat.dwAvailPageFile)/1024)]);
   26 : result := Format('%d %%',[100-trunc(MemStat.dwAvailPageFile/MemStat.dwTotalPageFile*100)]);
   27 : begin
          FillChar(PathArray, SizeOf(PathArray), #0);
          GetWindowsDirectory(PathArray,255);
          result:=Format('%s',[PathArray]);
        end;
  end;
  RegIni.Free;
end;


procedure TAHMInformationLabel.SetCap(value : TROInfo);
begin
  Caption:=concat(fcaplab,fcapval);
end;

procedure TAHMInformationLabel.Loaded;
begin
  inherited Loaded;
  SetCap('');
end;

procedure TAHMInformationLabel.UpdateInfo;
begin
  fcapval:=AHMGetInformationNo(Integer(finfotype)+1);
  Caption:=concat(fcaplab,fcapval);
  Invalidate;
end;

procedure TAHMInformationLabel.SetCapVal(value : TROInfo);
begin
  fcapval:=AHMGetInformationNo(Integer(finfotype)+1);
  SetCap('');
end;

procedure TAHMInformationLabel.SetCapLab(value : String);
begin
  fCapLab:=value;
  SetCap('');
end;

procedure TAHMInformationLabel.SetInfoType(value : TAHMInformation);
begin
  finfotype := value;
  SetCapVal('');
end;

end.
