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
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
|EEikDialogFlagNoTitleBar | EEikDialogFlagNoDrag |
buttons = R_AVKON_SOFTKEYS_OK_EMPTY;
// Do not add any items
Add Edwin control to the modal dialog :
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().
_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.
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 )
ontrolInfo.iControl = NULL;
controlInfo.iTrailerTextId = 0;
controlInfo.iFlags = 0;
switch ( aControlType )
// Instantiate your own custom control here
controlInfo.iControl = new (ELeave) CMyControl;