码迷,mamicode.com
首页 > 编程语言 > 详细

MFC绘制函数

时间:2014-11-01 06:25:42      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:mfc draw

/////////////////////////////////////////////////////////////////////////////
// CX_SelfView construction/destruction
//void DrawHMI(CDC *pDC, int NodeNum, CRect rect, int type, BOOL MasterNet, BOOL SlaveNet,int nParent = View)
void DrawHMI(CDC *pDC, int NodeNum, CRect rect, int type, WORD MasterNet, WORD SlaveNet,int nParent = View)
{
 bool bTwinkleA= false;
 bool bTwinkleB= false;
 int left,right,top,bottom;
 char text[10];
 left = rect.left;
 right = rect.right;
 top = rect.top;
 bottom = rect.bottom;
 HGDIOBJ hPen1,hPen2,hOldPen;
 HGDIOBJ hBrush,hBrushnet,hOldBrush;
 HGDIOBJ hFont,hOldFont;
 COLORREF OldColor,OldBkColor;
 hBrush = CreateSolidBrush(RGB(0,0,255));
 hBrushnet = CreateSolidBrush(RGB(128,128,128));
 int wide = right-left;
 int cross = bottom-top;
 OldBkColor = pDC->SetBkColor(RGB(0,0,255));
 OldColor = pDC->SetTextColor(RGB(0,0,0)); 
 pDC->Rectangle(left+wide/8,top,right-wide/8,bottom-cross*2/5);
 int top1 = bottom-cross*2/5;
 pDC->Rectangle(left+wide/3,top1,right-wide/3,top1+cross/16);
 top1+=cross/16;
 pDC->Rectangle(left+wide/5,top1,right-wide/5,top1+cross/10);
 top1+=cross/10; 
 hOldBrush = pDC->SelectObject(hBrush);
 pDC->Rectangle(left+wide/8+wide/10,top+cross/10,right-wide/8-wide/10,bottom-cross/2);
 pDC->Rectangle(left,top1,right,bottom); 
 hFont= (HGDIOBJ)CreateFont(15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "TRUE TYPE FONTS");
 hOldFont=pDC->SelectObject(hFont);
 sprintf(text,"%d",NodeNum);
 rect.left = rect.left;
 rect.top = rect.top+cross/8;
 rect.right = rect.right;
 rect.bottom = rect.bottom;
 pDC->SetBkColor(RGB(255,255,255));
 pDC->SetTextColor(RGB(255,0,0));
 pDC->DrawText(text,strlen(text),&rect,DT_CENTER);
 /*
 if (MasterNet) hPen1=(HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen1 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,0,0));
 if (SlaveNet) hPen2 = (HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen2 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,255,13));
 */
 if (MasterNet == 0xff) hPen1=(HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen1 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,0,0));

