|
-
April 13th, 1999, 03:34 PM
#1
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
-
April 13th, 1999, 08:33 PM
#2
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
-
April 14th, 1999, 02:06 PM
#3
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);
}
-
April 14th, 1999, 02:12 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|