Dynamic Dialog class
These classes are being used for displaying a modal/modelles dialog, on which
the controls are dynamically added, without the need of having a dialog
template as resource. 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:
- class is derived of
CDialog
- in the class there is an array of
CDynDialogItemEx
pointers, the dialog controls
- class includes
DoDataExchange()
function.
- add controls to dialog through function
AddDlgControl()
Global structure of the CDynDialogItemEx
class:
- class is derived of
CWnd
- 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;
CRect rect(10,5,60,19);
CDynDialogEx dlg(this);
dlg.SetWindowTitle(_T("Dynamic Dialog : WindowTitle....."));
dlg.AddDlgControl(_T("BUTTON"),
_T("Press me!"),
STYLE_BUTTON,
EXSTYLE_BUTTON,
&rect,
NULL,
IDC_DYN_BUTTON);
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);
dlg.DoModal()
}
Working explained
CDynDialogEx::AddDlgControl()
function creates new
object of class CDynDialogItemEx
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.
CDynDialogEx::DoModal()
function initializes the
DLGTEMPLATE
structure using the selected font and calls
CDialog::InitModalIndirect()
for modal dialogs or
CDialog::CreateIndirect()
for modless dialogs
CDynDialogEx::OnCreate()
function creates all the
controls on the dialog
CDynDialogItemEx::CreateEx()
does nothing (ActiveX controls)
or creates the window
CDynDialogEx::OnInitDialog()
function repositions
all the controls on the dialog or creates the ActiveX controls
CDynDialogItemEx::SetWindowPos()
function converts from
dialog units to screen units and creates ActiveX control
Update 18-06-2002
- Class
CDynDialogItemEx
now derived from CWnd instead of heaving a CWnd member
- Added modless gialog possibility as supposed by CodeBuddy. (
CDynDialogEx::SetUseModeless()
)
- Added subclassed controls, because I needed them. After adding the control you can use
SubclassDlgItem with the Control_ID returned by calling
CDynDialogEx::AddSubclassedDlgControl()
- Improved
DDX_Control
support for dialog items
- Added partial ActiveX controls support. Partial because the controls are created, but there is
no support for the EVENT_SINK! But there is code for creating licensed controls dynamicly.
- Added examples for modeless dialog, adding and filling a CListbox,
an ActiveX control on a dialog
Tip!
Possible extensions:
- improving ActiveX controls support, specially EVENT_SINK related
- adding Menus dynamically to the dialog
- ...