home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 December
/
Chip_2001-12_cd1.bin
/
zkuste
/
delphi
/
kolekce
/
d56
/
DM2KVCL.ZIP
/
ABOUT.PAS
next >
Wrap
Pascal/Delphi Source File
|
2000-09-27
|
6KB
|
145 lines
{****************************************************************************}
{ Data Master 2000 }
{****************************************************************************}
unit About;
{$B-,X+,S+}
interface
uses Common, Windows, ShellAPI, MMSystem, SysUtils;
type
TVersionStringKey=(vskComments, vskProductName, vskProductVersion,
vskFileDescription, vskFileVersion, vskInternalName, vskOriginalFilename,
vskLegalCopyright, vskLegalTrademarks, vskCompanyName);
const
VersionStringKeys: array[TVersionStringKey] of string=
('Comments', 'ProductName', 'ProductVersion',
'FileDescription', 'FileVersion', 'InternalName', 'OriginalFilename',
'LegalCopyright', 'LegalTrademarks', 'CompanyName');
cSystemRes=0;
cGDIRes=1;
cUSERRes=2;
function GetVersionString(Key,FName: string): string;
{This function allows to retrieve version information from resource}
function GetFreeMemory: string; {returns free memory in kbytes}
function GetTotalMemory: string; {returns available physical memory in kbytes}
procedure ShellAboutBox(Title, FName: string; H,Ico: THandle; Snd: boolean);
{This function displays standard shell about box, e.g.
with Application do ShellAboutBox(Title,Exename,Handle,Icon.Handle,true);}
procedure ShellOpenFile(Name: string); {may run browser or mailer...}
function GetFreeSystemResources(N: word): word; {thunked from 16-bit USER}
{This function allows to determine system resources like in Win16}
function IsPreRelease: boolean; {true if current file build is pre-release}
implementation
function IsPreRelease: boolean;
var H: THandle; VBS,I: dword; VB,Root: pointer; FN: array[0..300] of char;
begin
GetModuleFileName(HInstance,FN,SizeOf(FN)-1);
VBS:=GetFileVersionInfoSize(FN, H);
GetMem(VB,VBS); Result:=false;
try
if GetFileVersionInfo(FN,H,VBS,VB) then
if VerQueryValue(VB,'\',Root,I) then
if (VS_FIXEDFILEINFO(Root^).dwFileFlags and VS_FF_PRERELEASE)<>0
then Result:=true;
finally
FreeMem(VB,VBS);
end;
end;
function GetVersionString(Key,FName: string): string;
var FN,K: array[0..255] of char; VerBuf: PChar;
Han: THandle; VerBufLen, ValBufLen: cardinal;
ValBuf: pointer; LangCharID: longint;
begin
Result:=''; StrPCopy(FN,FName); {make name}
VerBufLen:=GetFileVersionInfoSize(FN, Han); {get version buffer size}
GetMem(VerBuf, VerBufLen); {alloc memory for buffer}
try
if not GetFileVersionInfo(FN,Han,VerBufLen,VerBuf) then Exit; {failure!}
if VerQueryValue(VerBuf,'\VarFileInfo\Translation',ValBuf,ValBufLen)
and (ValBufLen>0) {determine language & charset IDs}
then LangCharID:=longint(ValBuf^) else Exit; {no translation table!}
StrLFmt(K,sizeof(K),'\StringFileInfo\%4.4x%4.4x\%s', {make key info}
[(LangCharID and $ffff),(LangCharID shr 16),Key]); {according to ID!!!}
if VerQueryValue(VerBuf,K,ValBuf,ValBufLen) then
begin StrMove(FN,PChar(ValBuf),ValBufLen); Result:=StrPas(FN); end;
finally
FreeMem(VerBuf, VerBufLen); {free version buffer}
end;
end;
{$ifdef WIN32}
function LoadLibrary16(LibraryName: PChar): THandle;
stdcall; external kernel32 index 35;
procedure FreeLibrary16(HInstance: THandle);
stdcall; external kernel32 index 36;
function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer;
stdcall; external kernel32 index 37;
procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';
var hInst16: THandle; GFSR: Pointer;
function GetFreeSystemResources(N: word): word; {thunked from 16-bit USER}
var ThunkTrash: array[0..$20] of Word;
begin {implementation taken from Lischner's FreeRes.pas unit}
ThunkTrash[0]:=hInst16;
hInst16:=LoadLibrary16('user.exe');
if hInst16>=32 then
begin
FreeLibrary16(hInst16);
GFSR:=GetProcAddress16(hInst16, 'GetFreeSystemResources');
if GFSR<>nil then
asm
push N { push arguments }
mov edx, GFSR { load 16-bit procedure pointer }
call QT_Thunk { call thunk }
mov Result, ax { save the result }
end;
end;
end;
{$endif}
function GetFreeMemory: string;
{$ifdef WIN32} var MemStat: TMemoryStatus; {$endif}
begin
{$ifdef WIN32}
MemStat.dwLength:=SizeOf(TMemoryStatus); GlobalMemoryStatus(MemStat);
Result:=IntToStr(MemStat.dwAvailPhys DIV 1024)+'k';
{$else}
Result:=IntToStr(GetFreeSpace(0) DIV 1024)+'k';
{$endif}
end;
function GetTotalMemory: string;
var MemStat: TMemoryStatus;
begin
MemStat.dwLength:=SizeOf(TMemoryStatus); GlobalMemoryStatus(MemStat);
Result:=IntToStr(MemStat.dwTotalPhys DIV 1024)+'k';
end;
procedure ShellAboutBox(Title, FName: string; H,Ico: THandle; Snd: boolean);
var B,Bb: array[0..1000] of char;
begin
StrPLCopy(B, Title, SizeOf(B)-1);
StrPLCopy(Bb, 'Build '+
GetVersionString(VersionStringKeys[vskFileVersion],FName)+CRLF+
GetVersionString(VersionStringKeys[vskComments],FName),SizeOf(Bb)-1);
if Snd then PlaySound('systemstart',0,SND_ALIAS+SND_ASYNC);
ShellAbout(H, B, Bb, Ico);
end;
procedure ShellOpenFile(Name: string);
var B: array[0..1000] of char;
begin
StrPLCopy(B,Name,SizeOf(B)-1);
ShellExecute(0,nil{'open'?},B,nil,nil,SW_NORMAL);
end;
end.