2004-06-08 21:58:59 +02:00
|
|
|
{
|
|
|
|
:: 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
|
2005-09-28 10:38:02 +02:00
|
|
|
uses
|
|
|
|
MultiMon,
|
|
|
|
Windows;
|
|
|
|
|
2004-06-08 21:58:59 +02:00
|
|
|
type
|
|
|
|
THackCustomForm = class(TCustomForm);
|
|
|
|
|
2005-03-12 17:01:52 +01:00
|
|
|
procedure ReadFormPos(const AFactory: TX2SettingsFactory;
|
|
|
|
const ASection: String; const AForm: TCustomForm);
|
2005-09-28 10:38:02 +02:00
|
|
|
var
|
|
|
|
rBounds: TRect;
|
|
|
|
|
2004-06-08 21:58:59 +02:00
|
|
|
begin
|
|
|
|
with AFactory[ASection] do
|
2005-03-12 17:01:52 +01:00
|
|
|
try
|
2005-03-14 20:17:34 +01:00
|
|
|
if ValueExists('Left') then
|
|
|
|
begin
|
|
|
|
if ReadBool('Maximized', (AForm.WindowState = wsMaximized)) then
|
|
|
|
AForm.WindowState := wsMaximized
|
2005-09-28 10:38:02 +02:00
|
|
|
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;
|
2005-03-14 20:17:34 +01:00
|
|
|
end;
|
2004-06-08 21:58:59 +02:00
|
|
|
end;
|
2005-03-12 17:01:52 +01:00
|
|
|
finally
|
|
|
|
Free();
|
|
|
|
end;
|
2004-06-08 21:58:59 +02:00
|
|
|
end;
|
|
|
|
|
2005-03-12 17:01:52 +01:00
|
|
|
procedure WriteFormPos(const AFactory: TX2SettingsFactory;
|
|
|
|
const ASection: String; const AForm: TCustomForm);
|
2005-11-29 15:00:54 +01:00
|
|
|
var
|
|
|
|
pPlacement: TWindowPlacement;
|
|
|
|
|
2004-06-08 21:58:59 +02:00
|
|
|
begin
|
|
|
|
with AFactory[ASection] do
|
2005-03-12 17:01:52 +01:00
|
|
|
try
|
|
|
|
WriteBool('Maximized', (AForm.WindowState = wsMaximized));
|
2005-11-29 15:00:54 +01:00
|
|
|
|
|
|
|
pPlacement.length := SizeOf(TWindowPlacement);
|
2005-11-29 15:01:41 +01:00
|
|
|
if GetWindowPlacement(AForm.Handle, @pPlacement) then
|
2005-11-29 15:00:54 +01:00
|
|
|
with pPlacement.rcNormalPosition do
|
|
|
|
begin
|
2005-03-12 17:01:52 +01:00
|
|
|
WriteInteger('Left', Left);
|
|
|
|
WriteInteger('Top', Top);
|
2005-11-29 15:00:54 +01:00
|
|
|
WriteInteger('Width', Right - Left);
|
|
|
|
WriteInteger('Height', Bottom - Top);
|
2005-03-12 17:01:52 +01:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Free();
|
|
|
|
end;
|
2004-06-08 21:58:59 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|