|
-
June 4th, 1999, 09:30 AM
#1
How to copy CRgn object
Hello!
I'm writing on a class that mainly encapsulates a CRgn.
As I want to use this class in a container (mainly an array), i added
a copy constructor and assignment operator that should copy the
CRgn encapsulated in my class to the new instance.
However i get an error (access violation) when i try to create a CRgn
using CreateFromData and GetRegionData.
Here's the code:
class CMyRgn : public CObject
{
CRgn m_rgn;
CMyRgn (CMyRgn&);
CMyRgn operator= (CMyRgn&);
...
};
CMyRgn operator= (CMyRgn&)
{
// copy the region data
RGNDATA RgnData;
int nDataSize;
nDataSize = rgnSrc.m_rgn.GetRegionData (NULL, 0);
rgnSrc.m_rgn.GetRegionData (&RgnData, nDataSize); // this one fails
m_rgn.CreateFromData (NULL, nDataSize, &RgnData);
...
}
-
June 4th, 1999, 11:10 AM
#2
Re: How to copy CRgn object
Well, you see, you need to allocate memory for your region data, specifically, the rectangles pointed by RgnData.Buffer....
// copy the region data
LPRGNDATA lpRgnData;
int nDataSize;
nDataSize = rgnSrc.m_rgn.GetRegionData (NULL, 0);
lpRgnData = (LPRGNDATA) new char[sizeof(RGNDATA)+nDataSize];
rgnSrc.m_rgn.GetRegionData (lpRgnData, nDataSize);
m_rgn.CreateFromData (NULL, nDataSize, &RgnData);
...
// clean up
delete (char*)lpRgnData;
-Safai
-
June 4th, 1999, 11:15 AM
#3
Re: How to copy CRgn object
The other option is to use CRgn::CopyRgn
-Safai
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
|