简体   繁体   English

如何在 MDI 应用程序中将 MFC 无模式对话框更改为 CView 的子项?

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

I have an MFC application that is a Doc/View/Frame implementation.我有一个 MFC 应用程序,它是一个文档/视图/框架实现。 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.我希望将无模式对话框添加到 MDI 子视图中。 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.基本上,我想从资源文件加载模板,并在我添加到 MDI 模板列表的新三重奏 (doc/view/frame) 中将其创建为 CView 的子项。

I've tried a few things in my derived CMyView class:我在派生的 CMyView 类中尝试了一些东西:

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).我试过调用 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.每次调用 Create 时,ListDialog 的 m_hWnd 都保留为 0。这告诉我它没有被正确创建。 Any call to SetWindowPos() or ShowWindow() fails because the m_hWnd is 0 (debug assertion fails).对 SetWindowPos() 或 ShowWindow() 的任何调用都失败,因为 m_hWnd 为 0(调试断言失败)。

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?我需要做什么才能在我的 MDI 应用程序中构造、创建和显示为 CMyView 的子级的无模式对话框?

I don't know.我不知道。 But...但...
You have several alternative choices which could be suitable depending on how your application should looks.根据您的应用程序的外观,您有几种可能适合的替代选择。

1/using CFormView . 1/使用CFormView If your view is dedicated to the dialog then you can derive a view from the MFC class CFormView.如果您的视图专用于对话框,那么您可以从 MFC 类 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. Juste 使用向导创建一个新应用程序,我认为您应该能够选择 CFormView 类作为您的视图类,然后将生成的文件复制到您现有的应用程序中。

2/ Using a CSplitterWnd . 2/ 使用CSplitterWnd One view being a CFormView and the other your current CView.一个视图是 CFormView,另一个是您当前的 CView。

3/ using CDialogBar If your view already displays something, you can add your dialog as a tool bar using the class CDialogBar. 3/ 使用CDialogBar如果你的视图已经显示了一些东西,你可以使用类 CDialogBar 添加你的对话框作为工具栏。

this is working in my MDI app...这在我的 MDI 应用程序中有效...

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM