简体   繁体   中英

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

  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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM