Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

News Tips .NET Software VCL Software Partners  

Restore window to its last state
You can store the main parameters of your form in Registry. Resave them, when you close form, and you can restore them, if you create form again.

uses Registry;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  with TRegistry.Create do
  begin
   RootKey:=HKEY_LOCAL_MACHINE;
   if OpenKey('Greatis Software\Example\Form', True) then
   begin
     WriteInteger('Left', Form1.Left);
     WriteInteger('Top',  Form1.Top);
     WriteInteger('Width', Form1.Width);
     WriteInteger('Height', Form1.Height);
     case WindowState of
       wsMaximized: WriteInteger('State', 1);
       wsMinimized: WriteInteger('State', 2);
       wsNormal   : WriteInteger('State', 3);
     end;
   end
   else
     MessageDlg('Registry reading error', mtError, [mbOk], 0);
   CloseKey;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TRegistry.Create do
  begin
    RootKey:=HKEY_LOCAL_MACHINE;
    if OpenKey('Greatis Software\Example\Form', False) then
    try
      Form1.Left:=ReadInteger('Left');
      Form1.Top:=ReadInteger('Top');
      Form1.Width:=ReadInteger('Width');
      Form1.Height:=ReadInteger('Height');
     case ReadInteger('State') of
       1: Form1.WindowState:=wsMaximized;
       2: Form1.WindowState:=wsMinimized;
       3: Form1.WindowState:=wsNormal;
     end;
    except
      MessageDlg('Can not go to handle', mtError, [mbOk], 0);
    end
    else
      MessageDlg('Registry reading error', mtError, [mbOk], 0);
    CloseKey;
  end;
end;

Related chapters
System
Registry

Related topics
Detect windows version
Detect font (Small or Large) is in use
Use registry instead of *.ini file

For more
Delphi Help

Download source


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software