#include <IniFiles.hpp>
#include <DBGrids.hpp>
#include<memory>
//RegistrarControles(This); en el constructor de la forma
//---------------------------------------------------------------------------
void __fastcall RegistrarControles(TWinControl *F)
{
AnsiString asResize=ExtractFilePath(Application->ExeName)+F->Name.Trim()+".ini";
std::auto_ptr<TIniFile> pIni(new TIniFile(asResize));
TControl *pControl;
TDBGrid *pGrid;
TStatusBar *pBar;
float ccLeft,ccHeight,ccTop,ccWidth,cgWith,csWith;
AnsiString Tclase;
for(int control = 0; control <F->ComponentCount; control++)
{
Application->ProcessMessages();
if (F->Components[control]->InheritsFrom(__classid(TControl)))
{
Application->ProcessMessages();
pControl = dynamic_cast<TControl*>(F->Components[control]);
Tclase = AnsiString(pControl->ClassName().operator AnsiString());
// sacamos los porcentajes
ccTop = ( pControl->Top * 100 ) / F->Height;
ccLeft = ( pControl->Left * 100 ) / F->Width;
ccHeight = ( pControl->Height * 100 ) / F->Height;
ccWidth = ( pControl->Width * 100 ) / F->Width;
// grabamos en Archivo de Configuracion
pIni->WriteFloat(pControl->Name,"Top",ccTop) ;
pIni->WriteFloat(pControl->Name,"Left",ccLeft) ;
pIni->WriteFloat(pControl->Name,"Width",ccWidth) ;
pIni->WriteFloat(pControl->Name,"Height",ccHeight) ;
if(Tclase == "TDBGrid")
{
pGrid = dynamic_cast<TDBGrid*>(F->Components[control]);
for(int col=0;col<pGrid->Columns->Count;col++)
{
cgWith = (pGrid->Columns->Items[col]->Width * 100) / pGrid->Width;
pIni->WriteFloat(pControl->Name,"col"+AnsiString(col),cgWith);
}
}
}
}
pIni->UpdateFile();
}
//---------------------------------------------------------------------------
//AcomodarControles(This); en el evento OnResize de la forma
void __fastcall AcomodarControles(TWinControl *F)
{
AnsiString asResize=ExtractFilePath(Application->ExeName)+F->Name.Trim()+".ini";
std::auto_ptr<TIniFile> pIni(new TIniFile(asResize));
TControl *pControl;
TDBGrid *pGrid;
float ccLeft,ccHeight,ccTop,ccWidth;
float gWidthCol;
for(int control = 0; control <F->ComponentCount; control++)
{
if (F->Components[control]->InheritsFrom(__classid(TControl)))
{
Application->ProcessMessages();
pControl = reinterpret_cast<TControl*>(F->Components[control]);
// recuperamos los porcenajes en relacion al form
ccTop = pIni->ReadFloat(pControl->Name,"Top",ccTop);
ccLeft = pIni->ReadFloat(pControl->Name,"Left",ccLeft) ;
ccWidth = pIni->ReadFloat(pControl->Name,"Width",ccWidth) ;
ccHeight= pIni->ReadFloat(pControl->Name,"Height",ccHeight) ;
pControl->Left = (ccLeft * F->Width) / 100 ;
pControl->Top = (ccTop * F->Height) / 100 ;
pControl->ClientWidth = (ccWidth * F->Width) / 100 ;
pControl->ClientHeight = (ccHeight * F->Height) / 100 ;
if(pControl->ClassName().operator AnsiString()=="TDBGrid")// Esto lo hice yo
{
pGrid = reinterpret_cast<TDBGrid*>(F->Components[control]);
for(int col=0;col<pGrid->Columns->Count;col++)
{
gWidthCol = pIni->ReadFloat(pControl->Name,"col"+AnsiString(col),gWidthCol);
pGrid->Columns->Items[col]->Width=(gWidthCol*pGrid->Width)/100;
}
}
}
}
}