MFC Bring up a dialog.

This is a discussion on MFC Bring up a dialog. within the Windows Programming forums, part of the Platform Specific Boards category; Hello,
I already have a basic MFC Application created (with the default dialog and the about box, and another one ...

MFC Bring up a dialog.

Hello,

I already have a basic MFC Application created (with the default dialog and the about box, and another one I made called IDC_DIALOG1) using the standard MFC library. My question is how do I make a dialog pop up?

Basic steps;
1. Create a class based on the dialog.
How you do this depends on the version of MSVC you are using.
Try double clicking on the dialog in the resource viewer.

2. Include the header file for the new dialog's class in the main dialog.

3. Create instance of dlg class (a variable)

4. Call DoModal()

Code:

//create a class CMyDlg from IDD_DIALOG1
//include the class in the parent dialog
#include "MyDlg.h"
//in the method you want the dialog to appear
//create the dialog class
CMyDlg MyDlg;
//create modal,
//does not return from the dialog until the dialog is closed
int iReturn=0;
//catch the button the user clicked to close the dialog
iReturn = MyDlg.DoModal();
//now the IDD_DIALOG1 code will run,
//until the user finishes and closes the dialog
//what did the user do
if(iReturn == IDOK)//user clicked the OK button
{
//do stuff
{
else if (iReturn == IDCANCEL)//user canceled the dlg
{

Post if you need a modeless dlg, which runs at the same time as your app.