简体   繁体   English

如何在MFC中启动对话框?

[英]How Do I Launch a Dialog in MFC?

I'm fairly new to VC++ and MFC, so bear with me. 我刚接触VC ++和MFC,请多多包涵。 I have created a new dialog, and I want to figure out how to display it when the user clicks a button. 我创建了一个新对话框,我想弄清楚当用户单击按钮时如何显示它。

I have not create a class or header file for the dialog -- I tried using the class wizard, but it pretty much sucked and didn't work. 我尚未为对话框创建类或头文件-我尝试使用类向导,但是它很烂,无法正常工作。 That, or I was doing something wrong. 那,或者我做错了什么。 Either one is equally as likely if you ask me. 如果您问我,任何一种可能性都一样。

So what steps do I need to take when creating the source/header files and getting the dialog to launch/display? 那么,在创建源/头文件并使对话框启动/显示时,我需要采取什么步骤? It is a modal dialog. 这是一个模式对话框。

CLARIFICATION: I understand that I need to create an instance of the dialog class, then just call DoModal() on it, but I'm not sure how to create the class file (with and/or without the wizard). 澄清:我知道我需要创建一个对话框类的实例,然后在其上调用DoModal(),但是我不确定如何创建类文件(使用和/或不使用向导)。

  1. Right click the project and select Add | 右键单击该项目,然后选择添加|。 Resource... 资源...
  2. Select Dialog under Resource type and click New. 选择资源类型下的对话框,然后单击新建。
  3. Select Project | 选择项目| Add Class... 添加课程...
  4. Enter CMyDialog for the Class name, CDialog for the Base class and Click Finish. 输入CMyDialog作为类名, CDialog作为基类,然后单击Finish。

Read more: How to Make MFC Dialog Boxes 阅读更多: 如何制作MFC对话框

Seems to me you can make the button click just create a new instance of the dialog object and activate it. 在我看来,您可以使按钮单击,仅创建对话框对象的新实例并激活它。 You'll probably have to keep a reference to the dialog so it doesn't get killed when the button action fxn returns it doesn't get garbage collected.. 您可能必须保留对对话框的引用,以便当按钮操作fxn返回时,它不会被杀死,而不会被杀死。

暂无
暂无

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

相关问题 创建MFC对话框成员后如何对其进行修改? - How do I modify a MFC dialog member after it is created? 在MFC中拖动子对话框时如何移动父对话框? - How do i move parent dialog when dragging child dialog, in MFC? 如何在另一个线程中关闭MFC Modal对话框并获得对话框的返回值? - How do I close a MFC Modal Dialog in another thread and can get the dialog return value? 如何在我的 mfc 应用程序的 non-dialog.cpp 中使用 SetTimer? - How do I use SetTimer in non-dialog .cpp in my mfc app? 如何从 dialog.cpp 访问在.cpp 中创建的对象,反之亦然 mfc? - How do i access objects created in .cpp from the dialog.cpp and vice verse in mfc? 如何使用CPropertyPage :: OnOk()阻止我的MFC对话框窗口关闭? - How do I prevent my MFC dialog's window from closing using CPropertyPage::OnOk()? 在MFC中,如何避免对话框停留在应用程序窗口顶部? - In MFC how do I avoid dialog boxes from staying on top of my app window? C ++ MFC对话框-如何将连接应用于应用程序的所有对话框? - C++ MFC Dialog - How do I apply a connection to all the dialogs of my application? 如何获得Visual Studio 2008为MFC对话框资源创建类? - How do i get visual studio 2008 to create a class for my MFC dialog resource? 如何修复OnRButtonDown()以检测对话框的右键单击? (使用MFC) - How do I fix my OnRButtonDown() to detect right click for my dialog? (using mfc)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM