我将一些属于某些对象的符号绘制到设备上下文中,现在希望以后能够测试鼠标光标是否在这样的符号上方。
为此,我的计划是首先创建一个CDC
路径并使用它来创建一个CRgn
区域对象。
pDC->BeginPath();
pDC->Ellipse(ellipse[0], ellipse[1], ellipse[2], ellipse[3]); // Create path only
pDC->EndPath();
// Actually draw the ellipse
pDC->StrokeAndFillPath(); // Apparently removes the path from the DC
CRgn region;
if (region.CreateFromPath(pDC)) // Would also remove the path from the DC
{
// We never get here :-/
// Here I would copy the region's data,
// attach it to the object being drawn and
// destroy the region.
// That way I can create a region later on and do the hit-testing.
}
我怎样才能同时使用路径,绘制和创建区域,而不必绘制两次?绘制两次几乎使我的绘制方法所花费的时间翻了一番,这是我想避免的。