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

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

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

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

void __fastcall TForm1::NewForm(void)
TForm2 *F2 = new TForm2(this);
if (F2)
F2->OnClose = Form2Close;

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

5) Unit2.cpp:

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

void __fastcall TForm2::Button1Click(TObject *Sender)

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.


Stefano Frosio




More >> 

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