CustomLineCap类有一个属性是m_BaseCap,看了MSDN上的解释太模糊了:
baseCap
[in] Element of the LineCap enumeration that specifies the line cap used on the ends of the line to be drawn.解释模糊就算了,我想可以实践一下看看效果总该知道了吧。结果:
   Graphics graphics(hdc);   PointF points[3] = {PointF(1, 0), PointF(0, 2), PointF(-1, 0)};
   GraphicsPath capPath;
   capPath.AddLines(points, 3);   CustomLineCap custCap(NULL, &capPath, LineCapRound, 0.0);
   custCap.SetWidthScale(2);
   custCap.SetBaseCap(LineCapTriangle); // 这里设置这个属性为三角形
   GraphicsPath linePath;
   linePath.AddLine(Point(100, 100), Point(100, 200));
   linePath.AddLine(100, 200, 300, 200);   Pen pen(Color(255, 0, 0, 255), 20.0f);
   pen.SetCustomEndCap(&custCap);
   graphics.DrawPath(&pen, &linePath); 上面代码结果是,跟该属性没有设置时候没有任何区别。
所以,有请知道的大虾告诉小弟,这个属性到底是用来干什么的

解决方案 »

  1.   

    有那位大哥知道怎么用c/c++编写 一个用 回溯算法 实现的 小棋局游戏啊 ,最好是一个 残局象棋游戏 ,设定2个残局棋谱就能实现人机对战,要简单的就好,急求啊
    有的帮帮我  我邮箱 [email protected]
      

  2.   

    CustomLineCap custCap(NULL, &capPath, LineCapRound, 0.0);
     
        自定义的是跟属性没有关系的,属性的设置是GDI+默认的几种样式
      

  3.   

    他有一个StrokeCap是用来设置自定义线帽的Cap的。但是这个BaseCap是用来设置哪里的CAP的呢?
      

  4.   

    The SetStrokeCap method sets the LineCap object used to start and end lines within the GraphicsPath object that defines this CustomLineCap object.  我的理解是 本身线貌也是  GraphicsPath 这个设置是设置线貌的线条的两端样式   画笔也有这样的功能
      

  5.   

    忘记说了 ,假如你把 Pen 的宽度放大一下 你就能看的很清楚
      

  6.   

    你的理解是这样的,我也这么认为,但是如果Fxingtianxia兄试一下的话,我相信你会发现不了任何变换的。随便你把这个BaseCap设置为LineJOinRound,LineJoinTriangle...(而且,经过测试发现这个属性不能设置为带Anchor的LineCap,这样将导致错误的参数传递)把Pen的宽度设为多大,都无法发现任何改变。始终都为LineCapFlat的效果。Fxingtianxia兄,我是经过测试了许多次才到这上面来问的。
      

  7.   

    // 自定义线帽
    GraphicsPath startPath, endPath; // 创建起点和终点路径对象
    startPath.AddRectangle(Rect(-10, -5, 20, 10)); // 起点矩形
    Point polygonPoints[4] = {Point(0, -20), Point(10, 0), Point(0, -10), Point(-10, 0)};
    endPath.AddPolygon(polygonPoints, 4);// 终点箭头
    CustomLineCap startCap(NULL, &startPath); // 创建起点线帽
    CustomLineCap endCap(NULL, &endPath); // 创建终点线帽
    // 定义笔
    Pen pen(Color::Black, 20); // 画带线帽粗线的黑笔
    Pen redPen(Color::Red); // 画不带线帽细线的红笔
    // 中英文线帽字符串数组
    CString cstrs[] = {L"平线帽", L"方线帽", L"圆线帽", L"三角线帽", L"无锚线帽", 
    L"方锚线帽", L"圆锚线帽", L"菱锚线帽", L"箭锚线帽", L"定制线帽"};
    CString estrs[] = {L"LineCapFlat", L"LineCapSquare", L"LineCapRound", 
    L"LineCapTriangle", L"LineCapNoAnchor", L"LineCapSquareAnchor", 
    L"LineCapRoundAnchor", L"LineCapDiamondAnchor", 
    L"LineCapArrowAnchor", L"LineCapCustom"};
    FontFamily fontFamily(L"Times New Roman"); // 或"宋体"
    Font font(&fontFamily, 10.5); // 五号字
    // 绘制各种线帽
    Graphics graph(pDC->m_hDC);
    for (int i = 0; i <= 9; i++) { // 画线循环
    LineCap lc = (LineCap)(i < 4 ? i : i + 12); // 线帽常量(整数)
    if ( i < 9) pen.SetLineCap(lc, lc, DashCapFlat); // 标准线帽
    else { // 自定义线帽(i = 9)
    pen.SetCustomStartCap(&startCap); // 设置自定义的起点线帽
    pen.SetCustomEndCap(&endCap); // 设置自定义的终点线帽
    pen.SetWidth(3.0f); // 重新设置线宽为3个像素
    }
    int y = 20 + i * 40; // 计算直线的垂直坐标
    graph.DrawLine(&pen, 100, y, 400, y); // 画带线帽的粗线
    graph.DrawLine(&redPen, 100, y, 400, y); // 画不带线帽的细线
    // 绘制中英文线帽字符串
    graph.DrawString(cstrs[i], -1, &font, PointF(15.0f, y - 8.0f), &brush);
    graph.DrawString(estrs[i], -1, &font, PointF(425.0f, y - 8.0f), &brush);
    }
      

  8.   

    Graphics graph(pDC->m_hDC);
    Pen pen(Color::Black, 10);
    pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapFlat);
    //pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapRound);
    //pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapTriangle);
    REAL dashVals[4] = {5.0f, 2.0f, 15.0f, 4.0f};
    for (int i = 0; i <= 5; i++) {
    pen.SetDashStyle((DashStyle)i);
    if (i == 5) pen.SetDashPattern(dashVals, 4);
    graph.DrawLine(&pen, 10, 10 + i * 20, 400, 10 + i * 20);
    }
      

  9.   

    Graphics graph(pDC->m_hDC);
    Pen redPen(Color::Red); // 画细线的红笔
    Pen pen(Color::DarkGreen, 40.0f); // 画粗线的绿色笔
    Point points[] = {Point(20, 100), Point(400, 130), Point(20, 160)}; // 点数组
    pen.SetLineJoin(LineJoinMiter); // 斜接
    //pen.SetLineJoin(LineJoinBevel); // 斜截
    //pen.SetLineJoin(LineJoinRound); // 圆角
    //pen.SetLineJoin(LineJoinMiterClipped); // 斜剪
    //pen.SetMiterLimit(20.0f); // 设置斜接限长
    graph.DrawLines(&pen, points, 3); // 画粗线
    graph.DrawLines(&redPen, points, 3); // 画细线