Click to See Complete Forum and Search --> : serialize a CRgn


Don Janik
April 13th, 1999, 03:34 PM
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

Fabian
April 13th, 1999, 08:33 PM
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

Don Janik
April 14th, 1999, 02:06 PM
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);
}

Don Janik
April 14th, 1999, 02:12 PM
Thankyou for your input, it helped. I posted an excerpt of my serialize code if your interested in looking at it.

Don