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!

Recommended Answers

All 3 Replies

Read through Microsoft's Scribble Tutorial -- it is something similar to MS-Paint and it serializes the data. See how that tutorial serializes data and it might give you some ideas how to implement it in your program.

Hey thanks. Now that I see MS haven't invested in the method of serializing the metafile, which would be the easiest way to go around saving all those points, I now believe that the method I am using while it produces no errors, it is clearly not applicable.

Nothing good comes that easy anyways.

For anyone whom might be wondering, I'll now just create a class for any stroke, no matter how short it may be, serialize the points, since I have no problem storing those and using the usual Lineto and MoveTo functions "re-play" the strokes after. If it works as expected I'll post back later.

Cheers.

Since my drawings run on mouse move to give the user that 'as you draw see what you draw' effect had to use some sort of storage object that is dynamically expandable, don't know why I didn't think of it sooner, but I used CArray to store all those points. The rest is self explanatory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.