WEB开发网
开发学院软件开发VC 一个工业控制管道流动控件的实现 阅读

一个工业控制管道流动控件的实现

 2010-07-11 20:44:38 来源:WEB开发网   
核心提示:FlowCtrl在OnPaint函数中通过调用PipeImpl的Draw就能够完成背景的绘制了,下面是滑块的绘制,一个工业控制管道流动控件的实现(3),根据开始的原理,我们对每个滑块抽象一个小类CFlowUnit

FlowCtrl在OnPaint函数中通过调用PipeImpl的Draw就能够完成背景的绘制了。下面是滑块的绘制,根据开始的原理,我们对每个滑块抽象一个小类CFlowUnit,根据滑块的形状我们可以抽象滑块的外观:

typedef enum _UnitPattern
{
   UP_RECTANGLE = 0,
   UP_CIRCLE  = 1,
   UP_DLINE   = 2,  // 象 >> 类别
   UP_TRIANGLE = 3
}UNITPATTERN;

然后实现一个Draw函数完成这些不同形状的滑块的绘制工作。

void CFlowUnit::Draw(CDC *pDC, CRect &rcClient)
{
  CBrush pBackBrush, *pOldBrush;
  if (m_pParentWnd == NULL)
  {
    return;
  }

  pBackBrush.CreateSolidBrush(m_pParentWnd->GetUnitBackColor());
  pOldBrush = (CBrush *)pDC->SelectObject(&pBackBrush);
  switch (m_pParentWnd->GetUnitPattern())
  {
  case UP_RECTANGLE:
    pDC->FillRect(&m_rectClient, &pBackBrush);
    break;
  case UP_CIRCLE:
    pDC->SelectObject(::GetStockObject(NULL_PEN));
    pDC->Ellipse(&m_rectClient);
    break;
  case UP_DLINE:
    {
      int xCenter = 0, yCenter = 0;

      if ((m_pParentWnd->GetUnitDLinePattern() == DP_RIGHT) || (m_pParentWnd->GetUnitDLinePattern() == DP_LEFT))
      {
        xCenter = m_rectClient.left + (m_rectClient.right - m_rectClient.left) / 2;
        yCenter = (rcClient.bottom - rcClient.top) / 2;
      }
      else
      {
        xCenter = (rcClient.right - rcClient.left) / 2;
        yCenter = m_rectClient.top + (m_rectClient.bottom - m_rectClient.top) / 2;
      }
      DrawDLine(pDC, CPoint(xCenter, yCenter));
    }
    break;
  case UP_TRIANGLE:
    pDC->SelectObject(::GetStockObject(NULL_PEN));
    DrawTriangle(pDC);
    break;
  }
  pDC->SelectObject(pOldBrush);
  pBackBrush.DeleteObject();
}
void CFlowUnit::DrawDLine(CDC *pDC, CPoint ptCenter)
{
  if (m_pParentWnd == NULL)
  {
    return;
  }
  switch (m_pParentWnd->GetUnitDLinePattern())
  {
  case DP_RIGHT:
    _D_LINE_H(ptCenter.x + 0, ptCenter.y + 0, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 1, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 2, ptCenter.y + 2, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 1, ptCenter.y + 3, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 0, ptCenter.y + 4, m_pParentWnd->GetUnitBackColor());
    break;
  case DP_LEFT:
    _D_LINE_H(ptCenter.x + 2, ptCenter.y + 0, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 1, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 0, ptCenter.y + 2, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 1, ptCenter.y + 3, m_pParentWnd->GetUnitBackColor());
    _D_LINE_H(ptCenter.x + 2, ptCenter.y + 4, m_pParentWnd->GetUnitBackColor());
    break;
  case DP_DOWN:
    _D_LINE_V(ptCenter.x + 0, ptCenter.y + 0, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 1, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 2, ptCenter.y + 2, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 3, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 4, ptCenter.y + 0, m_pParentWnd->GetUnitBackColor());
    break;
  case DP_UP:
    _D_LINE_V(ptCenter.x + 0, ptCenter.y + 2, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 1, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 2, ptCenter.y + 0, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 3, ptCenter.y + 1, m_pParentWnd->GetUnitBackColor());
    _D_LINE_V(ptCenter.x + 4, ptCenter.y + 2, m_pParentWnd->GetUnitBackColor());
    break;
  default:
    break;
  }
}
void CFlowUnit::DrawTriangle(CDC *pDC)
{
  if (m_pParentWnd == NULL)
  {
    return;
  }
  CPoint ptRgn[3];
  switch (m_pParentWnd->GetFlowCtrl()->GetDirectionType())
  {
  case LEFT_TO_RIGHT:
    ptRgn[0].x = m_rectClient.left;
    ptRgn[0].y = m_rectClient.top;
    ptRgn[1].x = m_rectClient.left;
    ptRgn[1].y = m_rectClient.bottom;
    ptRgn[2].x = m_rectClient.right;
    ptRgn[2].y = m_rectClient.top + (m_rectClient.bottom - m_rectClient.top) / 2;
    break;
  case RIGHT_TO_LEFT:
    ptRgn[0].x = m_rectClient.right;
    ptRgn[0].y = m_rectClient.top;
    ptRgn[1].x = m_rectClient.right;
    ptRgn[1].y = m_rectClient.bottom;
    ptRgn[2].x = m_rectClient.left;
    ptRgn[2].y = m_rectClient.top + (m_rectClient.bottom - m_rectClient.top) / 2;
    break;
  case TOP_TO_BOTTOM:
    ptRgn[0].x = m_rectClient.left;
    ptRgn[0].y = m_rectClient.top;
    ptRgn[1].x = m_rectClient.right;
    ptRgn[1].y = m_rectClient.top;
    ptRgn[2].x = m_rectClient.left + (m_rectClient.right - m_rectClient.left) / 2;
    ptRgn[2].y = m_rectClient.bottom;
    break;
  case BOTTOM_TO_TOP:
    ptRgn[0].x = m_rectClient.left;
    ptRgn[0].y = m_rectClient.bottom;
    ptRgn[1].x = m_rectClient.right;
    ptRgn[1].y = m_rectClient.bottom;
    ptRgn[2].x = m_rectClient.left + (m_rectClient.right - m_rectClient.left) / 2;
    ptRgn[2].y = m_rectClient.top;
    break;
  default:
    break;
  }
  CBrush pBackBrush, *pOldBrush;
  pBackBrush.CreateSolidBrush(m_pParentWnd->GetUnitBackColor());
  pOldBrush = (CBrush *)pDC->SelectObject(&pBackBrush);
  pDC->SetPolyFillMode(WINDING);
  pDC->Polygon(ptRgn, 3);
  pDC->SelectObject(pOldBrush);
  pBackBrush.DeleteObject();
}

上一页  1 2 3 4 5  下一页

Tags:一个 工业控制 管道

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接