Hello all,
I am Lisa and fairly new to C++/MFC. For a class project, we are to develop any software of our choice and add as much functionality as possible. I have chosen to build a program similar to MS Paint since MFC has functions that makes building shapes very simple. So far I've gotten serialization() of dynamic members sorted out.
Although we can add whatever we want to the program, I might have bitten more then I can chew and scripted complex drawings which I have chosen to save in MetaFiles.
Here's how I have implemented things:
1. I have created a class called CMetaStorage with another subclass CMetaObject.
class CMetaObject : public CObject
{
DECLARE_SERIAL(CMetaObject)
public:
HMETAFILE metaFileObj;
public:
CMyObject();
virtual void Serialize( CArchive& ar );
};
class CMetaStorage: public CObject
{
DECLARE_SERIAL(CMetaStorage)
public:
CMetaObject m_metaFileObj;
public:
CMetaStorage();
virtual void Serialize(CArchive& ar);
};
In MetaStorage.cpp I have attempted to serialize the "object" like so:
void CCompoundObject::Serialize( CArchive& ar )
{
CObject::Serialize( ar );
m_metaFileObj.Serialize( ar );
}
The program runs fine without any errors. I think that the structure of the code is fine as I have serialized other objects fine, thus being able to save and open file data.
However, for serialization of the metafile, if the user chooses to save the file, it appears to be saved fine (as no run time errors and the output file actually has a 1KB file size), however when the file is re-opened nothing is shown/drawn onto the view. To test things, I put an alert in the code block that plays metafiles, if and only if the data is of type CMetaStorage and not of my other defined classes. This alert box pops up, so the file actually contains some kind of data that is related to CMetaStorage.
So what might be the problem? MetaFiles can't be that easily serialized? If that is so, how do I go about saving them? I have heard of converting into bmp files, but even this technique is short of resources. So therefore, that would still lead me to a similar question.
I'd prefer to keep my raw data which saving a metafile should ensure. For instance I can serialize the co-ordinates for a simple line. (I have invested alert boxes into the code block for type CLine, that would alert the cpoints of the line. If the user saves a file with just a line drawn, then re-opens the file, the alert box would successfully echo the points and the line that was drawn is also seen on view.) So like I've mentioned above, I can successfully serialize dynamic members. Just those metafiles... :(
Any help would be appreciated.
Thanks!