Serialize HMetaFile in C++/MFC

Hello all,

I am 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.

[code] 1. class CMetaObject : public CObject
2. {
4. public:
5. HMETAFILE metaFileObj;
6. public:
7. CMyObject();
8. virtual void Serialize( CArchive& ar );
9. };
11. class CMetaStorage: public CObject
12. {
13. DECLARE_SERIAL(CMetaStorage)
14. public:
15. CMetaObject m_metaFileObj;
16. public:
17. CMetaStorage();
18. virtual void Serialize(CArchive& ar);
19. };[/code]

In MetaStorage.cpp I have attempted to serialize the "object" like so:
[code] 1. void CCompoundObject::Serialize( CArchive& ar )
2. {
3. CObject::Serialize( ar );
4. m_metaFileObj.Serialize( ar );
5. }

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.


  • Never mind folks, don't think what I was trying to do is possible. So I implemented a CArray instead.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion