c++ - 如何设置方边线api窗口

标签 c++ c api line square

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

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

我当前的行输出:

Current output

我想要这一行:

Desired output

谢谢,有代码

最佳答案

您可以修改用于绘制线条的笔样式,特别是 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/

相关文章:

c++ - 使用 gSoap 的异步、确认、点对点连接

c++ - 从只允许访问带索引的 vector 的对象创建 vector 包装器

c++ - Trie 中的最短路径

c++ - 在 C++ 中指向 this 的指针

c - 搜索有序和无序链表

c - 全局变量未正确递增

c - 如何计算字符串中的字符数(如果没有占用所有空间)

javascript - 当使用 www 时,我没有得到 api 结果,如果没有 www 使用,我会得到它们

javascript - 错误 : No QueryClient set, 使用 QueryClientProvider 设置一个,但我做到了

c++ - 同步和异步 API