Componentes.Terceros.jvcl/official/3.00/run/JvgSysRequirements.pas

212 lines
7.3 KiB
ObjectPascal

{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvgSysRequirements.PAS, released on 2003-01-15.
The Initial Developer of the Original Code is Andrey V. Chudin, [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Burov Dmitry, translation of russian text.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvgSysRequirements.pas,v 1.23 2005/10/28 08:37:23 marquardt Exp $
unit JvgSysRequirements;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, SysUtils, Classes, Forms,
JvVCL5Utils,
JvComponentBase,
JclSysInfo;
type
TJvSystemFont = (fsfSmallFont, fsfBigFont);
TJvSystemFontSet = set of TJvSystemFont;
TWindowsVersionSet = set of TWindowsVersion;
TJvSysReqBehavior = (fsbHalt, fsbWarning);
TJvWarningEvent = procedure(Sender: TObject; var ReportMessage: string;
var DoShowWarning, DoHalt: Boolean) of object;
const
AllWindowsVersions = [wvUnknown];
AllSystemFonts = [fsfSmallFont, fsfBigFont];
type
TJvgSysRequirements = class(TJvComponent)
private
FBehavior: TJvSysReqBehavior;
FEnabled: Boolean;
FMinColorDepth: Integer;
FMaxColorDepth: Integer;
FMinScreenX: Integer;
FMaxScreenX: Integer;
FMinScreenY: Integer;
FMaxScreenY: Integer;
FSystemFonts: TJvSystemFontSet;
FWindowsVersions: TWindowsVersionSet;
FMinVideoRefreshRate: Integer;
FMaxVideoRefreshRate: Integer;
FOnWarning: TJvWarningEvent;
protected
procedure Loaded; override;
function TestRequirements(var ReportMessage: string): Boolean; dynamic;
public
constructor Create(AOwner: TComponent); override;
published
property Behavior: TJvSysReqBehavior read FBehavior write FBehavior default fsbHalt;
property Enabled: Boolean read FEnabled write FEnabled default True;
property MinColorDepth: Integer read FMinColorDepth write FMinColorDepth default 0;
property MaxColorDepth: Integer read FMaxColorDepth write FMaxColorDepth default 0;
property MinScreenX: Integer read FMinScreenX write FMinScreenX default 0;
property MaxScreenX: Integer read FMaxScreenX write FMaxScreenX default 0;
property MinScreenY: Integer read FMinScreenY write FMinScreenY default 0;
property MaxScreenY: Integer read FMaxScreenY write FMaxScreenY default 0;
property MinVideoRefreshRate: Integer read FMinVideoRefreshRate write FMinVideoRefreshRate default 0;
property MaxVideoRefreshRate: Integer read FMaxVideoRefreshRate write FMaxVideoRefreshRate default 0;
property WindowsVersions: TWindowsVersionSet read FWindowsVersions write FWindowsVersions default AllWindowsVersions;
property SystemFonts: TJvSystemFontSet read FSystemFonts write FSystemFonts default AllSystemFonts;
property OnWarning: TJvWarningEvent read FOnWarning write FOnWarning;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvgSysRequirements.pas,v $';
Revision: '$Revision: 1.23 $';
Date: '$Date: 2005/10/28 08:37:23 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
JvResources;
constructor TJvgSysRequirements.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBehavior := fsbHalt;
FEnabled := True;
FMinColorDepth := 0;
FMaxColorDepth := 0;
FMinScreenX := 0;
FMaxScreenX := 0;
FMinScreenY := 0;
FMaxScreenY := 0;
FMinVideoRefreshRate := 0;
FMaxVideoRefreshRate := 0;
FWindowsVersions := AllWindowsVersions;
FSystemFonts := AllSystemFonts;
end;
procedure TJvgSysRequirements.Loaded;
var
ReportMessage: string;
DoShowWarning, DoHalt: Boolean;
Icon: Integer;
begin
inherited Loaded;
if Enabled and not (csDesigning in ComponentState) then
if not TestRequirements(ReportMessage) then
begin
DoShowWarning := True;
DoHalt := Behavior = fsbHalt;
if Assigned(FOnWarning) then
FOnWarning(Self, ReportMessage,DoShowWarning, DoHalt);
if DoHalt then
Icon := MB_ICONWARNING
else
Icon := MB_ICONERROR;
if DoShowWarning then
Application.MessageBox(PChar(ReportMessage),
PChar(ExtractFileName(ParamStr(0))), MB_OK + Icon);
if DoHalt then
Application.Terminate;
end;
end;
function TJvgSysRequirements.TestRequirements(var ReportMessage: string): Boolean;
var
DC: HDC;
Refresh, ScreenX, ScreenY, BitsPerPixel, LogPixels: Integer;
procedure Test(Value: Boolean; const ErrMsg: string);
begin
Result := Result and Value;
if not Value then
begin
if ReportMessage <> '' then
ReportMessage := ReportMessage + sLineBreak;
ReportMessage := ReportMessage + ErrMsg;
end;
end;
procedure TestMinMax(TestVal, MinVal, MaxVal: Integer; const MinMsg, MaxMsg, BetweenMsg: string);
begin
if (MinVal > 0) or (MaxVal > 0) then
if (MinVal > 0) and (MaxVal > 0) then
Test((TestVal >= MinVal) and (TestVal <= MaxVal), Format(BetweenMsg, [TestVal, MinVal, MaxVal]))
else
if MinVal > 0 then
Test(TestVal >= MinVal, Format(MinMsg, [TestVal, MinVal]))
else
Test(TestVal <= MaxVal, Format(MaxMsg, [TestVal, MaxVal]));
end;
begin
ReportMessage := '';
Result := True;
DC := GetDC(HWND_DESKTOP);
BitsPerPixel := GetDeviceCaps(DC, BITSPIXEL);
ScreenX := GetDeviceCaps(DC, HORZRES);
ScreenY := GetDeviceCaps(DC, VERTRES);
Refresh := GetDeviceCaps(DC, VREFRESH);
LogPixels := GetDeviceCaps(DC, LOGPIXELSX);
ReleaseDC(HWND_DESKTOP, DC);
TestMinMax(BitsPerPixel, MinColorDepth, MaxColorDepth, RsMinColorDepthReq, RsMaxColorDepthReq, RsBetweenColorDepthReq);
TestMinMax(ScreenX, MinScreenX, MaxScreenX, RsMinScreenXReq, RsMaxScreenXReq, RsBetweenScreenXReq);
TestMinMax(ScreenY, MinScreenY, MaxScreenY, RsMinScreenYReq, RsMaxScreenYReq, RsBetweenScreenYReq);
TestMinMax(Refresh, MinVideoRefreshRate, MaxVideoRefreshRate, RsMinRefreshReq, RsMaxRefreshReq, RsBetweenRefreshReq);
if not (wvUnknown in WindowsVersions) then
Test(GetWindowsVersion in WindowsVersions, RsWindowsVersionReq);
if SystemFonts = [fsfSmallFont] then
Test(LogPixels = 96, RsSystemFontSmallReq);
if SystemFonts = [fsfBigFont] then
Test(LogPixels = 120, RsSystemFontBigReq);
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.