/* else if((MasterNet==0) && (g_incount%2==0)) 
 {
  hPen1=NULL;
 }
 else 
 {
  hPen1 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,0,0));
 }
*/
 if (SlaveNet == 0xff) hPen2 = (HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen2 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,255,13));
 
 if(MasterNet==1)
 {
  bTwinkleA = true;
 }
 else
 {
  bTwinkleA = false;
 }
 if(SlaveNet==1)
 {
  bTwinkleB = true;
 }
 else
 {
  bTwinkleB = false;
 }
 
 /*
 bTwinkleA = true;
 bTwinkleB = true;
 */
 hOldPen = pDC->SelectObject(hPen1);
 if(type==0)
 {
  CRect rect1;
  pDC->SelectObject(hOldBrush);
  hOldBrush = pDC->SelectObject(hBrushnet);
  pDC->MoveTo((left+right)/2-3,top);
  if(bMultLev)  //5行
  {
   
   if(bTwinkleA && (g_incount%2==0))
   {
//    pDC->LineTo((left+right)/2-3,top-47+2);
    pDC->LineTo((left+right)/2-3,top-47+2+8); 
   }
   else if(!bTwinkleA)
   {
//    pDC->LineTo((left+right)/2-3,top-47+2);
    pDC->LineTo((left+right)/2-3,top-47+2+8); 
   }
   
//   pDC->LineTo((left+right)/2-3,top-47+2); 
   /*
   rect1.top    =top-47+2-3 ;
   rect1.bottom =top-47+2+3 ;
   */
   rect1.top    =top-47+2-3+8 ;
   rect1.bottom =top-47+2+3+8 ;
  }
  else
  {
   
   if(bTwinkleA && (g_incount%2==0))
   {
//    pDC->LineTo((left+right)/2-3,top-60+2);
    pDC->LineTo((left+right)/2-3,top-47+2); 
   }
   else if(!bTwinkleA)
   {
//    pDC->LineTo((left+right)/2-3,top-60+2);
    pDC->LineTo((left+right)/2-3,top-47+2); 
   }
  
//   pDC->LineTo((left+right)/2-3,top-60+2);
//   rect1.top    =top-60+2-3 ;
//   rect1.bottom =top-60+2+3 ;
   
   rect1.top    =top-47+2-3 ;
   rect1.bottom =top-47+2+3 ;
  }
  rect1.left   =(left+right)/2-3-3;
  rect1.right  =(left+right)/2-3+3 ;
        pDC->Rectangle(&rect1);
  
  pDC->SelectObject(hOldPen);
     hOldPen = pDC->SelectObject(hPen2); 
  pDC->MoveTo((left+right)/2+3,top);
  if(bMultLev)
  {
   if(bTwinkleB && (g_incount%2==0))
   {
//    pDC->LineTo((left+right)/2+3,top-32+2);
    pDC->LineTo((left+right)/2+3,top-32+2+3);
   }
   else if(!bTwinkleB)
   {
//    pDC->LineTo((left+right)/2+3,top-32+2);
    pDC->LineTo((left+right)/2+3,top-32+2+3);
   }
   /*
   rect1.top    =top-32+2-3 ;
   rect1.bottom =top-32+2+3 ;
   */
   rect1.top    =top-32+2-3+3 ;
   rect1.bottom =top-32+2+3+3 ;
  }
  else
  {
   if(bTwinkleB && (g_incount%2==0))
   {
    pDC->LineTo((left+right)/2+3,top-35+2);
   }
   else if(!bTwinkleB)
   {
    pDC->LineTo((left+right)/2+3,top-35+2);
   }
   rect1.top    =top-35+2-3 ;
   rect1.bottom =top-35+2+3 ;
  }
  rect1.left   =(left+right)/2+3-3;
  rect1.right  =(left+right)/2+3+3 ;
   
        pDC->Rectangle(&rect1);
 }
 pDC->SelectObject(hOldPen);
 DeleteObject(hPen1);
 DeleteObject(hPen2);
 pDC->SetBkColor(OldBkColor); 
 pDC->SetTextColor(OldColor);
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrush);
 DeleteObject(hBrushnet);
 
 pDC->SelectObject(hOldFont);
 DeleteObject(hFont);
