2015-02-06 50 views
0

我想从书中学习MFC:MV C++ Windows Application by Example(2008)。有示例应用程序。在那里我可以吸取环充满女巫选择的颜色:MFC:环 - 没有颜色变化

void CRingView::OnDraw(CDC* pDC) 
{ 
CRingDoc* pDoc = GetDocument(); 
ASSERT_VALID(pDoc); 
if (!pDoc) 
    return; 
PointArray& pointArray = pDoc->GetPointArray(); 
ColorArray& colorArray = pDoc->GetColorArray(); 
int iSize = static_cast<int>(pointArray.GetSize()); 
for (int iIndex = 0; iIndex < iSize; iIndex++) 
{ 
    CPoint point = pointArray[iIndex]; 
    COLORREF color = colorArray[iIndex]; 
    CPen pen(PS_SOLID, 0, BLACK); 
    CBrush brush(color); 
    pDC->Ellipse(point.x - RADIUS, point.y - RADIUS, point.x + RADIUS, point.y + RADIUS); 
    CPen* pOldPen = pDC->SelectObject(&pen); 
    CBrush* pOldBrush = pDC->SelectObject(&brush); 
} 
} 

但没有颜色变化(白总是像BG),即使我做的:

CBrush brush(BLACK); 

所以问题是:我在做什么错误?我正在使用Visual Studio 2013,但新项目不应该有任何兼容性错误。 和黑色是:

static const COLORREF BLACK = RGB(0, 0, 0); 
+2

在进行椭圆绘制之前,请尝试选择笔和笔刷。 – acraig5075 2015-02-06 12:41:04

+0

@ acraig5075感谢它的使用:'CBrush brush(color); \t \t pDC-> SelectObject(brush); \t \t pDC-> Ellipse ...' - 您是否将它作为答案广告或我们保留原样? – mielu 2015-02-06 14:53:33

+0

很高兴工作。我已将评论添加为答案,以便您对自己的个人资料没有未解答的问题。 – acraig5075 2015-02-06 16:52:51

回答

1

直流绘制与任何刷,笔,字体等目前选定的对象。因此在绘图之前笔和刷子的SelectObject应该发生。