Главная страница | назад





Article #18795: Storing a Forms Position and Size in The Registry

 Question and Answer Database
FAQ3795C.txt Storing a Forms Position and Size in The Registry
Category :VCL
Platform :Win95/NT
Product : C++Builder1.0 C++Builder3.x
Question:
How do I store my forms position and size in the Windows
registry?
Answer:
Place the following code in your form's OnShow and OnClose
Events:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
TRegistry *Registry = new TRegistry();
// You must have this try catch block because these
// registry entries may not exist the first time
// your application is run.
try
{
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey("Software\\CGSoftware International\\CoolTool", true);
Left = Registry->ReadInteger("Left");
Top = Registry->ReadInteger("Top");
Height = Registry->ReadInteger("Height");
Width = Registry->ReadInteger("Width");
Registry->CloseKey();
}
catch (...)
{
ShowMessage("First Run detected.");
}
delete Registry;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
TRegistry *Registry = new TRegistry();
try
{
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey("Software\\CGSoftware International\\CoolTool", true);
Registry->WriteInteger("Left", Left);
Registry->WriteInteger("Top", Top);
Registry->WriteInteger("Height", Height);
Registry->WriteInteger("Width", Width);
Registry->CloseKey();
}
catch (...)
{
ShowMessage("Error: Problem with Registry");
}
delete Registry;
}
//---------------------------------------------------------------------------
NOTE: Make sure that your form's Position property is
set to poDesigned.
12/30/99

Last Modified: 01-SEP-99