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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds