CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    12

    serialize a CRgn

    Does anyone know how to serialize a CRgn data member. I have a member variable of type CRgn. In the serialize function of my doc class the following will assert an error.

    ASSERT( mTheCRgn.IsSerializable() );

    in my app the region is created in two stages
    CRgn mTheCRgn;
    mTheCRgn.CreateRectRgn(50,50,200,100);

    The user modifies the shape of the region using the mouse. But it won't serialize. CRgn is derived from CObject so it should work.

    Thankyou for your help

    Don


  2. #2
    Join Date
    Apr 1999
    Posts
    21

    Re: serialize a CRgn

    Hi there, is true that CRgn is derived from CObject, but also is true that CRgn doesn't implement Serialize(), so if you used it... nothing happen.
    So, to solve this you should take care of the serialization of your region. Take a look to CRgn::GetRegionData(), you'll obtain a RGNDATA Structure, and inside of this you'll find a RGNDATAHEADER structure, so you can serialize all the members of these structures. Use a CRgn::CreateFromData to recreate the region.

    Good luck

    Fabian



  3. #3
    Join Date
    Apr 1999
    Posts
    12

    Re: serialize a CRgn

    Below is my code to serialize the CRgn object called "myCRgn"


    if (ar.IsStoring())
    {
    RegionDataSize = myCRgn.GetRegionData(NULL, 0);
    lpRgnData = (LPRGNDATA) ::GlobalAlloc(GPTR, RegionDataSize);
    result = myCRgn.GetRegionData(lpRgnData, RegionDataSize);


    ar << RegionDataSize; // Store the size of the region
    ar.Write(lpRgnData,RegionDataSize); // Store the region data
    ::GlobalFree(lpRgnData); // free memory

    }
    else
    {
    ar >> RegionDataSize; // Retrieve the size of the region in bytes

    lpRgnData = (LPRGNDATA) ::GlobalAlloc(GPTR, RegionDataSize);

    ar.Read(lpRgnData,RegionDataSize);
    tempCRgn.CreateFromData(NULL,RegionDataSize,lpRgnData);

    myCRgn.CopyRgn(&tempCRgn);
    tempCRgn.DeleteObject();
    ::GlobalFree(lpRgnData);
    }


  4. #4
    Join Date
    Apr 1999
    Posts
    12

    Re: serialize a CRgn

    Thankyou for your input, it helped. I posted an excerpt of my serialize code if your interested in looking at it.

    Don


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured