CRuntimeClass is a structure to hold the runtime type, name, parent class and methods to indentify class information and dynamic creation function.
MFC base class CObject holds CRuntimeClass and thus each class derived from CObject is associated with a CRuntimeClass structure that
you can use to obtain information about an object or its base class at run time.
Here are CRuntimeClass methods and member variables.
|CreateObject||Creates an object during run time.|
|FromName||Creates an object during run time using the familiar class name.|
|IsDerivedFrom||Determines if the class is derived from the specified class.|
|m_lpszClassName||The name of the class.|
|m_nObjectSize||The size of the object in bytes.|
|m_pBaseClass||A pointer to the CRuntimeClass structure of the base class.|
|m_pfnCreateObject||A pointer to the function that dynamically creates the object.|
|m_pfnGetBaseClass||Returns the CRuntimeClass structure (only available when dynamically linked).|
|m_wSchem||The schema number of the class.|
class CMyClass : public CWnd
CRuntimeClass* pClass = RUNTIME_CLASS(CMyClass);
CObject* pObject = pClass->m_pfnCreateObject();
CObject* pObject = pClass->CreateObject();
CRuntimeClass* pClass = CRuntimeClass::FromName(_T("CMyClass"));
if (pClass == NULL)
// not found, display a warning for diagnostic purposes
AfxMessageBox(_T("Warning: CMyClass not defined"));
// We only want to create an object derived from CWnd.
TRACE(_T("Error; Object %s is not derived from CWnd\n"),
ClassName, BaseClass, size, schema
// Get a pointer to the base class CRuntimeClass.
CRuntimeClass* pBaseClass = pClass->m_pfnGetBaseClass();
CRuntimeClass* pBaseClass = pClass->m_pBaseClass;
ASSERT(pBaseClass != NULL);
TRACE("Creating object %s derived from %s, with object size %d "
"and schema %d\n", pClass->m_lpszClassName,
You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.
Similar topics related to this section
Programming Windows, Fifth Edition (Developer Reference)
Programming Applications for Microsoft Windows (Microsoft Programming Series)
Programming Windows with MFC, Second Edition
Visual C++ Programming
Programming Microsoft Visual C++, Fifth Edition
| #1 webmaster Tue 29 Apr/2014 04:43:32(GMT) || 0 || 0|
We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.
Your message goes here: