Serialize HMetaFile in C++/MFC

  • theBruney
  • Student
  • Student
  • User avatar
  • Posts: 67
  • Loc: China

Post 3+ Months Ago

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: [ Select ]
  class CMetaObject : public CObject
   HMETAFILE metaFileObj;
   virtual void Serialize( CArchive& ar );

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

In MetaStorage.cpp I have attempted to serialize the "object" like so:

Code: [ Select ]
void CCompoundObject::Serialize( CArchive& ar )
   CObject::Serialize( ar );
   m_metaFileObj.Serialize( ar );
  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.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • theBruney
  • Student
  • Student
  • User avatar
  • Posts: 67
  • Loc: China

Post 3+ Months Ago

Problem solved. No worries folks.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

For anyone else who may stumble across your post in the future, would you mind telling us a bit more about how you solved the issue?

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 76 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.