通常情况,我们想编写一个自己的对话框类,这个对话框类可以有自己的消息和各种属性,这样其他对话框通过继承,就直接有了相应的属性和消息,消息的内容就无需再写一遍了;
一:编写自己的对话框:
1:最简单的方式,用向导生成一个继承与CDialog的类(如:setDlg),这个类没有关联任何资源;
2:删除 setDlg 类头文件中的这句话:enum { IDD = _UNKNOWN_RESOURCE_ID_ };
3:增加或修改构造函数:
setDlg(CWnd* pParent = NULL); //.h文件;
setDlg::setDlg(CWnd* pParent /*=NULL*/) //.cpp文件;
: CDialog(setDlg::IDD, pParent)/**/
{
//{{AFX_DATA_INIT(setDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
删除或改为:
setDlg( UINT nIDTemplate, CWnd* pParentWnd ); //.h文件;
setDlg::setDlg( UINT nIDTemplate, CWnd* pParentWnd )//(CWnd* pParent /*=NULL*/)//2 .cpp文件;
: CDialog(nIDTemplate,pParentWnd)//(setDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(setDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
4:添加自己的消息和相应的成员变量和成员方法;
二:继承自定义对话框:
1:我们创建了一个对话框类(如:MainDlg)已经关联了相应的资源;
2:将 MainDlg 的继承从 CDialog 改为 setDlg; //.h文件;
3:修改构造函数实现中的 CDialog 为setDlg;//.cpp文件;
4:修改BEGIN_MESSAGE_MAP 中的CDialog 为setDlg;//.cpp文件;
这样就基本ok了,但是还有相关的 CDialog,如果需要,应该全部改为setDlg;//.cpp文件;