MFC中CDialog的DoModal()函数的问题 [英] question on DoModal() function of CDialog in MFC

查看:399
本文介绍了MFC中CDialog的DoModal()函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关此技术问题的帮助:
我有一个对话框.

I need help on this technical issue:
I have one Dialog.

CMyDialog::CDialog ()
{
///// class members
CFirstDialog m_firstdialog ; // derived from CDialog

CSecondDialog m_seconddialog;
}







CMyDialog::OnButtonClick( ) { m_firstdialog .DoModal (); } CMyDialog::OnDisplay() { int return_val = m_seconddialog.DoModal(); AfxMessageBox("OnDisplay"); } 



在按钮上单击它会调用CMyDialog::OnButtonClick( ),并且对话框m_firstdialog .DoModal ()变为模式对话框.控件停留在该对话框上以供用户操作,并且该对话框没有任何输入,它保持打开状态.同时,同一应用程序中的另一个线程调用CMyDialog::OnDisplay(),然后控制该函数的传输,并显示第二个对话框m_seconddialog.DoModal().我在此对话框上单击确定",它关闭.执行完此步骤后,仍然打开的m_firstdialog 对话框变为无模式对话框",它将失去其Modal属性,并且控件再也不会返回到m_firstdialog 了.这是我的问题,我该如何使m_firstdialog =>一个模态对话框,当显示第二个模态对话框m_seconddialog 时为什么会变成模型?

问候,
在此先感谢Martin



On button click it calls CMyDialog::OnButtonClick( ) and dialog m_firstdialog .DoModal () becomes a modal dialog. The control stays there for user action on this dialog and I have not given any input to this Dialog and it remains open. At the same time another thread in the same application calls CMyDialog::OnDisplay() then control transfer to this function and it displays second dialog m_seconddialog.DoModal() . I click OK on this dialog and it closes. After this steps of execution m_firstdialog dialog which is still open becomes Modeless Dialog it looses its Modal property and control never goes back to m_firstdialog . Here my question is, how can I make m_firstdialog => a Modal Dialog and why it becomes Modelss when second modal dialog m_seconddialog is displayed?

Regards,
Thanks in advance, Martin

推荐答案

要退出模态循环,您只需发送WM_QUIT消息即可.

但我想您应该重新考虑您的设计:
带有两个子对话框的对话框应看到两个无模式的子级,可能会通知其父级,该子级应包含OK/Cancel命令.

没有理由使用更多线程(用户总是会同时对一个控件起作用!)没有理由指导"用户.

在这种情况下,您需要引导"用户,想到一种向导"方法:将一个父级作为后退/下一步"按钮,以及一个数量众多的无模式子级,一次可以看到一个子级.
To exit a modal-loop you can simply send a WM_QUIT message.

But I thing you should reconsider your design:
A dialog with two sub-dialogs should see two mode-less children, possibly notifying the parent, that should be the one that contains the OK/Cancel commands.

There are no reason to use more threads (the user will always act to one control at time!) as no reason to "guide" the user.

In the case you have instead need to "guide" the user, think to a "Wizard" approach: a parent as Back/Next buttons, and a umber of mode-less children, visible one at time.


这篇关于MFC中CDialog的DoModal()函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