我用CRgn :: CreatePolygonRgn()创建了一个CRgn。现在,我需要从该区域提取这些点。我发现可以使用CRgn :: GetRegionData()提取数据。但无法获取数据。
谁能告诉我一个例子。
最佳答案
能够使用OnPaint事件检索有效数据。
CPaintDC dc(this); // device context for painting
CRgn rgnA;
CPoint ptVertex[5];
ptVertex[0].x = 180;
ptVertex[0].y = 80;
ptVertex[1].x = 100;
ptVertex[1].y = 160;
ptVertex[2].x = 120;
ptVertex[2].y = 260;
ptVertex[3].x = 240;
ptVertex[3].y = 260;
ptVertex[4].x = 260;
ptVertex[4].y = 160;
VERIFY(rgnA.CreatePolygonRgn(ptVertex, 5, ALTERNATE));
CRect rectRgnBox;
int nRgnBoxResult = rgnA.GetRgnBox(&rectRgnBox);
ASSERT(nRgnBoxResult != ERROR && nRgnBoxResult != NULLREGION);
CBrush brA;
VERIFY(brA.CreateSolidBrush(RGB(255, 0, 0))); // rgnA Red
VERIFY(dc.FrameRgn(&rgnA, &brA, 2, 2));
rectRgnBox.InflateRect(3, 3);
int size = GetRegionData(rgnA, 0, NULL);
int rectcount = 0;
if (size)
{
RGNDATA * pRegion = (RGNDATA *) new char[size];
GetRegionData(rgnA, size, pRegion);
RECT * pRect = (RECT *)& pRegion->Buffer;
int rectcount = pRegion->rdh.nCount;
if (pRegion)
{
int f;
for (unsigned i = 0; i < pRegion->rdh.nCount; i++)
{
f = pRect[i].left;
f = pRect[i].top;
f = pRect[i].right;
f = pRect[i].bottom;
}
}
delete[](char *) pRegion;
}
代码参考
CRgn::CreatePolygonRgn
编辑
每个具有唯一颜色的矩形将使您知道矩形如何填充区域
关于c++ - 有关从CRgn对象提取点的查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57943143/