MFC stands for microsoft foundation class ,Its a microsoft class library ,its a wrapper of the API ,its use for creating Windows application( GUI application) in Windows .basiccally in MFC there is two class CFrameWnd and CWinApp
CframeWnd is provide the funcitonalities related to GUI and CWinapp for application level functionalities ..
Both these classes derived from CCmdTarget .CCmdTarget is created with the capability to handle windows messages,which is referred as Message Maps.CCmdTarget is derived from CObject
CObject:-
its main root class for major MFC class.it provides these major features in your own class Object like as Serialization support,run time class information and object diagnostic output. CObject class has the ability to determine the exact class of an object at run time.
Some classes are not derived form the CObject like CString ,CTime,CTimespan
CObject Serialization support:-
when a class is derived from COject there is two main MACRO use for the serialization object.
DECLARE_SERIAL and IMPLEMENT_SERIAL
Reads or writes this object from or to an archive.
function signature is
virtual void Serialize(CArchive & ar)
{
}
here is ar is serialize to or from.
You must override Serialize for each class that you intend to serialize. The overridden Serialize must first call theSerialize function of its base class.
For ex:-
void CMyClass:: Serialize(CArchive& ar )
{
CObject::Serialize( ar );
if(ar.IsStoring())
{
arr<<myClass;
}
else
arr>>myClass;
}
COject is associated with the CRuntimeClass use can use to obtain the inforamation about an object or its base class at Run time .
CRuntimeCLass is a struct so it is does not contain any base class.
CframeWnd is provide the funcitonalities related to GUI and CWinapp for application level functionalities ..
Both these classes derived from CCmdTarget .CCmdTarget is created with the capability to handle windows messages,which is referred as Message Maps.CCmdTarget is derived from CObject
CObject:-
its main root class for major MFC class.it provides these major features in your own class Object like as Serialization support,run time class information and object diagnostic output. CObject class has the ability to determine the exact class of an object at run time.
Some classes are not derived form the CObject like CString ,CTime,CTimespan
CObject Serialization support:-
when a class is derived from COject there is two main MACRO use for the serialization object.
DECLARE_SERIAL and IMPLEMENT_SERIAL
Reads or writes this object from or to an archive.
function signature is
virtual void Serialize(CArchive & ar)
{
}
here is ar is serialize to or from.
You must override Serialize for each class that you intend to serialize. The overridden Serialize must first call theSerialize function of its base class.
For ex:-
void CMyClass:: Serialize(CArchive& ar )
{
CObject::Serialize( ar );
if(ar.IsStoring())
{
arr<<myClass;
}
else
arr>>myClass;
}
COject is associated with the CRuntimeClass use can use to obtain the inforamation about an object or its base class at Run time .
CRuntimeCLass is a struct so it is does not contain any base class.
struct CRuntimeClass
The ability to determine the class of an object at run time is useful when extra type checking of function arguments is needed, or when you must write special-purpose code based on the class of an object. Run-time class information is not supported directly by the C++ language.
CRuntimeClass* pClass = RUNTIME_CLASS( CObject );the IsKindOf member function for objects of that class, using the RUNTIME_CLASS macro to generate theCRuntimeClass argument, as shown here:class CPerson : public CObject { DECLARE_DYNAMIC( CPerson ) public: CPerson(){}; // other declaration }; // in .CPP file IMPLEMENT_DYNAMIC( CPerson, CObject ) void SomeFunction(void) { CObject* pMyObject = new CPerson; if(pMyObject->IsKindOf( RUNTIME_CLASS( CPerson ) ) ) { //if IsKindOf is true, then cast is all right CPerson* pmyPerson = (CPerson*) pMyObject ; ... delete pmyPerson; } ... delete [MyObject]; }
Comments
Post a Comment