Embed 'child' dialogs into your main dialog

Environment: VC6, VC5

One of the challenges I was recently set was to produce some code that would allow 'child' dialogs to be added to a 'parent' dialog at run time so that all the controls operated as if they were part of the original dialog.

To this end I came up with some code that reads the dialog template resource file of the child dialogs and embeds the controls onto the parent dialog.

Using the code is simple. Derive your parent dialog from the CMultiDialog class and call the AddDialog function to embed your child dialog. The first parameter is the ID of the child dialog template and the second parameter is the ID of a marker control (usually a static control) that marks the position of the child control. This marker control will be hidden after the child controls have been embedded.

Place follow lines into the OnInitDialog function of the parent dialog. // Embed the dialog AddDialog( IDD_DIALOG1, IDC_MARKER );

Access controls on the dialog as per a normal dialog control. eg.:-

   m_pListBox = (CListBox*) GetDlgItem( IDC_LIST1 );
   if ( m_pListBox ) {
      m_pListBox->AddString( "First" );
      m_pListBox->AddString( "Second" );
      m_pListBox->AddString( "Third" );
   }

I've not extensively tested this code - so don't shoot me if it breaks! :o)

Downloads

Download demo project - 33 Kb
Download source - 3 Kb


Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds