We help IT Professionals succeed at work.

Wizard style nested dialogs using VC++/MFC

1,682 Views
Last Modified: 2013-12-14
I want create wizard style nested dialogs using VC++/MFC, there will be only one outer dialog with some header and footer with JPG images and there will be many inner dialog. The inner dialog will keep on changing based on selecting back and Next button.

 I am using a static box as a place holder and I am able to insert one dialog(child) by adding the following code in OnInitDialog.  But how can I make it like a wizard, so that on selecting next and back I can change the inner dialog?

CRect rct;
      m_staticPlaceholder.GetWindowRect(&rct); // In screen coordinates
      ScreenToClient(&rct);
      m_staticPlaceholder.ShowWindow(SW_HIDE);
      
          CDialog* pchild = new CWelComeDlg;
      // Call Create() explicitly to ensure the HWND is created.
      pchild->Create(CWelComeDlg::IDD, this);
      

      // Set the window position to be where the placeholder was.
                     pchild->SetWindowPos(NULL,rct.left,rct.top,rct.Width(),rct.Height(), SWP_SHOWWINDOW)
Comment
Watch Question

Freelance programmer / Consultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
CPropertySheet and CPropertyPage is a good option. I have used them many times, for this particular scenario its not appropriate, especially when I need few other buttons apart from Next and back and I even need to have all my inner and outer dialogs to use JPG files as the back ground.

Thanks
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
OK.

pChild->ShowWindow(SW_SHOW);   //to show a window or SW_HIDE to hide the window

You will need to somehow keep track yourself of which dialog is to be shown next in response to the button press.

Author

Commented:
Well I had done that and it works fine, but the problem is it flickers. I have almost 10 inner dialogs and if I want show one, I need to hide all of them first and then  show the one as per the flow. Hiding all and showing one is causing the flickering. So fare I have not added the JPG files as the background and this may cause more flickering.

Thanks

Author

Commented:
May be I can reduce the flickering by hiding just the previous dialog. Lets see how it works.
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
You only need to have one dialog visible at once.

Author

Commented:
I was showing only one dialog at a time, but still the flickering was there, because I was using a bitmap to paint the outer dialogs background in OnEraseBkgnd and thats why it used to flicker. Now its ok, I may need to find a different way for the background or I may skin it with JPG.

Thanks
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
OK - sounds like your OnPaint code isn't efficient.  (Getting flicker free behaviour isn't as easy as one thinks it should be.  The real question should be 'is it suitable?' )
Flickering mostly is due to painting a bitmap more than once. If for example you handle the WM_SIZE message the screen (image) already was drawn. A new action invoked in the handler would draw the image again and it flickers.

>>>> But how can I make it like a wizard, so that on
>>>> selecting next and back I can change the inner dialog?

To solve a similar problem, I made a 'button control' which was placed at the bottom of each dialog

 [<-]  [page 1] [page 2] ...  [page n] [->]

(more precisily I made a dialog baseclass for all of my pages which contains the button control). The button control was configurable for each page and could have 'grayed' buttons for pages which currently were not available. The handler function for the buttons would hide the current dialog, check whether the selected page already was one of the hidden pages, if not it would create the dialog and call DoModal, if yes it simply would show the dialog.

Regards, Alex

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.