Click here to Skip to main content
Click here to Skip to main content

Dynamic Dialog Class

, 19 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Create dialogs dynamically, and easily, without the need for a dialog resource script.

Sample Image Testappliction - TestDynDialog.gif Sample Image Dynamic dialog - DynamicDialog.gif

Sample Image Dynamic dialog with List control - DynDialogList.gif Sample Image Dynamic dialog with ActiveX control - DynDialogActiveX.gif

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;
    //Create a rectangle in dialog units, where the control should be placed
    CRect rect(10,5,60,19);
    
    CDynDialogEx dlg(this);     //create the dynamic dialog, using this as parent window
    dlg.SetWindowTitle(_T("Dynamic Dialog : WindowTitle....."));

    //Add a button control at the given position
    dlg.AddDlgControl(_T("BUTTON"),    // Type of control OR classname of the control
            _T("Press me!"),    // Caption of control
            STYLE_BUTTON,    // dwStyle of control
            EXSTYLE_BUTTON,    // dwStyleEx of control
            &rect,    // Position of control on dialog in dialog units, default = NULL
            NULL,    // void pointer to variable use for DDX, default = NULL
            IDC_DYN_BUTTON);    // ID of the contol, default = zero

    //Add a group of radio buttons
    //variable nRadio1 is used for DDX
    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);

    //Now show me the dialog
    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
  • ...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Marcel Scherpenisse
Software Developer
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
QuestionCompile as DLL? Pinmembernamezero1111118-Jul-10 11:21 
AnswerRe: Compile as DLL? PinmemberAlbert van Peppen12-Sep-10 22:37 
Generalanother approach to dynamic dialogs [modified] PinmemberMikeDunlavey24-Nov-07 3:42 
QuestionAdding a button to an existing dialog class dynamically Pinmemberodette77629-Nov-06 15:43 
GeneralCrear con otra vntana padre Pinmemberucsm14-Oct-06 16:03 
GeneralRe: Crear con otra vntana padre Pinmemberlexugax22-Mar-07 23:38 
GeneralRe: Crear con otra vntana padre PinmemberKeia26-May-08 21:37 
GeneralIs possible to add a control to an existing dialog Pinmemberdtgarry15-Jun-06 4:25 
AnswerRe: Is possible to add a control to an existing dialog PinmemberMarcel Scherpenisse15-Jun-06 6:21 
Questionto add new control to dynamic dialog box at runtime Pinmemberwavesss5-Apr-06 23:50 
AnswerRe: to add new control to dynamic dialog box at runtime PinmemberMarcel Scherpenisse5-Apr-06 23:58 
GeneralSpinner message solution ! Pinmembersaviorman28-Feb-06 4:39 
GeneralInspiration PinmemberRedZenBird17-Sep-05 9:33 
GeneralDynamic Modeless dialog bug PinmemberMNN Murthy6-May-04 9:38 
GeneralRe: Dynamic Modeless dialog bug PinsussAnonymous7-Mar-05 1:30 
QuestionHOw to Add the Contents to Combo Box PinmemberDELIVER THE PROMISE16-Dec-03 20:35 
AnswerRe: HOw to Add the Contents to Combo Box PinmemberPaul Wolfensberger4-Aug-04 13:01 
GeneralRe: HOw to Add the Contents to Combo Box PinmemberMarcel Scherpenisse5-Aug-04 3:46 
GeneralRe: How to Add the Contents to Combo Box PinmemberJordan Walters4-Jan-05 23:56 
GeneralRe: How to Add the Contents to Combo Box Pinmemberrudywang20-Sep-06 20:39 
GeneralRe: How to Add the Contents to Combo Box PinmemberLieWei6-Apr-12 15:12 
QuestionRe: How to Add the Contents to Combo Box PinmemberMember 927478521-Jul-12 22:48 
GeneralRe: How to Add the Contents to Combo Box PinmemberLIYAFU6-Dec-12 2:30 
GeneralGood work PinmemberVitali Halershtein30-Sep-03 6:01 
GeneralAWT PinmemberGeMe_Hendrix23-Jul-03 2:21 
Generalbuttons with bitmaps PinmemberFreespirit13-Feb-03 3:48 
QuestionHow to add Scrolling Pinmembermarigapudi6-Jan-03 6:02 
GeneralTab Control Use Pinmembermcordon26-Dec-02 0:49 
QuestionRe: Tab Control Use Pinmemberkdobek3-Jul-08 14:08 
GeneralSupport for controls not standart Pinmemberamauta20-Nov-02 10:27 
GeneralRe: Support for controls not standart PinmemberChrisJohnShort6-Mar-06 17:59 
QuestionWhere's the new version? Pinmembernaveed20-Jun-02 13:45 
AnswerRe: Where's the new version? PinadminChris Maunder21-Jun-02 15:25 
GeneralAdding CListCtrl PinmemberTximist25-Apr-02 1:59 
GeneralRe: Adding CListCtrl PinmemberBlagodaria25-Apr-02 2:06 
GeneralRe: Adding CListCtrl PinmemberGreg Niswonger26-Oct-06 10:47 
GeneralDDX PinmemberEVOLUTION MAN1-Oct-01 13:28 
Generalresize dialog Pinmemberray4-Apr-01 6:29 
GeneralRe: resize dialog PinmemberChunjying17-Apr-01 23:52 
GeneralAdding entries to a ClistCtrl PinsussRon King25-Sep-00 4:54 
AnswerRe: Adding entries to a ClistCtrl PinmemberGreg Niswonger26-Oct-06 10:53 
GeneralRe: Adding entries to a ClistCtrl PinmemberCALIFF219-Oct-09 12:39 
GeneralRe: Adding entries to a ClistCtrl PinmemberGreg Niswonger20-Oct-09 4:48 
GeneralAdding ActiveX Controls PinsussJames Hunter Ross20-Sep-00 8:29 
GeneralRe: Adding ActiveX Controls PinsussMarcel Scherpenisse24-Sep-00 23:19 
QuestionHow are you supposed to adjust the controls? PinsussJason15-Sep-00 6:06 
AnswerRe: How are you supposed to adjust the controls? PinsussMarcel Scherpenisse18-Sep-00 23:15 
GeneralThis is great, but... PinsussNathan Cook9-Jun-00 9:26 
GeneralRe: This is great, but... Pinmember*RPM16-Apr-03 4:16 
GeneralRe: This is great, but... PinmemberKarstenK15-Mar-04 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 20 Jun 2002
Article Copyright 2000 by Marcel Scherpenisse
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid