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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds