Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)qqpublished in(发表于) 2014/7/9 22:38:41 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 classCObject* (PASCAL* m_pfnCreateObject)(); // NULL => abstract class#ifdef _AFXDLLCRuntimeClass* (PASCAL* m_pfnGetBaseClass)();#elseCRuntimeClass* m_pBaseClass;#endif// OperationsCObject* CreateObject();BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass) const;// Implementationvoid Store(CArchive& ar) const;static CRuntimeClass* PASCAL Load(CArchive& ar, UINT* pwSchemaNum);// CRuntimeClass objects linked together in simple listCRuntimeClass* m_pNextClass; // linked list of registered classes};在CRuntimeClass结构中定义了类名、对象所占存储空间的大小、类的版本号等成员变量及动态创建对象、派生关系判断等成员函数。CRuntimeClass结构在MFC中有着至关重要的作用,要继承CObject类的功能离不开CRuntimeClass结构,每个从CObject类派生的类都有一个CRuntimeClass结构同它关联,以便完成在运行时得到对象的信息或其基类的信息。要使用CRuntimeCalss结构,必须结合使用RUNTIME_CLASS()宏和其他有关运行时类型识别的MFC宏。
赞