友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!
深入浅出MFC第2版(PDF格式)-第72部分
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部! 如果本书没有阅读完,想下次继续接着阅读,可使用上方 "收藏到我的浏览器" 功能 和 "加入书签" 功能!
class CDynobj : public CObject
。CPP { 計
static AFX_DATA CRuntimeClass classCDynobj;
virtual CRuntimeClass* GetRuntimeClass () const;
IMPLEMENT_DYNCREATE (CDynobj; CObject)
static CObject* PASCAL CreateObject();
。。。
}
#define IMPLEMENT_DYNCREATE (class_name; base_class_name)
#define IMPLEMENT_DYNCREATE (class_name; base_class_name)
CObject* PASCAL class_name::CreateObject()
CObject* PASCAL class_name::CreateObject()
{ return new class_name; }
AFX。H
{ return new class_name; }
_IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; 0xFFFF;
_IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; 0xFFFF;
class_name::CreateObject)
class_name::CreateObject)
CDynobj::classCDynobj CObject* PASCAL CDynobj::CreateObject()
“CDynobj” { return new CDynobj; }
sizeof(CDynobj) AFX_DATADEF CRuntimeClass CDynobj::classCDynobj = {
“CDynobj”; sizeof(CDynobj); 0xFFFF; CDynobj::CreateObject;
0xFFFF &CObject::classCObject; NULL };
m_pfnCreateObject CDynobj::CreateObject static const AFX_CLASSINIT _init_CDynobj(&CDynobj::classCDynobj);
CRuntimeClass* CDynobj::GetRuntimeClass() const
m_pBaseClass CObject::classCObject { return &CDynobj::classCDynobj; }
m_pNextClass NULL
圖8…7b DECLARE_DYNCREATE / IMPLEMENT_DYNCREATE
…………………………………………………………Page 587……………………………………………………………
。H
#define DECLARE_SERIAL (class_name) AFX。H
class CDynobj : public CObject #define DECLARE_SERIAL (class_name)
DECLARE_DYNCREATE(class_name)
{ DECLARE_DYNCREATE(class_name)
friend CArchive& AFXAPI operator》》(CArchive& ar; class_name* &pOb);
DECLARE_SERIAL (CDynobj) friend CArchive& AFXAPI operator》》(CArchive& ar; class_name* &pOb);
。。。
}
class CDynobj : public CObject
{
static AFX_DATA CRuntimeClass classCDynobj;
。CPP
virtual CRuntimeClass* GetRuntimeClass () const;
static CObject* PASCAL CreateObject();
(CDynobj; CObject; )
IMPLEMENT_SERIAL 1 friend CArchive& AFXAPI operator》》 (CArchive& ar; CDynobj* &pOb);
。。。
}
#define IMPLEMENT_SERIAL (class_name; base_class_name; wSchema)
#define IMPLEMENT_SERIAL (class_name; base_class_name; wSchema) AFX。H
CObject* PASCAL class_name::CreateObject()
CObject* PASCAL class_name::CreateObject()
{ return new class_name; }
{ return new class_name; }
_IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; wSchema;
_IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; wSchema;
class_name::CreateObject)
class_name::CreateObject)
CArchive& AFXAPI operator》》(CArchive& ar; class_name* &pOb)
CArchive& AFXAPI operator》》(CArchive& ar; class_name* &pOb)
{ pOb = (class_name*) ar。ReadObject(RUNTIME_CLASS(class_name));
{ pOb = (class_name*) ar。ReadObject(RUNTIME_CLASS(class_name));
return ar; }
return ar; } 第
8
章
D
CDynobj::classCDynobj o
CObject* PASCAL CDynobj::CreateObject() c
“CDynobj” u
{ return new CDynobj; } m
e
AFX_DATADEF CRuntimeClass CDynobj::classCDynobj = { n
sizeof(CDynobj) t
“CDynobj”; sizeof(CDynobj); ; CDynobj::CreateObject; V
1
i
1 e
w
&CObject::classCObject; NULL };
static const _init_CDynobj(&CDynobj::classCDynobj);
深
m_pfnCreateObject CDynobj::CreateObject AFX_CLASSINIT
入
CRuntimeClass* CDynobj::GetRuntimeClass() const
m_pBaseClass CObject::classCObject { return &CDynobj::classCDynobj; } 探
CArchive& AFXAPI operator》》 (CArchive& ar; CDynobj* &pOb) 討
m_pNextClass NULL { pOb = (CDynobj*)ar。ReadObject(&CDynobj::classCDynobj);
return ar; }
5
2
5 圖8…7c DECLARE_SERIAL / IMPLEMENT_SERIAL
…………………………………………………………Page 588……………………………………………………………
第篇 深入 MFC 程式設計
DYNAMIC / DYNCREATE / SERIAL 三套宏分别在CRuntimeClass 所组成的「类别型录
网」中填写不同的记录,使MFC 类别(以及你自己的类别)分别具备三个等级的性能:
基础机能以及对象诊断(可利用afxDump 输出诊断消息),以及Run Time Type
Information (RTTI )。也有人把RTTI 称为Run Time Class Information (RTCI )。
动态生成(Dynamic Creation )
文件读写(Serialization)
你的类别究竟拥有什么等级的性能,得视其所使用的宏而定。三组宏分别实现不同
等级的功能,如图8…8 。
功能 RTTI Dynamic Creation Serialize
CObject::IsKindOf CRuntimeClass::CreateObject CArchive::operator》》
宏
CArchive::operator
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!