在模态窗口中如何打开非模态窗口 您所在的位置:网站首页 mfc如何创建对话框 在模态窗口中如何打开非模态窗口

在模态窗口中如何打开非模态窗口

2023-03-29 22:13| 来源: 网络整理| 查看: 265

你好,

根据你的描述,我进行了重现并正常显示了非模态对话框。

重现过程具体如下:

首先,新建一个基于对话框的MFC程序,默认情况下,主对话框就是以模态方式显示的(具体可见以下初始化代码);

然后,为了测试,我插入了两个对话框。

插入一个对话框IDD_DIALOG1,并创建一个对话框类MyDialog1;

插入一个对话框IDD_DIALOG2,并创建一个对话框类ADDialog ;

最后,在主对话框中添加了两个按钮并添加相应的按钮响应事件;

具体代码片段请见以下:

BOOL CMFCApplication1App::InitInstance() { ... CMFCApplication1Dlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n"); TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n"); } .. . } void CMFCApplication1Dlg::OnBnClickedButton2() { // TODO: Add your control notification handler code here MyDialog1 *dlgAD=new MyDialog1(); dlgAD->Create(IDD_DIALOG1,this); dlgAD->ShowWindow(SW_SHOW); ////////////////////////////////////// } void CMFCApplication1Dlg::OnBnClickedButton3() { // TODO: Add your control notification handler code here ADDialog *dlgAD=new ADDialog(); dlgAD->Create(IDD_DIALOG2,this); dlgAD->ShowWindow(SW_SHOW); }

运行结果:

希望对你有帮助!

;THE CONTENT IS PROVIDED ;AS IS; WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED; Thanks We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey. MSDN Community Support Please remember to ;Mark as Answer; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有