开发者

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

开发者 https://www.devze.com 2022-12-25 06:24 出处:网络
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

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 gett开发者_开发百科ing 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?


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.


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消