主题:图形重绘问题
在OnDraw函数中实现图形的重绘,利用CPtrArray,但是每次刷新后图像所画图形的颜色,全部成了最后一次选择的颜色,
请教哪里出了错误,有什么解决办法吗?
头文件中定义:
CPoint m_ptOrigin;
CPoint m_ptEnd;
UINT m_nDrawType;
COLORREF m_ptclr;
void CGraphicView::OnDraw(CDC* pDC)
{
CGraphicDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC dc(this);
CPen pen(PS_SOLID, m_nLineWidth, m_clr);//m_clr为选择颜色的COLORREF
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
pDC -> SelectObject(pBrush);
for (int i = 0; i < m_ptrArray.GetSize(); i++)
{
switch(((CGraph*)m_ptrArray.GetAt(i)) -> m_nDrawType)
{
case 1:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> MoveTo(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin);
pDC -> LineTo(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd);
break;
case 2:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> Rectangle(CRect(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin,
((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd));
break;
case 3:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> Ellipse(CRect(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin,
((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd));
break;
}
}
}
请教哪里出了错误,有什么解决办法吗?
头文件中定义:
CPoint m_ptOrigin;
CPoint m_ptEnd;
UINT m_nDrawType;
COLORREF m_ptclr;
void CGraphicView::OnDraw(CDC* pDC)
{
CGraphicDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC dc(this);
CPen pen(PS_SOLID, m_nLineWidth, m_clr);//m_clr为选择颜色的COLORREF
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
pDC -> SelectObject(pBrush);
for (int i = 0; i < m_ptrArray.GetSize(); i++)
{
switch(((CGraph*)m_ptrArray.GetAt(i)) -> m_nDrawType)
{
case 1:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> MoveTo(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin);
pDC -> LineTo(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd);
break;
case 2:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> Rectangle(CRect(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin,
((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd));
break;
case 3:
pDC -> SelectObject(&pen);
((CGraph*)(m_ptrArray.GetAt(i))) -> m_ptclr;
pDC -> Ellipse(CRect(((CGraph*)m_ptrArray.GetAt(i)) -> m_ptOrigin,
((CGraph*)m_ptrArray.GetAt(i)) -> m_ptEnd));
break;
}
}
}