Handwritten MFC ---- 2 IMPLEMENT

zhaozj2021-02-16  70

Still look at the definition first

#define import_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)

So IMPLEMENT_DYNCREATE (MYDOC, CDocument) is equivalent to

COBJECT * PASCAL MYDOC :: CreateObject () /

{Return New MyDoc;} /

Implement_runtimeclass (MyDoc, cdocument, 0xfff, /

MYDOC :: CreateObject)

What is import_runtimeclass?

#define import_runtimeclass (class_name, base_class_name, wschema, pfnnew) /

AFX_COMDAT constimeclass 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);} /

So IMPLEMENT_DYNCREATE (MYDOC, CDocument) is equivalent to

COBJECT * PASCAL MYDOC :: CreateObject () /

{Return New MyDoc;} /

AFX_COMDAT Const AFX_DATADEF CRUNTIMECLASS MYDOC :: Class ## mydoc = {/

# mildoc, class mydoc, 0xffff, MyDoc :: CreateObject, /

Runtime_class (cdocument), NULL}; /

Cruntimeclass * mydoc :: getruntimeclass () const /

{Return Runtime_class (mydoc);} /

Plus

#define AFX_COMDAT

#define AFX_DATADEF

#define runtime_class (Class_name) (CRUNTIMECLASS *) (& class_name :: class ## class_name))

Above

So IMPLEMENT_DYNCREATE (MYDOC, CDocument) is equivalent to

COBJECT * __STDCALL MYDOC :: CREATEOBJECT () /

{Return New MyDoc;} /

Const cruntimeclass mydoc :: classmydoc = {/

# mildoc, class mydoc, 0xffff, MyDoc :: CreateObject, /

(CruntimeClass *) (& CDocument :: ClasscDocument), NULL}; /

Cruntimeclass * mydoc :: getruntimeclass () const /

{RETURN (CRUNTIMECLASS *) (& mydoc :: class mydoc);} /

转载请注明原文地址:https://www.9cbs.com/read-17051.html

New Post(0)