-1

我在windows(不是gdi)上使用api,我想知道如何做方边线。

MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);

我当前的线路输出:

电流输出

我想要这条线:

期望的输出

谢谢,有代码

4

2 回答 2

2

您可以修改用于绘制线条的笔样式,特别PS_ENDCAP_SQUARE是将该笔选择到设备上下文中,阅读CPen的文档:

 LOGBRUSH logBrush;//you need to use LOGBRUSH structure to specifiy brush attributes of the pen when the pen has PS_GEOMETRIC style
 logBrush.lbStyle = BS_SOLID;
 logBrush.lbColor = RGB(255,0,0);
 CPen pen( PS_GEOMETRIC |  PS_ENDCAP_SQUARE,10,&logBrush);//creates a pen with a square end caps and width of 10 pixels

 SelectObject(hdc,pen.GetSafeHandle());//select the above pen into the device context
 MoveToEx(hdc,x1,y1,NULL);
 LineTo(hdc,x2,y2);
于 2016-04-23T10:10:01.460 回答
-1

那个工作!谢谢 !请参阅以下代码:

         LOGBRUSH logBrush;
         logBrush.lbStyle = BS_SOLID;
         logBrush.lbColor = RGB(R,G,B);
         HPEN border = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_SQUARE | PS_SOLID | PS_JOIN_MITER, size_, &logBrush, 0, nullptr);

         SelectObject(hdc, border);
         MoveToEx(hdc, x1, y1, nullptr);
         LineTo(hdc, x2, y2);

         DeleteObject(border);

于 2016-04-23T10:38:45.297 回答