Changeset 28


Ignore:
Timestamp:
Jun 4, 2010, 6:51:31 AM (14 years ago)
Author:
george
Message:
  • Upraveno: PersistentForm upraven tak, aby nevyužíval WIN32 API funkce, ale přímo vlastnosti LCL.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PersistentForm/UPersistentForm.pas

    r26 r28  
    33{$mode delphi}
    44
     5// Date: 2010-06-01
     6
    57interface
    68
    79uses
    8   Classes, SysUtils, Forms, URegistry, Windows;
     10  Classes, SysUtils, Forms, URegistry, LCLIntf, Registry;
    911
    1012type
     
    1517  public
    1618    RegistryKey: string;
    17     RegistryRootKey: Cardinal;
     19    RegistryRootKey: HKEY;
    1820    procedure Load(Form: TForm);
    1921    procedure Save(Form: TForm);
     
    2729procedure TPersistentForm.Load(Form: TForm);
    2830var
    29   Pl : TWindowPlacement;  // used for API call
    30   R : TRect;               // used for wdw pos
    31   Width, Height, Top, Left : Integer;
     31  RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight: Integer;
    3232begin
    3333  with TRegistryEx.Create do
     
    3636      OpenKey (RegistryKey + '\Forms\' + Form.Name, True);
    3737
    38       Width := ReadIntegerWithDefault ('Width', Form.Width);
    39       Height := ReadIntegerWithDefault ('Height', Form.Height);
    40       Top := ReadIntegerWithDefault ('Top', (Screen.Height - Form.Height) div 2);
    41       Left := ReadIntegerWithDefault ('Left', (Screen.Width - Form.Width) div 2);
    42       if Left < 0 then
    43         Left := 0;
    44       if Left > (Screen.Width - 50) then
    45         Left := Screen.Width - 50;
    46       if Top < 0 then
    47         Top := 0;
    48       if Top > (Screen.Height - 50) then
    49         Top := Screen.Height - 50;
     38      Form.Width := ReadIntegerWithDefault('Width', Form.Width);
     39      Form.Height := ReadIntegerWithDefault('Height', Form.Height);
     40      Form.Top := ReadIntegerWithDefault('Top', (Screen.Height - Form.Height) div 2);
     41      Form.Left := ReadIntegerWithDefault('Left', (Screen.Width - Form.Width) div 2);
     42      if Form.Left < 0 then
     43        Form.Left := 0;
     44      if Form.Left > (Screen.Width - 50) then
     45        Form.Left := Screen.Width - 50;
     46      if Form.Top < 0 then
     47        Form.Top := 0;
     48      if Form.Top > (Screen.Height - 50) then
     49        Form.Top := Screen.Height - 50;
     50      RestoredWidth := ReadIntegerWithDefault('RestoredWidth', Form.RestoredWidth);
     51      RestoredHeight := ReadIntegerWithDefault ('RestoredHeight', Form.RestoredHeight);
     52      RestoredTop := ReadIntegerWithDefault ('RestoredTop', (Screen.Height - Form.RestoredHeight) div 2);
     53      RestoredLeft := ReadIntegerWithDefault ('RestoredLeft', (Screen.Width - Form.RestoredWidth) div 2);
     54      Form.SetRestoredBounds(RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight);
    5055
    51       // Restore position using WinAPI
    52       Pl.Length := SizeOf (TWindowPlacement);
    53       GetWindowPlacement (Form.Handle, @Pl);
    54       R := Pl.rcNormalPosition;
    55       R.Left := Left;
    56       R.Top := Top;
    57       R.Right := Left + Width;
    58       R.Bottom := Top + Height;
    59       Pl.rcNormalPosition := R;
    60       if ReadBoolWithDefault('Maximized', False) then
    61         Pl.showCmd := SW_SHOWMAXIMIZED else Pl.showCmd := SW_HIDE;
    62       SetWindowPlacement(Form.Handle, @Pl);
    63 
     56      Form.WindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal)));
    6457      if ReadBoolWithDefault('Visible', False) then Form.Show;
    6558    finally
     
    6962
    7063procedure TPersistentForm.Save(Form: TForm);
    71 var
    72   Pl: TWindowPlacement;  // used for API call
    73   R: TRect;               // used for wdw pos
    7464begin
    75   {Calculate window's normal size and position using
    76   Windows API call - the form's Width, Height, Top and
    77   Left properties will give maximized window size if
    78   form is maximised, which is not what we want here}
    79   Pl.Length := SizeOf (TWindowPlacement);
    80   GetWindowPlacement (Form.Handle, @Pl);
    81   R := Pl.rcNormalPosition;
    82 
    8365  with Form, TRegistryEx.Create do
    8466    try
    8567      RootKey := RegistryRootKey;
    8668      OpenKey(RegistryKey + '\Forms\' + Form.Name, True);
    87       WriteInteger('Width', R.Right - R.Left);
    88       WriteInteger('Height', R.Bottom - R.Top);
    89       WriteInteger('Top', R.Top);
    90       WriteInteger('Left', R.Left);
    91       WriteBool('Maximized', WindowState = wsMaximized);
     69      WriteInteger('Width', Form.Width);
     70      WriteInteger('Height', Form.Height);
     71      WriteInteger('Top', Form.Top);
     72      WriteInteger('Left', Form.Left);
     73      WriteInteger('RestoredWidth', Form.RestoredWidth);
     74      WriteInteger('RestoredHeight', Form.RestoredHeight);
     75      WriteInteger('RestoredTop', Form.RestoredTop);
     76      WriteInteger('RestoredLeft', Form.RestoredLeft);
     77      WriteInteger('WindowState', Integer(Form.WindowState));
    9278      WriteBool('Visible', Form.Visible);
    9379    finally
Note: See TracChangeset for help on using the changeset viewer.