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!

Child Dialogs in MDI AFC Application

Status
Not open for further replies.

sparafucile17

Programmer
Apr 5, 2002
40
US
Does anyone know a quick and easy way to make a dialog into a child of a MDI? I tried changing the dialog properties to WS_CHILD but it crashes the program whenever the dialog is launched via domodal().

The application I am designing uses the menu bar to launch several dialogs that need to stay "within" the parent app. It also supports document-view architecture for printing reports, but I still need dialogs for some functions.

Any ideas?

Thanks,
Jeff
 
If you are using MFC, then you can use the CFormView class to do this within the document/view model. Easy as pie.

I REALLY hope that helps.
Will
 
Actually, no this doesn't help me.

You are talking about launching a CFormView, not a dialog. I need to make a dialog a child of a parent MDI. I know there is a property called WS_CHILD for dialogs, I just don't know how to use it.

Suggestions?
 
A FormView actually does create a dialog as an MDI child window...try it. But it does not create a MODAL dialog.

"Modality" means that while the dialog is running, the rest of the application does not receive any user input, and waits for the dialog to finish.

Running a modal dialog as a child simply does not make sense. And Windows probably doesn't support it, thus the program crash.

What's wrong with CFormView? You don't even have to make use of the document/view model if you don't want to.

I REALLY hope that helps.
Will
 
The following code creates a dialog box that I have created using the resource editor. Additionally I have used the classwizard to create the class for the dialog derived from CDialog.

First make sure that you include a pointer to the dialog in your program. The definition of the pointer cannot be destroyed before the dialog goes out of scope unless you will crash (much for the same reason that you are experiencing the crash before).

//include the header file for the dialog definition
#include "DlgScope.h"

//define a pointer to an instance of the dialog
CDlgScope m_pScopeRI;

//In you initialization for your program initialize the pointer
m_pScopeRI = NULL;


//When you want to show the dialog, first check to see if the dialog exists.
if(m_pScopeRI == NULL)
{ //does not exist so create it now
m_pScopeRI = new CDlgScope;
m_pScopeRI->Create(IDD_DLG_SCOPE, this);

//change the icon for the dialog box
m_pScopeRI->SetIcon(AfxGetApp()->LoadIcon(IDI_SCOPE), TRUE);

//change the caption for the dialog box
m_pScopeRI->SetWindowText(_T("SCOPE - Real(Input)"));

//set the parent for the dialog as this window
CWnd* xWnd;
xWnd = this;
m_pScopeRI->SetParent(xWnd);

//show the dialog and set focus to it
m_pScopeRI->ShowWindow(SW_SHOW);
m_pScopeRI->SetFocus();
}
else
{ //the dialog already exist
//just show the dialog and set focus to it
m_pScopeRI->ShowWindow(SW_SHOW);
m_pScopeRI->SetFocus();
}


Hopefully these code fragments will point you in the direction you need for your solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top