These classes were developed as base classes for use in a script parser, where users can build there own dialogs, using a VB-script alike language. So basically there can be any number of controls on the dialog, at any place on the dialog.
Global structure of the
CDynDialogEx |
- class is derived of
CDialog
- in the class there is an array of
pointers, the dialog controlsCDynDialogItemEx
- class includes
function.DoDataExchange()
- add controls to dialog through function
AddDlgControl()
Global structure of the
CDynDialogItemEx |
- holds the data of the control that was added to the dialog, like the caption, the rectangle, etc.
- creates the controls on the dialog
Small piece of sample code on how to use the classes
void CTestDynDialogDlg::OnButton1(); { int nRadio1 = 0; <font color=#008000>//Create a rectangle in dialog units, where </font> <font color=#008000>//the control should be placed</font> CRect rect(10,5,60,19); <font color=#008000>//create the dynamic dialog, </font> <font color=#008000>//using this as parent window</font> CDynDialogEx dlg(this); dlg.SetWindowTitle(_T("Dynamic Dialog : WindowTitle.....")); <font color=#008000>//Add a button control at the given position</font> dlg.AddDlgControl(_T("BUTTON"), <font color=#008000>// Type of control OR control classname</font> _T("Press me!"), <font color=#008000>// Caption of control</font> STYLE_BUTTON, <font color=#008000>// dwStyle of control</font> EXSTYLE_BUTTON, <font color=#008000>// dwStyleEx of control</font> &rect, <font color=#008000>// Position of control on dlg in dlg units</font> NULL, <font color=#008000>// void ptr to DDX var - default=NULL</font> IDC_DYN_BUTTON); <font color=#008000>// control ID - default=zero</font> <font color=#008000>//Add a group of radio buttons</font> <font color=#008000>//variable nRadio1 is used for DDX</font> dlg.AddDlgControl(_T("BUTTON"), _T("Radio1Caption 1"), STYLE_RADIO_GROUP, EXSTYLE_RADIO, NULL, (void*)&nRadio1); dlg.AddDlgControl(_T("BUTTON"), _T("Radio1Caption 2"), STYLE_RADIO, EXSTYLE_RADIO); <font color=#008000>//Now show me the dialog</font> dlg.DoModal() } |
Working explained
function creates new object of classCDynDialogEx::AddDlgControl()
and adds it to the array of controls. Function also checks/sets the size of the dialog, so the control is seen on the dialog.CDynDialogItemEx
function initializes theCDynDialogEx::DoModal()
structure using the selected font and callsDLGTEMPLATE
CDialog::InitModalIndirect()
function creates all the controls on the dialogCDynDialogEx::OnInitDialog()
function converts from dialog units to screen units and creates the controlCDynDialogItemEx::CreateEx()
Possible extensions:
- adding ActiveX controls dynamically to the dialog
- adding Menus dynamically to the dialog
- …