创建一个从CDialog派生的类 [英] Creating a class derived from CDialog
本文介绍了创建一个从CDialog派生的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我正在创建一个从CDialog派生的类,假设该类名称为"CBase".
我希望它充当MFC的CDialog,并且从基类派生的任何类都将创建一个对话框.我该怎么办?
我尝试过休假
dear,
I''m creating a class derived from CDialog, suppose that class name it is ''CBase''.
I want it acting as CDialog of MFC and any class derived from base create one dialog box. What can I do for it?
I tried out as fallows
CBase : public Cdialog
{
CBase(CWnd* pParent = NULL); // standard constructor
//{{AFX_DATA(CTestDlgBase)
enum { IDD = _UNKNOWN_RESOURCE_ID_ };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV protected:
DECLARE_MESSAGE_MAP()
}
Cderive : public CBase
{
Cderive(CWnd* pParent = NULL);
//{{AFX_DATA(CTestDlgBase)
enum { IDD = _UNKNOWN_RESOURCE_ID_ };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV protected:
DECLARE_MESSAGE_MAP()
}
但由于休假而出现错误
错误C2065:"_ UNKNOWN_RESOURCE_ID_":未声明的标识符
错误C2057:期望的常量表达式
当我创建类CBase&的对象时调用DoModal时,对话框未显示.
我该怎么办?
but I got error as fallows
error C2065: ''_UNKNOWN_RESOURCE_ID_'' : undeclared identifier
error C2057: expected constant expression
also when I create object of class CBase & calling DoModal the dialog isn''t shown.
What can I do for it?
推荐答案
您必须删除代码枚举{IDD = _UNKNOWN_RESOURCE_ID_};"
并更改构造函数,例如"CBase(UINT nIDD,CWnd * pParent = NULL);//标准构造函数"
自己输入的对话框ID!
you must delete the code of "enum { IDD = _UNKNOWN_RESOURCE_ID_ };"
and change the constructor like "CBase(UINT nIDD ,CWnd* pParent = NULL); // standard constructor"
the dialog id put in by youself !
作为对Glen响应的增强,中间类CBase不了解所使用的对话框ID.除非您创建一个您知道的对话框实例.因此,id必须是CBase中的参数/变量.
根据您实现Cderive类的方式,它可以使用enum构造,或者也必须对id使用参数/变量.
As an enhancement to Glen''s response, the intermediate class CBase has no knowledge of the dialog id used. It''s not until you create a dialog instance you do know. Hence, the id must be an argument/variable in CBase.
Depending on how you implement your Cderive class, it can use the enum construct or it too has to use an argument/variable for the id.
如果_UNKNOWN_RESOURCE_ID_是对话框资源,那么.
只需在文件中#include resource.h.
if _UNKNOWN_RESOURCE_ID_ is the dialog resource then .
just #include resource.h in your file.
这篇关于创建一个从CDialog派生的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文