// DeleteObject(hOldPen);
// DeleteObject(hOldBrush);
// DeleteObject(hOldFont);
}
//void DrawXCU(CDC* pDC,int NodeNum,CRect rect,int texttype,int linetype,int xcutype,BOOL MasterNet,BOOL SlaveNet,int nParent = View)
void DrawXCU(CDC* pDC,int NodeNum,CRect rect,int texttype,int linetype,int xcutype,WORD MasterNet,WORD SlaveNet,int nParent = View)
{
 bool bTwinkleA= false;
 bool bTwinkleB= false;
 HGDIOBJ hPen1,hPen2,hOldPen;
 HGDIOBJ hBrushtop,hBrushleft,hBrushforce,hBrushclient,hBrushnet,hOldBrush;
 COLORREF OldBkColor;
 int left,right,top,bottom;
 char text[10];
 left = rect.left;
 right = rect.right;
 top = rect.top;
 bottom = rect.bottom;
 int wide = right-left;
 int cross = bottom-top;
 COLORREF old_tClr = pDC->SetTextColor(RGB(0,0,0));
 hBrushtop    = CreateSolidBrush(RGB(0,0,128));
 hBrushleft   = CreateSolidBrush(RGB(0,128,128));
 switch(xcutype)
 {
 case XCU_MAIN:
  hBrushforce  = CreateSolidBrush(RGB(0,255,0));
  hBrushclient = CreateSolidBrush(RGB(0,255,0));
  break;
 case XCU_TRACE:
  hBrushforce  = CreateSolidBrush(RGB(0,0,255));
  hBrushclient = CreateSolidBrush(RGB(0,0,255));
  break;
 case XCU_INIT:
  hBrushforce  = CreateSolidBrush(RGB(255,255,0));
  hBrushclient = CreateSolidBrush(RGB(255,255,0));
  break;
 case NODE_OFFLINE:
  hBrushforce  = CreateSolidBrush(RGB(255,0,0));
  hBrushclient = CreateSolidBrush(RGB(255,0,0));
  break;
 default:
  break;
 }
 hBrushnet    = CreateSolidBrush(RGB(128,128,128));
 CPoint pts[4];
 pts[0].x = left+wide/4;
 pts[0].y = top;
 pts[1].x = right;
 pts[1].y = top;
 pts[2].x = right-wide/4;
 pts[2].y = top+cross/4;
 pts[3].x = left;
 pts[3].y = top+cross/4;
 hOldBrush = pDC->SelectObject(hBrushtop);
    pDC->Polygon(pts, 4);//画上面的阴影
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrushtop);
 pts[0].x = right;
 pts[0].y = bottom-cross/4;
 pts[3].x = right-wide/4;
 pts[3].y = bottom;
 hOldBrush = pDC->SelectObject(hBrushleft);
 pDC->Polygon(pts, 4);//画左边的阴影
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrushleft);
 
    hOldBrush = pDC->SelectObject(hBrushforce);
 pDC->Rectangle(left,top+cross/4,right-wide/4,bottom);//画正面方块
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrushforce);
    hOldBrush = pDC->SelectObject(hBrushclient);
 
 RECT r1 = rect;
 sprintf(text,"%d",NodeNum);
 rect.left = rect.left+9;
 rect.top = rect.bottom;
 rect.right = rect.right;
 rect.bottom = rect.bottom + 40;
 OldBkColor = pDC->SetBkColor(RGB(192,192,192));
 if(texttype==XCU_TEXT) pDC->DrawText(text,strlen(text),&rect,DT_CENTER);
 else if(texttype==XCU_TEXTCENTER) {
  r1.top +=15;r1.bottom +=15;
  pDC->DrawText(text,strlen(text),&r1,DT_CENTER);
 }
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrushclient);
 /*
 if (MasterNet) hPen1 = (HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen1 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,0,0));
 if (SlaveNet) hPen2 = (HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen2=(HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,255,13));
 */
 if (MasterNet == 0xff) hPen1=(HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen1 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,0,0));
 if (SlaveNet == 0xff) hPen2 = (HGDIOBJ)CreatePen(PS_DOT,0,RGB(255,0,0));
 else hPen2 = (HGDIOBJ)CreatePen(PS_SOLID,2,RGB(255,255,13));
 
 if(MasterNet==1)
 {
  bTwinkleA = true;
 }
 else
 {
  bTwinkleA = false;
 }
 if(SlaveNet==1)
 {
  bTwinkleB = true;
 }
 else
 {
  bTwinkleB = false;
 }
    OldBkColor = pDC->SetBkColor(RGB(255,255,255));
 if(linetype==XCU_LINE)
 {
  hOldPen=pDC->SelectObject(hPen1);
  hOldBrush = pDC->SelectObject(hBrushnet);
  pDC->MoveTo((left+right)/2-4,top);
  CRect rect1;
  
  if( nParent == View )
  {
   if( bMultLev )
   {
    if(bTwinkleA && (g_incount%2==0))
    {
//     pDC->LineTo((left+right)/2-4,rect.top-87+2);
     pDC->LineTo((left+right)/2-4,rect.top-87+2+10+10); //change by hhs at 20130716
    }
    else if(!bTwinkleA)
    {
//     pDC->LineTo((left+right)/2-4,rect.top-87+2);
     pDC->LineTo((left+right)/2-4,rect.top-87+2+10+10); //change by hhs at 20130716
    }
    /*
    rect1.top    =rect.top-87+2-3 ;
    rect1.bottom =rect.top-87+2+3 ; 
    */
    rect1.top    =rect.top-87+2-3 +10+10;
    rect1.bottom =rect.top-87+2+3 +10+10;
   }
   else
   {
    if(bTwinkleA && (g_incount%2==0))
    {
//     pDC->LineTo((left+right)/2-4,rect.top-101+2);
     pDC->LineTo((left+right)/2-4,rect.top-87+2);
    }
    else if(!bTwinkleA)
    {
//     pDC->LineTo((left+right)/2-4,rect.top-101+2);
     pDC->LineTo((left+right)/2-4,rect.top-87+2);
    }
//    rect1.top    =rect.top-101+2-3 ;
//    rect1.bottom =rect.top-101+2+3 ;
    
    rect1.top    =rect.top-87+2-3 ;
    rect1.bottom =rect.top-87+2+3 ;
   }
  }
  else 
  {
   /*
   pDC->LineTo((left+right)/2-4,rect.top-101+2);
   rect1.top    =rect.top-101+2-3 ;
   rect1.bottom =rect.top-101+2+3 ;
   */
   pDC->LineTo((left+right)/2-4,rect.top-101+2+10+10-20);  //单xcu画面中画网络连接线A网
   rect1.top    =rect.top-101+2-3+10+10-20 ;
   rect1.bottom =rect.top-101+2+3+10+10-20 ;
  }
  
  rect1.left   =(left+right)/2-4-3;
  rect1.right  =(left+right)/2-4+3 ;
        pDC->Rectangle(&rect1);
  pDC->SelectObject(hOldPen);
  hOldPen = pDC->SelectObject(hPen2);
  pDC->MoveTo((left+right)/2+4,top);
  if(nParent == View)
  {
   if(bMultLev)
   {
    if(bTwinkleB && (g_incount%2==0))
    {
//     pDC->LineTo((left+right)/2+4,rect.top-72+2);
     pDC->LineTo((left+right)/2+4,rect.top-72+2+10+10-5); //hhs
    }
    else if(!bTwinkleB)
    {
//     pDC->LineTo((left+right)/2+4,rect.top-72+2);
     pDC->LineTo((left+right)/2+4,rect.top-72+2+10+10-5); //hhs
    }
//    rect1.top    =rect.top-72+2-3 ;
//    rect1.bottom =rect.top-72+2+3 ;
    
    rect1.top    =rect.top-72+2-3+10+10-5;
    rect1.bottom =rect.top-72+2+3+10+10-5;
   }
   else
   {
    if(bTwinkleB && (g_incount%2==0))
    {
//     pDC->LineTo((left+right)/2+4,rect.top-75+2);
     pDC->LineTo((left+right)/2+4,rect.top-72+2);
    }
    else if(!bTwinkleB)
    {
//     pDC->LineTo((left+right)/2+4,rect.top-75+2);
     pDC->LineTo((left+right)/2+4,rect.top-72+2);
    }
//    rect1.top    =rect.top-75+2-3 ;
//    rect1.bottom =rect.top-75+2+3 ;
    
    
    rect1.top    =rect.top-72+2-3 ;
    rect1.bottom =rect.top-72+2+3 ;
   }
  }
  else if(nParent == Station)
  {
//   pDC->LineTo((left+right)/2+4,rect.top-75+2);
//   rect1.top    =rect.top-75+2-3 ;
//   rect1.bottom =rect.top-75+2+3 ;
   pDC->LineTo((left+right)/2+4,rect.top-75+2+10+10-15);  //hhs
   rect1.top    =rect.top-75+2-3+10+10-5-15 ;
   rect1.bottom =rect.top-75+2+3+10+10-5-15 ;
  }
  
  rect1.left   =(left+right)/2+4-3;
  rect1.right  =(left+right)/2+4+3;
        pDC->Rectangle(&rect1);
 }  
 pDC->SelectObject(hOldPen);
 DeleteObject(hPen1);
 DeleteObject(hPen2);
// DeleteObject(hOldPen);
 pDC->SelectObject(hOldBrush);
 DeleteObject(hBrushnet);
// DeleteObject(hOldBrush);
 pDC->SetBkColor(OldBkColor);
 pDC->SetTextColor(old_tClr);
}
void DrawXCUHMI(CDC* pDC,int NodeNum,BYTE Type,RECT Rect,int nParent = View)
{
 switch(Type)
 {
 case 0: DrawXCU(pDC,NodeNum,Rect,XCU_TEXTCENTER,XCU_NOLINE,XCU_MAIN,0,0,nParent);break;
 case 1: DrawXCU(pDC,NodeNum,Rect,XCU_TEXTCENTER,XCU_NOLINE,XCU_TRACE,0,0,nParent);break;
 case 2: DrawXCU(pDC,NodeNum,Rect,XCU_TEXTCENTER,XCU_NOLINE,XCU_INIT,0,0,nParent);break;
 default:DrawHMI(pDC,NodeNum,Rect,1,0,0);break;
 }
}

MFC绘制函数

标签:mfc draw

原文地址:http://embeded.blog.51cto.com/3989210/1570525

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!