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?
In general you should adhere to the documented API, otherwise you risk relying on OS version specific behaviour.
The
ExtCreatePenrestrictions you describe (e.g, noPS_DASHwithPS_GEOMETRIC) only apply to Win9x, not WinNT, so on NT/2000/XP your ‘fat, dashed geometric pen’ shouldn’t be a problem. Also note thatPolylinehas some limitations on Win9x.If you want dashed lines, I’d suggest using
PS_USERSTYLEso that you control the lengths of the dashes and gaps, rather than relying on whatever defaultPS_DASHgives you.