VC++的简单的问题,不是本难
voidCChildView::OnPaint(){CPointpoint[3];CPaintDCdc(this);//devicecontextforpaintingC...
void CChildView::OnPaint()
{
CPoint point[3];
CPaintDC dc(this); // device context for painting
CRect rcClient;
GetClientRect(&rcClient);
int cx = rcClient.Width()/2;
int cy = rcClient.Height()/2;
CRect rcShape(cx - 45,cy - 45 ,cx + 45,cy + 45);
CBrush brush (RGB(255,0,0));
CBrush *pOldBrush = dc.SelectObject(&brush);
switch(m_nShape)
{
case 0:
dc.Ellipse(rcShape);
break;
case 1:
point[0].x = cx - 45;
point[0].y = cy + 45;
point[1].x = cx;
point[1].y = cy - 45;
point[2].x = cx + 45;
point[2].y = cy + 45;
dc.Polygon(point,3);
break;
case 2:
dc.Rectangle(rcShape);
break;
}
dc.SelectObject(pOldBrush);
}
--------------------------------
--------------------------------
一个简单的选择绘图程序,在前面选择的颜色,并把他的颜色选到了设备描述表,我想知道的就是最后这个dc.SelectObject(pOldBrush)是有什么用啊,既然选择颜色到设备描述表了,怎么结束的时候又进行一次选择.有知道了帮解答一下,我把这句删除了程序还是能运行的 展开
{
CPoint point[3];
CPaintDC dc(this); // device context for painting
CRect rcClient;
GetClientRect(&rcClient);
int cx = rcClient.Width()/2;
int cy = rcClient.Height()/2;
CRect rcShape(cx - 45,cy - 45 ,cx + 45,cy + 45);
CBrush brush (RGB(255,0,0));
CBrush *pOldBrush = dc.SelectObject(&brush);
switch(m_nShape)
{
case 0:
dc.Ellipse(rcShape);
break;
case 1:
point[0].x = cx - 45;
point[0].y = cy + 45;
point[1].x = cx;
point[1].y = cy - 45;
point[2].x = cx + 45;
point[2].y = cy + 45;
dc.Polygon(point,3);
break;
case 2:
dc.Rectangle(rcShape);
break;
}
dc.SelectObject(pOldBrush);
}
--------------------------------
--------------------------------
一个简单的选择绘图程序,在前面选择的颜色,并把他的颜色选到了设备描述表,我想知道的就是最后这个dc.SelectObject(pOldBrush)是有什么用啊,既然选择颜色到设备描述表了,怎么结束的时候又进行一次选择.有知道了帮解答一下,我把这句删除了程序还是能运行的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询