Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a dialog from another dialog

Status
Not open for further replies.

byurow

Programmer
Jul 7, 2002
111
US
Is it possible to close a dialog from another dialog? I am VERY new to C++ (and programming!) so I am sorry if this is a simple question! What I am trying to do, is based on the results of a query, give the user the option to go back to the screen and make a change (click the OK - this works fine) or close out altogether and go back to the main menu without having to close two dialog boxes.

Hope this makes sense! Thanks in advance.
 
What about closing all dialogs in a row ?

For instance:
//Current dialog code
if(condtion1)
m_iCloseOption = icCloseAllDialogs;
else if(condition2)
m_iCloseOption = icCloseSingleDialog;
else
m_iCloseOption = icNoClose;

if(m_iCloseOption == icCloseSingleDialog)
/* Here code to close current dialog and make previous dialog active */

//Second dialog code(after first dialog has closed)
if(dialog1.m_iCloseOption == icCloseAllDialogs)
/* Here code to close second dialog and go to main menu */
 
Not quite what I was looking for but definetly on the right track. I don't want to close all dialogs, just 2 (I have 3 open). I think what I may need to do is call the close function from the 3rd dialog to the 2nd dialog. I know how to do this in VB, but not C++

Any other suggestions?

I appreciate the response!

Brenda
 
Brenda , the same thing happened to me. I used to try C/C++, then switched to Visual Basic three years ago and now I'm in process of restoring my knowledges/skills of C++.
Maybe I should study C# since it's the most advanced and
newest language/environment but who knows ...

About your example: if you need some help, please let me know.
 
OK, I am getting close now. I can now close both dialog boxes from one dialog box (I entered the OnOK code on the DoModal code from dialog box 1, then in dialog box 2, on the OnOK both boxes close.

Now what I am trying to do is only close both boxes IF the user wants to. The user may decide to go back to Dialog box 1 to make some changes. So, now I have a Cancel button and an Close button. On the Close button, I want both Dialog box 1 and Dialog box 2 to close - no problem, that now works. However, for the Cancel button I want to close Dialog box 2 but keep dialog box 1 open.

I know that I need to create a global variable to use in both dialog boxes. I don't seem to be able to do that. Where do I put the code to create a global variable to be used in both dialog boxes, or can I fully qualify the code to use the variable in both boxes? (example: if Dialog1.global == 0 OnOK(); I keep getting all kinds of errors.

Any suggestions???????

Thanks

Brenda
 
Ok. Correct me if I'm wrong.
What about adding new public member in first dialog class(for example, m_iDialogCloseOption) ?
You initialize it in the handler of button(Close and Cancel) click and check in the second dialog(onOK handler).
 
Ok. Correct me if I'm wrong.
There's one modal dialog(Dialog1) that displays second modal dialog(Dialog2). And you wanna close Dialog1 leaving Dialog2 visible and modal. As for me it's impossible and may lead to system crash ...
 
On your second post, you got it backwards. I want to close dialog box 2 but leave dialog box 1 open.

As to your first post, that's exactly what I had done. I am obviously doing it wrong. How about if I tell you exactly what I did, maybe that will help clear up any confusion.

On Dialog1.h I added the following code:

class CDialog1Dlg : public CDialog
public:
int m_iDialogCloseOption();

then in Dialog2.cpp I added the following code:

#include "Dialog1.h"

void CDialog2Dlg::OnOK()
{
// TODO: Add extra validation here
m_iDialogCloseOption = 0;
CDialog::OnOK();
}

void CDialog2Dlg::OnButtonCancel()
{
// TODO: Add your control notification handler code here
m_iDialogCloseOption = 1;
CDialog::OnOK();

}

Then finally in Dialog1.cpp I added the following code:

int CDialog1Dlg::Recognition()
{
Dialog2Dlg.DoModal();
if (m_iDialogCloseOption == 0)
{
OnOK();
}
}

Any advice????????????? I get the following error when I run the code:

Dialog2Dlg.cpp
C:\Folder1\file1\Dialog2.cpp(64) : error C2065: 'm_iDialogCloseOption' : undeclared identifier

Where on earth am I going wrong????? I am sooooo confused!

I appreciate all the help you given me!!!!!!!

Brenda
 
That' all right! Don't be frightened!:) VC compiler can't help informing you about all errors even if these're small errors :)

About your example: you should move(just my opinion) m_iDialogCloseOption declaration from CDialog1Dlg to CDialog2Dlg class and Recognition function:

int CDialog1Dlg::Recognition()
{
Dialog2Dlg.DoModal();
if (Dialog2Dlg.m_iDialogCloseOption == 0)
{
OnOK();
}
}

 
Hey Strannik,
Sorry for the delay in getting back to you. Well, the whole problem was that instead of having OnCancel on the Cancel button, I had OnOK. So I had OnOK twice! Ooops! So my code was working all along, only it kept getting reset back to 0 because it was hitting the 2nd OnOK. Ah the power of Debug!

Thanks for all of your help! As I get further into this application, I am sure you will be hearing from me again!

Thanks again!

Brenda
 
That's OK. I enjoy helping you to avoid the errors I've made while studying.
By the way, where are you from ??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top