Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Create Modal dialog and add controls dynamically

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: kiranmudiyam (10 Sep 2007)
Last edited: hamishwillee (20 Jul 2012)

Create an empty modal dialog :

Define a Dialog resource in RSS file with out any items. Instead of defining the items in the resource file, you can also construct them dynamically. Below is a sample code to create an empty dialog.

RESOURCE DIALOG r_modal_dialog
flags=EEikDialogFlagWait |EEikDialogFlagFillAppClientRect
|EEikDialogFlagNoTitleBar | EEikDialogFlagNoDrag |
// Do not add any items

Add Edwin control to the modal dialog :

Header files:

#include <eikedwin.h> 
#include <eikdialg.h>

Link against:

LIBRARY avkon.lib eikcoctl.lib eikctl.lib form.lib uiklaf.lib eikdlg.lib

PreLayoutDynInitL() is called by the EIKON dialog framework before the dialog is sized and laid out.The default implementation is empty and it should be overloaded to initialize the control values that should influence sizing and layout.

Now in PreLayoutDynInitL() controls can be created and added to the dialog dynamically using CreateLineByTypeL().

void CModalDialog::PreLayoutDynInitL()
_LIT(KMyText, "The mobile phone market will flourish
when software for phones flourishes"
const TInt KMyId = 1;
// To Create Edwin control
CCoeControl* control = CreateLineByTypeL(KNullDesC, KMyId, EEikCtEdwin, NULL);
iEdwin = static_cast<CEikEdwin*>(control);
iEdwin->ConstructL( EEikEdwinNoHorizScrolling |EEikEdwinNoAutoSelection
|EEikEdwinResizable, 20, 100, 10 );

PostLayoutDynInitL() is called by the EIKON dialog framework just before the dialog is activated, after it has called PreLayoutDynInitL() and the dialog has been sized.

void CModalDialog::PostLayoutDynInitL()
TRect rect = Rect();

Launching the dialog :

The following code snippet launches the dialog using the specified resource (RESOURCE DIALOG):

CModalDialog* dlg = new (ELeave) CModalDialog;

Code Example :

Add custom control to the modal dialog :

A control of type aControlType specified in CreateLineByTypeL() is created by the control factory. Built-in control types are recognized by the framework.If the value of aControlType is not known to the control factory then the construction of the control must be handled by CreateCustomControlL().

const TInt KMyId = 1;
const TInt EMyCotrol = 2300; // any arbitary value
CCoeControl* control = CreateLineByTypeL(KNullDesC, KMyId, EMyCotrol, NULL);
// CreateCustomControlL() called by framework
SEikControlInfo CMyDialog::CreateCustomControlL( TInt aControlType )
SEikControlInfo controlInfo;
ontrolInfo.iControl = NULL;
controlInfo.iTrailerTextId = 0;
controlInfo.iFlags = 0;
switch ( aControlType )
case EMyControl:
// Instantiate your own custom control here
controlInfo.iControl = new (ELeave) CMyControl;
return controlInfo;
This page was last modified on 20 July 2012, at 07:23.
36 page views in the last 30 days.