IonicWind Software

Aurora Compiler => GUI => Topic started by: Haim on March 01, 2006, 08:12:30 AM

Title: adding controls to a dialog/window
Post by: Haim on March 01, 2006, 08:12:30 AM
Hi,
Being a newbie I risk being ridiculed for asking stupid questions... Hope you indulge me... I have two questions:
1. I saw several examples in which controls are added to a window in sub main().
Is this the only place to do so? Can this be done in OnCreate() method of the dialog instance?

Title: Re: adding controls to a dialog/window
Post by: Ionic Wind Support Team on March 01, 2006, 08:27:01 AM
A dialog is a template which describes the controls to be created when DoModal or ShowDialog methods are called.  The  AddControl method adds control descriptions to that template.  AddControl doesn't create the control, just describes it.

You don't have to do that in main() of course.  But you do need to do it before DoModal or ShowDilaog is called.

You could create controls manually by defining a control class instance, and calling it's Create method.

Button b1;
b1.Create(....)

However with a dialog you would have to do that in OnInitDialog, not OnCreate.  And the control variables would need to be member variables of your dialog class, or dynamically created with NEW.

Controls in a window are always created manually.  See the examples included with build such as editor.src or keno.src.

Paul.

Title: Re: adding controls to a dialog/window
Post by: Ionic Wind Support Team on March 01, 2006, 08:54:09 AM
And if none of that was clear please let me know ;)  Otherwise I keep on rambling.

More descriptions:

Dialogs are reusable templates of controls.  There original design was to create a template once that could be shown many times without having to create controls manually with CreateWindow (Windows API).  In most programming languages a dialog template is created and saved in the executables resources to be loaded and shown on demand.

Aurora creates the template in memory with the CDialog::Create and CDialog::AddControl methods.  The template is loaded and shown when CDialog::DoModal or CDialog::ShowDialog is called. 

The important thing to note is you only need to create the template once.  When the dialog is closed you only need to use DoModal to show it again.  Windows takes care of creation/destruction of the controls in the template.

In a window if you delete the controls, or close the window, you would need to create each control again, usually in a subroutine.

Paul.

Title: Re: adding controls to a dialog/window
Post by: Haim on March 01, 2006, 11:02:43 PM
Thanks,
It is very clear now.