JasmineCorp Directory   
  
Usenet News Group Archives!!!

Usenet Groups:

 

 

 

 

 

Re: Create a new form dinamically so that ...
--------------------------------------------------------------------------------------------
Newsgroup: borland.public.cppbuilder.students
Posted by: Stefano Frosio
2006-12-19 19:10:01

> how i can keep open the second form (Form2) when i close the
> main form (Form1)?
>
> Mozzilla Thundembird has this behaviour!

Here are the steps to reproduce the same behaviour, of course
there could be other and better ways. Furthermore I haven't
tested the code deeply:

1) Create an application with 2 forms: Form1 (the main) and
Form2;

2) Add a TButton to Form2 and assign the below reported method.
Set the form's Position property to poDefaultPosOnly (just for
test);

3) Hide Form1 adding the following code in the WinMain function:

ShowWindow(Application->Handle, SW_HIDE);
Application->ShowMainForm = false;

4) Unit1.cpp (add a member of type int called NumberOfForm2 to
TForm1):

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
NumberOfForm2 = 0;
NewForm();
}

void __fastcall TForm1::NewForm(void)
{
TForm2 *F2 = new TForm2(this);
if (F2)
{
++NumberOfForm2;
F2->OnClose = Form2Close;
F2->Show();
}
}

void __fastcall TForm1::Form2Close(TObject *Sender, TCloseAction
&Action)
{
Action = caFree;
if (--NumberOfForm2 == 0) Close();
}

5) Unit2.cpp:

void __fastcall TForm2::CreateParams(TCreateParams &Params)
{
TForm::CreateParams(Params);
Params.ExStyle |= WS_EX_APPWINDOW;
Params.WndParent = GetDesktopWindow();
}

void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form1->NewForm();
}

You'll see one form (Form2) at start-up. Each time you click the
button a new form is shown. When all forms (Form2) are closed,
the main (hidden) form (and so the Application) is closed.

HTH,

--
Stefano Frosio
www.esse-effe.com


 

 

 

More >> 

Domain Registration:
.com .org .net
.info .biz .us