How Do I Launch a Dialog in MFC?

I'm fairly new to VC++ and MFC, so bear with me. 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).


  • Right click the project and select Add | Resource...
  • Select Dialog under Resource type and click New.
  • Select Project | Add Class...
  • Enter CMyDialog for the Class name, CDialog for the Base class and Click Finish.
  • Read more: How to Make MFC Dialog Boxes


    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..

    链接地址: http://www.djcxy.com/p/39234.html

    上一篇: 多线程和MFC

    下一篇: 如何在MFC中启动对话框?