Steps to create Model dialog box:
a) Create a dialog box using
the resource editor.
b) Derive a class, say
mydialog, from the CDialog class
c) Create an object of
mydialog class and while doing so pass the resource ID of the dialog box to the
constructor.
d) Call the
CDialog::DoModal()function to display the dialog box.
Ex:
#include
"afxwin.h"
#include
"resource.h"
classmydialog:publicCDialog
{
public:mydialog(int
n):CDialog(n){}
};
classMyFrame:publicCFrameWnd
{
CButton b;
public:MyFrame()
{
Create(NULL,"Simple Window");
}
intOnCreate()
{
b.Create("Display
Dialog",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,CRect(200,100,350,150),this,1);
return 0;
}
void display()
{
mydialog d(IDD_DIALOG1);
d.DoModal();
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(1,display)
END_MESSAGE_MAP()
classMyMain:publicCWinApp
{
public:intInitInstance()
{
MyFrame *f=new MyFrame();
f->ShowWindow(1);
m_pMainWnd=f;
return 1;
}
};
MyMain m;
Steps to create Modeless dialog box:
a) Create a dialog box using
the resource editor.
b) Derive a class, say
mydialog, from the CDialog class
c) Create an object of
mydialog class.
d) Call the
CDialog::Create()function to display the dialog box while calling the function
pass the resource ID of the dialog box to the function along with this pointer.
Ex:
#include
"afxwin.h"
#include
"resource.h"
classmydialog:publicCDialog
{
public:mydialog(){}
};
classMyFrame:publicCFrameWnd
{
mydialog *dl;
CButton b;
public:MyFrame()
{
Create(NULL,"Simple Window");
dl=NULL;
}
intOnCreate()
{
b.Create("Display
Dialog",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,CRect(200,100,350,150),this,1);
return 0;
}
void display()
{
if(dl==NULL)
{
dl=new mydialog();
dl->Create(IDD_DIALOG1,this);
}
}
DECLARE_MESSAGE_MAP()
};
No comments:
Write comments