Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)qq
published in(发表于) 2014/7/9 22:38:41
visual c++ 常用的mfc CRuntimeClass结构

visual c++ 常用的mfc CRuntimeClass结构

visual c++ 常用的mfc CRuntimeClass结构

在许多计算机书籍中,CRuntimeClass被称为类,实际上,CRuntimeClass在MFC中是以结构的方式定义的,虽然它也包含成员函数。这个结构定义在Afx.h中,它包含了使用CRuntimeClass结构的类的有关信息。

CRuntimeClass结构的原型如下:

struct CRuntimeClass

{

LPCSTR m_lpszClassName;

int m_nObjectSize;

UINT m_wSchema; // schema number of the loaded class

CObject* (PASCAL* m_pfnCreateObject)(); // NULL => abstract class

#ifdef _AFXDLL

CRuntimeClass* (PASCAL* m_pfnGetBaseClass)();

#else

CRuntimeClass* m_pBaseClass;

#endif

// Operations

CObject* CreateObject();

BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass) const;

// Implementation

void Store(CArchive& ar) const;

static CRuntimeClass* PASCAL Load(CArchive& ar, UINT* pwSchemaNum);

// CRuntimeClass objects linked together in simple list

CRuntimeClass* m_pNextClass; // linked list of registered classes

};

在CRuntimeClass结构中定义了类名、对象所占存储空间的大小、类的版本号等成员变量及动态创建对象、派生关系判断等成员函数。

CRuntimeClass结构在MFC中有着至关重要的作用,要继承CObject类的功能离不开CRuntimeClass结构,每个从CObject类派生的类都有一个CRuntimeClass结构同它关联,以便完成在运行时得到对象的信息或其基类的信息。

要使用CRuntimeCalss结构,必须结合使用RUNTIME_CLASS()宏和其他有关运行时类型识别的MFC宏。




If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759