使用不受支持的 Win32 GDI 笔模式有问题吗?
MSDN 文档(在某种程度上)清楚地说明了关于 GDI 笔的以下两个事实:
装饰笔(通过 CreatePen 或 ExtCreatePen w/ PS_COSMETIC 创建)必须为 1 单位 宽(好吧,<= 1,但我们不要这样做) .
几何(ExtCreatePen w/ PS_GEOMETRIC)笔必须是实心的(仅限 PS_SOLID,无 PS_DASH 等)。 然而,他们可以画更粗的线。这在我上面放置的链接中清楚地记录为仅 9x 限制(我很愚蠢)。 为了我的辩护,我的代码中的(坏的)评论和(破碎的)逻辑让我相信事实并非如此。 其他一些 Google 搜索文章必须仅考虑 Windows 9x。
为什么我可以违反这些规则并让 GDI 愉快地用这些笔进行绘图?
我可以创建粗体(例如,宽度 = 10) )化妆笔和虚线几何笔。 哎呀,我可以创造一支粗的虚线几何笔!
这些笔似乎通常工作正常。 我见过的唯一问题是在折线中,当我传递非常大的点数组时 - 它渲染线条的速度非常慢。 然而,Polyline 通常在大型数组中表现得很奇怪 - 它只是在使用坏笔时表现不同。 (我的其他折线问题可能是另一个问题...)
使用宽化妆笔或带图案的宽几何笔是否安全?
The MSDN documentation is (somewhat) clear about the following two facts about GDI Pens:
A Cosmetic pen (create via CreatePen or ExtCreatePen w/ PS_COSMETIC) must be 1 unit wide (well, <= 1, but let's not go there).
A Geometric (ExtCreatePen w/ PS_GEOMETRIC) pen must solid (PS_SOLID only, no PS_DASH, etc). They can, however, draw fatter lines.This is clearly documented in the link I put above as only a 9x restriction (I'm dumb). To my defense (bad) comments and (broken) logic in my code led me to believe otherwise. Some other googled articles must have been written concidering only Windows 9x.
Why can I voilate these rules and have GDI happily draw with these Pens?
I can create fat (width = 10, for example) cosmetic pens and dashed Geometric pens. Heck, I can create a fat, dashed geometric pen!
These Pens seem to work fine usually. The only problem I've seen is in Polyline when I pass very large arrays of points - it renders the lines very slowly. However, Polyline is acting strangely with large arrays in general - it justs acts differently with the bad pens. (my other polyline problems may be another question...)
Is it ever safe to use wide Cosmetic pens or wide Geometric with patterns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您应该遵守记录的 API,否则您将面临依赖操作系统版本特定行为的风险。
您描述的
ExtCreatePen
限制(例如,没有PS_DASH
和PS_GEOMETRIC
)仅适用于 Win9x,不适用于 WinNT,因此在 NT/2000/XP 上您的“粗的、虚线的几何笔”应该不成问题。 另请注意,Polyline
有一些限制在Win9x上。如果您想要虚线,我建议使用
PS_USERSTYLE
以便控制虚线和间隙的长度,而不是依赖PS_DASH
为您提供的任何默认值。In general you should adhere to the documented API, otherwise you risk relying on OS version specific behaviour.
The
ExtCreatePen
restrictions you describe (e.g, noPS_DASH
withPS_GEOMETRIC
) only apply to Win9x, not WinNT, so on NT/2000/XP your "fat, dashed geometric pen" shouldn't be a problem. Also note thatPolyline
has some limitations on Win9x.If you want dashed lines, I'd suggest using
PS_USERSTYLE
so that you control the lengths of the dashes and gaps, rather than relying on whatever defaultPS_DASH
gives you.