Tuesday, March 06, 2007

How to Create a Dialog and Use it in MFC

Every dialog is derived from CDialog in MFC.

we have to create the dialog in Resource Editor by Inserting a New dialog...

Next Add new header file....

IDD_DIALOG1 is the name of the new Dialog...

"CDlg.h" file contents :
-------------------------

#include
#define IDD_DIALOG1 101

class CDlg:public CDialog
{
public:
CDlg();
enum { IDD = IDD_DIALOG1 };

protected: virtual void DoDataExchange(CDataExchange* pDX);

protected: DECLARE_MESSAGE_MAP()

};

CDlg::CDlg():CDialog(CDlg::IDD){ }

void CDlg::DoDataExchange(CDataExchange* pDX)
{

CDialog::DoDataExchange(pDX);
BEGIN_MESSAGE_MAP(CDlg, CDialog)
END_MESSAGE_MAP()
}



if we want to display this dialog box while clicking the Left Button down means


#include "CDlg.h"

OnLButtonDown()
{

CDlg dlg;
dlg.DoModal();
}

No comments: