1
0
mirror of synced 2024-09-19 17:56:09 +00:00
x2utils/X2UtSettingsForm.pas
Mark van Renswoude e2f278892e Added: internet version checking
Fixed: restoring form position checks for visibility
2005-09-28 08:38:02 +00:00

80 lines
2.2 KiB
ObjectPascal

{
:: X2UtSettingsForm provides functions to read and write form settings.
::
:: Last changed: $Date$
:: Revision: $Rev$
:: Author: $Author$
}
unit X2UtSettingsForm;
interface
uses
Forms,
X2UtSettings;
procedure ReadFormPos(const AFactory: TX2SettingsFactory;
const ASection: String; const AForm: TCustomForm);
procedure WriteFormPos(const AFactory: TX2SettingsFactory;
const ASection: String; const AForm: TCustomForm);
implementation
uses
MultiMon,
Windows;
type
THackCustomForm = class(TCustomForm);
procedure ReadFormPos(const AFactory: TX2SettingsFactory;
const ASection: String; const AForm: TCustomForm);
var
rBounds: TRect;
begin
with AFactory[ASection] do
try
if ValueExists('Left') then
begin
if ReadBool('Maximized', (AForm.WindowState = wsMaximized)) then
AForm.WindowState := wsMaximized
else with THackCustomForm(AForm) do
begin
rBounds.Left := ReadInteger('Left', Left);
rBounds.Top := ReadInteger('Top', Top);
rBounds.Right := rBounds.Left + ReadInteger('Width', Width);
rBounds.Bottom := rBounds.Top + ReadInteger('Height', Height);
// Make sure the window is at least partially visible
if MonitorFromRect(@rBounds, MONITOR_DEFAULTTONULL) <> 0 then
begin
WindowState := wsNormal;
Position := poDesigned;
BoundsRect := rBounds;
end;
end;
end;
finally
Free();
end;
end;
procedure WriteFormPos(const AFactory: TX2SettingsFactory;
const ASection: String; const AForm: TCustomForm);
begin
with AFactory[ASection] do
try
WriteBool('Maximized', (AForm.WindowState = wsMaximized));
if AForm.WindowState <> wsMaximized then
with THackCustomForm(AForm) do begin
WriteInteger('Left', Left);
WriteInteger('Top', Top);
WriteInteger('Width', Width);
WriteInteger('Height', Height);
end;
finally
Free();
end;
end;
end.