分类: C/C++
2008-08-04 09:32:57
二、代码比较简单主要的部分是画管道,代码如下:
void CMultiAxtiveX1Ctrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { CBrush brBk[64]; //创建画刷 int nWidth = rcBounds.Width(); int nHeight = rcBounds.Height(); CRect rct; int j=0; if (m_ColorR>255 ||m_ColorR<0) //合理化m_ColorR值 m_ColorR=255; for (int i = 0; i < 64; i )//设置画刷颜色 { if (i<32) brBk[i].CreateSolidBrush(RGB(m_ColorR - (32-i % 32), m_ColorR - (32-i % 32), 100)); else brBk[i].CreateSolidBrush(RGB(m_ColorR - (i % 32), m_ColorR - (i % 32), 100)); } //画渐变 for (i = rcBounds.top; i <= nHeight 2; i ) { rct.SetRect(rcBounds.left, i,nWidth, i 1); pdc->FillRect(&rct, &brBk[((i * 63) / nHeight)]); } for( j=0;j<10;j ) { rct.SetRect(rcBounds.left m_grid[j]*nWidth/40, rcBounds.top , rcBounds.left m_grid[j]*nWidth/40 nWidth/40, nHeight ); pdc->FillRect(&rct, CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH))); } for (i = 0; i < 64; i ) brBk[i].DeleteObject(); }
四、结束语
利用vc这个强大的工具,我们可以做出更好更出色的控件。