May 07, 2024, 11:33:37 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


adding controls to a dialog/window

Started by Haim, March 01, 2006, 08:12:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

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?


Ionic Wind Support Team

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.

Ionic Wind Support Team

Ionic Wind Support Team

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.

Ionic Wind Support Team

Haim