我在 Windows 上使用 api(不是 gdi),我想知道如何做方形边缘线。
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
我当前的行输出:
我想要这一行:
谢谢,有代码
最佳答案
您可以修改用于绘制线条的笔样式,特别是 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);
关于c++ - 如何设置方边线api窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36808946/