tags:

views:

401

answers:

2

I have an MFC application that is a Doc/View/Frame implementation. One dialog is running as a modeless dialog which pops up on demand (from a menu option). I'm looking to add the modeless dialog to an MDI child view. Basically, I want to load the template from the resource file, and create it as a child of the CView in my new trio (doc/view/frame) that I am adding to the template lists for the MDI.

I've tried a few things in my derived CMyView class:

void CMyView::OnInitialUpdate()
{
  m_ListDialog = new Dialogs::CListDialog( m_config, this );
  m_ListDialog->Create( Dialogs::CListDialog::IDD, this );
  m_ListDialog->ShowWindow( SW_SHOW );
}

I've tried calling SetWindowPos, ModifyStyle (WS_CHILD, WS_VISIBLE, DS_CONTROL). I've tried modifying the resource file to set the child and control manually.

Everytime it calls Create, the ListDialog's m_hWnd is left as 0. This tells me it's not getting created properly. Any call to SetWindowPos() or ShowWindow() fails because the m_hWnd is 0 (debug assertion fails).

What do I need to do to get a modeless dialog to be constructed, created, and appear as a child to CMyView in my MDI application?

+1  A: 

I don't know. But...
You have several alternative choices which could be suitable depending on how your application should looks.

1/using CFormView. If your view is dedicated to the dialog then you can derive a view from the MFC class CFormView. The purpose of this view is to display a dialog.

Juste create a new application using the wizard and I think you should be able to choose the CFormView class as your view class, then copy the generated file into your existaing application.

2/ Using a CSplitterWnd. One view being a CFormView and the other your current CView.

3/ using CDialogBar If your view already displays something, you can add your dialog as a tool bar using the class CDialogBar.

FenchKiss Dev
Used the CFormView instead of CDialog. After investigations, it may have been a 'Custom Control' that was preventing it from working.
Kieveli
+1  A: 

this is working in my MDI app...

void CGUIView::OnInitialUpdate() { CView::OnInitialUpdate();

p_Dlg = new CTestDlg;   // a CDialog derived class
p_Dlg->Create(IDD_DIALOG1,this);
p_Dlg->ShowWindow(SW_SHOW);

}

Nijenhuis
This did work in a test application, but only when I modified the Dialog in the resource editor to change the Style property to 'Child' and not 'Popup'.
Kieveli