Solved

Opening another dialog (closing original)

Posted on 1998-11-20
6
167 Views
Last Modified: 2013-11-20
I would like my dialog-based program to open on the default dialog (IDD_DIALOG1) and then, through a function that's called when a selection is made from a menu, call/open another dialog (in the same project) called IDD_DIALOG2.  If possible I would like for the original dialog window to close at this time.  I'm a beginner so I don't know how complicated or simple this may be.  I'd appreciate any help you can provide.  Thanks a lot.
0
Comment
Question by:jkeebler
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 70 total points
ID: 1325076
Let's say your command handler in the first dialog is:

OnShowDialog2()
{
     CDialog2  dlg;
     int       ret;

     ShowWindow(SW_HIDE);  // Hide this dialog
     ret = dlg.DoModal();  // Show the 2nd dialog
     ShowWindow(SW_SHOW);  // Re-show the 1st dialog
}

One thing is for sure; to keep it simple your first dialog must not close with OnOK or OnCancel because in a simple dialog application this will terminate the application. Now it would only hide itself and show the 2nd dialog. When the 2nd dialog will return from DoModal, ie when it's closed, your 1st dialog will show up.
if you don't want the 1st to re-show then replace ShowWindow(SW_SHOW) by OnOK();

0
 

Author Comment

by:jkeebler
ID: 1325077
Thanks a lot for your quick response to my question :-)  I'll tell your what I did.

I made a new dialog called IDD_DIALOG1, made a new class called CDialog1, and made a button in the main dialog that, when clicked, calls a function containing your script:

         CDialog1 dlg;
         int ret;
         ShowWindow(SW_HIDE);
         ret = dlg.DoModal();
         ShowWindow(SW_SHOW);

When compiled, I got the following errors:

1) CDialog1: undecleared identifier
2) missing ; before identifier dlg
3) dlg: undecleared identifier
4) left of '.DoModal' must have class/struct/union type

Is there a quick step I can follow in ClassWizard to fix this?  A step to define CDialog1 in the main dialog?  Like I said, I'm new at Visual C++ programming and would appreciate any help you can give me.  Thanks again.

0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1325078
do you include header file?


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:jkeebler
ID: 1325079
wyy_cq >> It was included automatically by ClassWizard (I'm pretty sure).  Do I have to make some sort of initializing statement to identify CDialog1 in the main dialog source?
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1325080
The header file was not included by classwizrd. How could it know you want use that dialog in that cpp file.

You need to add an include directive to the top of the cpp file:

#include "dialog1.h"

where dialog1.h is the filename of the new dialog's header file.
0
 

Author Comment

by:jkeebler
ID: 1325081
That was the problem.  Thanks a lot.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now