CSDN博客

img zhoujiamurong

手写MFC---- 第二节 IMPLEMENT_DYNCREATE (mydoc,CDocument)

发表于2004/7/11 21:41:00  3278人阅读

还是先看定义

#define IMPLEMENT_DYNCREATE(class_name, base_class_name) /

         CObject* PASCAL class_name::CreateObject() /

                  { return new class_name; } /

         IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, /

                  class_name::CreateObject)

那么IMPLEMENT_DYNCREATE (mydoc,Cdocument)等同于

CObject* PASCAL mydoc::CreateObject() /

                  { return new mydoc; } /

         IMPLEMENT_RUNTIMECLASS(mydoc, Cdocument, 0xFFFF, /

                  mydoc::CreateObject)

 

IMPLEMENT_RUNTIMECLASS又是什么东东呢?

#define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) /

         AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = { /

                  #class_name, sizeof(class class_name), wSchema, pfnNew, /

                            RUNTIME_CLASS(base_class_name), NULL }; /

         CRuntimeClass* class_name::GetRuntimeClass() const /

                  { return RUNTIME_CLASS(class_name); } /

 

那么IMPLEMENT_DYNCREATE (mydoc,CDocument)等同于

CObject* PASCAL mydoc::CreateObject() /

                  { return new mydoc; } /

AFX_COMDAT const AFX_DATADEF CRuntimeClass mydoc::class##mydoc = { /

                  #mydoc, sizeof(class mydoc), 0xFFFF, mydoc::CreateObject, /

                            RUNTIME_CLASS(CDocument), NULL }; /

         CRuntimeClass* mydoc::GetRuntimeClass() const /

                  { return RUNTIME_CLASS(mydoc); } /

加上

#define AFX_COMDAT

#define AFX_DATADEF

#define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))

上面

 

 

那么IMPLEMENT_DYNCREATE (mydoc,CDocument)等同于

CObject* __stdcall mydoc::CreateObject() /

                  { return new mydoc; } /

const  CRuntimeClass mydoc::classmydoc = { /

                  #mydoc, sizeof(class mydoc), 0xFFFF, mydoc::CreateObject, /

                            (CRuntimeClass*)(& CDocument::classCDocument), NULL }; /

         CRuntimeClass* mydoc::GetRuntimeClass() const /

                  { return ((CRuntimeClass*)(& mydoc::class mydoc)); } /

好像还是不很明白,是吗?先看下一章吧

0 0

相关博文

我的热门文章

img
取 消
img