How to Change an MFC Modeless Dialog to be the child of a CView in an MDI application?

Posted by Kieveli on Stack Overflow See other posts from Stack Overflow or by Kieveli
Published on 2010-03-30T13:27:37Z Indexed on 2010/03/31 9:53 UTC
Read the original article Hit count: 313

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about mfc

Related posts about mdi