XcamaroX
July 26th, 2004, 12:47 AM
I need some help with these requirements, I kind of know what they are saying but I can not implement it. DO you guys have any clues on "how to" ? I would really appreciate anything at this point. Here it goes:
//////////////////////////////////////////////////////////////
Add a CArray to the document.
Derive a new class that is based on CObject.
Add member variables to the class for the characteristics of shapes.
Make the class serializable.
Include <afxtmpl.h> in the stdafx.h file.
Define a new type that uses CArray and your new class. Declare a member variable in the document that uses this new type. This is the database of shapes for the assignment. All shapes that are drawn will be saved in this array.
Overload the = operator for this class. Once the = operator is defined, it can be used to define a copy constructor.
Modify the Serialize method of the document so that the CArray is serialized.
The CArray class already supports serialization. Since your new class is not simple enough, you will need to override a super secret method in order to make the default CArray serialization work. If your class is named CShapeClass, then add this header to the .h file of your class, after your class definition and before the typedef that defines your CArray. This is a global function, it does not belong in the definition of your shape class.
template <> void AFXAPI SerializeElements <CShapeClass> ( CArchive& ar,
CShapeClass* pShapeClass, INT_PTR nCount );
Add the following definition to the .cpp of your class:
template <> void AFXAPI SerializeElements <CShapeClass> ( CArchive& ar,
CShapeClass* pShapeClass, INT_PTR nCount )
{
for ( int i = 0; i < nCount; i++, pShapeClass++ )
{
// Serialize each CShapeClass object
pShapeClass->Serialize( ar );
}
}
//////////////////////////////////////////////////////////////////////////////
This is based on a SDI that through a Dialog box (you get the kind of shape: rectangle, ellipse, line) you draw it on the Document.
TIA!!!
//////////////////////////////////////////////////////////////
Add a CArray to the document.
Derive a new class that is based on CObject.
Add member variables to the class for the characteristics of shapes.
Make the class serializable.
Include <afxtmpl.h> in the stdafx.h file.
Define a new type that uses CArray and your new class. Declare a member variable in the document that uses this new type. This is the database of shapes for the assignment. All shapes that are drawn will be saved in this array.
Overload the = operator for this class. Once the = operator is defined, it can be used to define a copy constructor.
Modify the Serialize method of the document so that the CArray is serialized.
The CArray class already supports serialization. Since your new class is not simple enough, you will need to override a super secret method in order to make the default CArray serialization work. If your class is named CShapeClass, then add this header to the .h file of your class, after your class definition and before the typedef that defines your CArray. This is a global function, it does not belong in the definition of your shape class.
template <> void AFXAPI SerializeElements <CShapeClass> ( CArchive& ar,
CShapeClass* pShapeClass, INT_PTR nCount );
Add the following definition to the .cpp of your class:
template <> void AFXAPI SerializeElements <CShapeClass> ( CArchive& ar,
CShapeClass* pShapeClass, INT_PTR nCount )
{
for ( int i = 0; i < nCount; i++, pShapeClass++ )
{
// Serialize each CShapeClass object
pShapeClass->Serialize( ar );
}
}
//////////////////////////////////////////////////////////////////////////////
This is based on a SDI that through a Dialog box (you get the kind of shape: rectangle, ellipse, line) you draw it on the Document.
TIA!!!