Create Modal dialog and add controls dynamically
Article Metadata
Code Example
Article
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 |
EEikDialogFlagCbaButtons;
buttons = R_AVKON_SOFTKEYS_OK_EMPTY;
// 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 );
iEdwin->CreateTextViewL();
iEdwin->SetTextL(&KMyText);
}
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();
iEdwin->SetRect(rect);
}
Launching the dialog :
The following code snippet launches the dialog using the specified resource (RESOURCE DIALOG):
CModalDialog* dlg = new (ELeave) CModalDialog;
dlg->ExecuteLD(R_MODAL_DIALOG);
Code Example :
File:ModalDlgWithEdwinControl.zip
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;
break;
default:
break;
}
return controlInfo;
}


(no comments yet)