VC++ GDI画立体管道

都是以前的一些代码,今天回头整理的时候,看到一些有些用的东西。在做SCADA的时候,所涉及的绘制对象,有立体管道。下面的代码,就是使用GDI来绘制3D立体管道的。下面是核心代码(略显冗余),如果使用,稍作修改即可。

http://vcsky.net  by havenzhao

void Draw(CDC *PDC) 
{ 
    int pointNum = m_PointArray.GetSize(); 
    //Draw figure 
    CPoint* tmpPoint= (CPoint*) new CPoint[pointNum]; 
    CSize tmpSize(m_nOrgX, m_nOrgY); 
    for(int Index = 0; Index < pointNum; Index++) 
       tmpPoint[Index] = m_PointArray[Index] + tmpSize;      
    COLORREF C1 = RGB(1, 69, 142); //m_LineColor
    COLORREF C2 = RGB(255, 255, 255); //m_BrushColor
    float f; 
    int i, count = 5; 
    count += m_LineWidth;//增加线宽,从而设置管道的粗细 
    CPen pen, *pOldPen; 
    for (i=count; i>0; i--) 
    { 
        f = float(i) / count;//设置颜色渐变的比例因子 
        BYTE  bR =  (BYTE)(GetRValue(C1) * f + GetRValue(C2) * (1 - f)); 
        BYTE  bG =  (BYTE)(GetGValue(C1) * f + GetGValue(C2) * (1 - f)); 
        BYTE  bB =  (BYTE)(GetBValue(C1) * f + GetBValue(C2) * (1 - f)); 
         pen.CreatePen(PS_SOLID, i, RGB(bR, bG, bB)); // 创建画笔         
        pOldPen = PDC->SelectObject(&pen); 
        PDC->Polyline(tmpPoint,pointNum);         
        pen.DeleteObject();                // 释放GDI资源 
    }
    //Remove pen/brush 
    PDC->SelectObject(pOldPen); 
    delete[] tmpPoint; 
}


你可能感兴趣的:(c,delete,vc++,float,byte)