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); 上面代码结果是,跟该属性没有设置时候没有任何区别。
所以,有请知道的大虾告诉小弟,这个属性到底是用来干什么的
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); 上面代码结果是,跟该属性没有设置时候没有任何区别。
所以,有请知道的大虾告诉小弟,这个属性到底是用来干什么的
解决方案 »
- MSCOMM 接收数据超时该如何判断?
- openprocess 使用
- c++学的差不多了,现在是学先mfc好还是直接学dotnet?
- 请问在API中...锁定互斥量的函数是什么?
- 如何解决这个问题:程序监听一个文件是否被另一个程序是否修改,如果修改则启动程序进行上传文件到服务器,否则程序挂起。
- 如何使用WINSOCK中的RECV函数?
- 如何最小化DOS程序!
- 这个错误怎么办?
- 256色BMP图,想把颜色表中(123,123,123)的颜色,改成黑色,怎么办?
- c++与vc++的关系
- 控件中添加stock属性,比如Font,在开发模式下,想修改这个属性,结果出错!
- WinINet的错误代码的含义?
有的帮帮我 我邮箱 [email protected]
自定义的是跟属性没有关系的,属性的设置是GDI+默认的几种样式
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);
}
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);
}
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); // 画细线