地理信息系统HfGIS,MFC绘图的办法

上次写了《VC++开发地理信息系统的源码HfGIS(1)》,GIS不可避免地要涉及绘图,在MFC是如何绘图呢。

请看例程:

void CDrawRect::Draw(CDC* pDC)

{

ASSERT_VALID(this);

CBrush brush;

if (!brush.CreateBrushIndirect(&m_logbrush))

return;

CPen pen;

if (!pen.CreatePenIndirect(&m_logpen))

return;

CBrush* pOldBrush;

CPen* pOldPen;

if (m_bBrush)

pOldBrush = pDC->SelectObject(&brush);

else

pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);

if (m_bPen)

pOldPen = pDC->SelectObject(&pen);

else

pOldPen = (CPen*)pDC->SelectStockObject(NULL_PEN);

CRect rect = m_position;

switch (m_nShape)

{

case rectangle:

pDC->Rectangle(rect);

break;

case roundRectangle:

pDC->RoundRect(rect, m_roundness);

break;

case ellipse:

pDC->Ellipse(rect);

break;

case circle:

DrawCircle(pDC,rect);

//pDC->Circle(rect);

break;

case line:

if (rect.top > rect.bottom)

{

rect.top -= m_logpen.lopnWidth.y / 2;

rect.bottom += (m_logpen.lopnWidth.y + 1) / 2;

}

else

{

rect.top += (m_logpen.lopnWidth.y + 1) / 2;

rect.bottom -= m_logpen.lopnWidth.y / 2;

}

if (rect.left > rect.right)

{

rect.left -= m_logpen.lopnWidth.x / 2;

rect.right += (m_logpen.lopnWidth.x + 1) / 2;

}

else

{

rect.left += (m_logpen.lopnWidth.x + 1) / 2;

rect.right -= m_logpen.lopnWidth.x / 2;

}

pDC->MoveTo(rect.TopLeft());

pDC->LineTo(rect.BottomRight());

break;

}

pDC->SelectObject(pOldBrush);

pDC->SelectObject(pOldPen);

}

你可能感兴趣的:(地理信息系统HfGIS,MFC绘图的办法)