1CDC *pDC =&MemDC; 2 CRect rectTab=rcWindow; 3 rectTab.left+=100; 4 rectTab.right=rectTab.left+100; 5 rectTab.top+=5; 6 rectTab.bottom=rectTab.top+25; 7 CList<POINT, POINT> pts; 8 9 POSITION posLeft = pts.AddHead (CPoint (rectTab.left, rectTab.top)); 10 posLeft = pts.InsertAfter (posLeft, CPoint (rectTab.left, rectTab.top + 2)); 11 12 POSITION posRight = pts.AddTail (CPoint (rectTab.right, rectTab.top)); 13 posRight = pts.InsertBefore (posRight, CPoint (rectTab.right, rectTab.top + 2)); 14 15 int xLeft = rectTab.left + 1; 16 int xRight = rectTab.right - 1; 17 18 int y = 0; 19 for (y = rectTab.top + 2; y < rectTab.bottom-4;y += 2) 20 { 21 22 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); 23 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y+2)); 24 25 posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); 26 posRight = pts.InsertBefore (posRight, CPoint (xRight, y+2)); 27 xLeft++; 28 xRight--; 29 30 } 31 32 xLeft--; 33 xRight++; 34 /**/ 35 36 const int nTabLeft = xLeft - 1; 37 const int nTabRight = xRight + 1; 38 39 for (;y < rectTab.bottom - 1; y++) 40 { 41 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft-1, y-1)); 42 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); 43 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y+1)); 44 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 2, y+2)); 45 46 posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); 47 posRight = pts.InsertBefore (posRight, CPoint (xRight - 1, y + 1)); 48 49 if (y == rectTab.bottom - 2) 50 { 51 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); 52 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 3, y + 1)); 53 54 posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 1)); 55 posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, y + 1)); 56 } 57 58 xLeft++; 59 xRight--; 60 }/**/ 61 62 posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 2, rectTab.bottom)); 63 posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, rectTab.bottom)); 64 LPPOINT points = new POINT [pts.GetCount ()]; 65 int i = 0; 66 67 for (POSITION pos = pts.GetHeadPosition (); pos != NULL; i++) 68 { 69 points [i] = pts.GetNext (pos); 70 points [i].y = rectTab.bottom - (points [i].y - rectTab.top); 71 } 72 73 CRgn rgnClip; 74 rgnClip.CreatePolygonRgn (points, (int) pts.GetCount (), WINDING); 75 pDC->SelectClipRgn (&rgnClip); 76 77 //Region rg((HRGN)rgnClip.GetSafeHandle()); 78 //CBrush br (RGB(255,255,255)); 79 //pDC->FillRect ( rectTab,&br); 80 //br.DeleteObject(); 81 /***绘制渐变色**/ 82 int R=255; 83 int G=255; 84 int B=255; 85 CPen Bpen (PS_SOLID, 1, RGB(R,G,B)); 86 CPen* pOLdBPen = pDC->SelectObject (&Bpen); 87 for(int i=rectTab.top;i<rectTab.bottom;i++) 88 { 89 CPen pen (PS_SOLID, 1, RGB(R--,G--,B--)); 90 pDC->SelectObject (&pen); 91 pDC->MoveTo (rectTab.left,i ); 92 pDC->LineTo (rectTab.right,i); 93 pen.DeleteObject(); 94 } 95 Bpen.DeleteObject(); 96 pDC->SelectObject (&pOLdBPen); 97 98 /*graphics.SetSmoothingMode(SmoothingModeHighSpeed); 99 SolidBrush brush22(Color(255,255, 255, 255)); 100 graphics.FillRegion(&brush22,&rg);*/ 101 102 pDC->SelectClipRgn (NULL); 103 CPen pen (PS_SOLID, 1, globalData.clrBarShadow); 104 CPen* pOLdPen = pDC->SelectObject (&pen); 105 106 for (i = 0; i < pts.GetCount (); i++) 107 { 108 if ((i % 2) != 0) 109 { 110 int x1 = points [i - 1].x; 111 int y1 = points [i - 1].y; 112 113 int x2 = points [i].x; 114 int y2 = points [i].y; 115 116 if (x1 > rectTab.CenterPoint ().x && x2 > rectTab.CenterPoint ().x) 117 { 118 x1--; 119 x2--; 120 } 121 122 if (y2 >= y1) 123 { 124 pDC->MoveTo (x1, y1); 125 pDC->LineTo (x2, y2); 126 } 127 else 128 { 129 pDC->MoveTo (x2, y2); 130 pDC->LineTo (x1, y1); 131 } 132 } 133 } 134 135 delete [] points; 136 pDC->SelectObject (pOLdPen); 137 rectTab.left = nTabLeft; 138 rectTab.right = nTabRight;
效果图:
