65.1.1 Cosmetic Pens

A cosmetic pen is used by applications that require lines of fixed width. For example, the hidden-, section-, center-, and dimension-lines in a drawing generated by a CAD application should always measure .015 to .022 inches wide—regardless of the scale factor. These lines would be drawn using a cosmetic pen.

Cosmetic pens have three attributes: width, style, and color. The width attribute specifies the pens width in device units. (For more information about device units, see Chapter 73, “Coordinate Spaces and Transformations.”

The current version of Windows limits the width of cosmetic pens to a single pixel; however, future versions will remove this limitation.

The style attribute identifies the line pattern that appears when a particular cosmetic pen is used. There are seven predefined styles. The following illustration shows each one:

The Seven Predefined Line-Styles

The last style, inside-frame, is identical to the solid style for cosmetic pens. However, when this style is specified for a geometric pen that is wider than a single pixel and one of the drawing functions which draws a border around a filled object is called, Windows draws the border inside of the objects frame, replacing the fill pattern along the border with the pen pattern. Using this style, an application can guarantee that an object will maintain its specified dimensions, regardless of the geometric pen width.

In addition to the seven predefined styles, there is an eighth style that is user (or application) defined. The user-defined style can be used to generate lines with a customized series of dashes and dots. You can use the ExtCreatePen function to create a cosmetic pen with this style. You can use the CreatePen, CreatePenIndirect, or ExtCreatePen functions to create a pen with the predefined styles.

The color attribute identifies the pen's color. You can create a cosmetic pen with a unique color by storing the RGB triplet that specifies the desired color in a COLORREF data structure and passing this structures address to the CreatePen, CreatePenIndirect, or ExtCreatePen functions. (The stock pens are limited to colors of black and white.) For more information about RGB triplets and color, see Chapter 70, “Colors and Color Palettes.”