如何显示非模态CDialog?
有人可以告诉我如何在 MFC 的 Visual c++ 6.0 中创建非模态对话框并显示它吗? 我写了这段代码:
CDialog dialog;
if (dialog.init(initialization values...))
dialog.DoModal();
但它阻止我的应用程序显示对话框。我不知道是否有任何方法或其他方式可以做到这一点。
谢谢
Can someone tell me how I could create a Non Modal Dialog in MFC's Visual c++ 6.0 and show it?
I wrote this code:
CDialog dialog;
if (dialog.init(initialization values...))
dialog.DoModal();
But it blocks my application from showing the dialog. I dont know if there exists any method or other way to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用CDialog::Create,然后使用CDialog::ShowWindow。您现在有一个非模式对话框。
Use CDialog::Create and then use CDialog::ShowWindow. You now have a modeless dialog box.
您可以调用
CDialog::Create< /code>
和
CWnd::ShowWindow
就像其他人建议的那样。另外,请记住,如果对话框存储在局部变量中,则对话框将在创建后立即被销毁。
You can call
CDialog::Create
andCWnd::ShowWindow
like the others have suggested.Also, keep in mind your dialog will be destroyed right after its creation if it is stored in a local variable.
在这种情况下,我发现让它自我删除来处理清理是最方便的。
通常,从类内部释放“隐式”内存,而不是通过创建它的内容来释放“隐式”内存,通常被认为是不好的形式,但我通常对非模式对话框进行例外处理。
那是;
调用代码:
对话代码:
In this case I find it most convenient to let it self-delete itself to handle the cleanup.
Often it's considered bad form to make "implicit" memory freeing from within a class, and not by what it created it, but I usually make exceptions for modeless dialog boxes.
That is;
Calling code:
Dialog code:
您需要改为调用
CDialog::Create
。完成对话框后,您需要调用DestroyWindow
。您可能还需要将对话框消息传递到对象上,但我不记得 MFC 是否为您处理这个问题。You need to call
CDialog::Create
instead. You will need to callDestroyWindow
when you are finished with the dialog. You might also need to pass dialog messages onto the object but I can't remember if MFC handles this for you or not.DoModal 正在阻塞。您必须在堆上创建对话框或使其成为您的类的成员(这很重要),调用 Create 然后调用 ShowWindow。
DoModal is blocking. You have to create your dialog on the heap or make it a member of your class (this is important), call Create then call ShowWindow.