CreatePen

  HPEN CreatePen(fnPenStyle, nWidth, clrref)    
  int fnPenStyle;    
  int nWidth;    
  COLORREF clrref;    

The CreatePen function creates a logical cosmetic-pen having the specified style, width, and color. The pen may subsequently be selected into a device context and used to draw lines and curves.

Parameters

fnPenStyle

Specifies the pen style. It can be any one of the following values:

Value Meaning

PS_SOLID Creates a solid pen.
PS_DASH Creates a dashed pen. Valid only when the pen width is one or less in device untis.
PS_DOT Creates a dotted pen. Valid only when the pen width is one or less in device units.
PS_DASHDOT Creates a pen with alternating dashes and dots. Valid only when the pen width is one or less in device untis.
PS_DASHDOTDOT Creates a pen with alternating dashes and double-dots. Valid only when the pen width is one or less in device untis.
PS_NULL Creates a null pen.
PS_INSIDEFRAME Creates a solid pen. When this pen is used in any GDI drawing function that takes a bounding rectangle, the dimensions of the figure will be shrunk so that it fits entirely in the bounding rectangle, taking into account the width of the pen.

nWidth

Specifies the width of the pen (in logical units). If nWidth is zero, the pen is a single pixel wide, regardless of the current transform.

clrref

Specifies a color reference for the pen color.

Return Value

The return value is a handle that identifies a logical pen if the function is successful. Otherwise, it is 0.

Comments

Once an application creates a logical pen, it can select that pen into a device context by calling the SelectObject function. After a pen is selected into a device context, it can be used to draw lines and curves.

If the value specified by nWidth is zero, any line drawn with the created pen will always be a single pixel wide—regardless of the current transform.

If the value specified by nWidth is greater than 1, the fnPenStyle constant must be PS_NULL, PS_SOLID, or PS_INSIDEFRAME.

If the value specified by nWidth is greater than 1 and fnPenStyle is PS_INSIDEFRAME, the line associated with the pen is drawn inside the frame of all primitives except polygons and polylines.

If the value specified by nWidth is greater than 1, fnPenStyle is PS_INSIDEFRAME, and the color specified by clrref does not match one of the entries in the logical palette, Windows will draw lines using a dithered color. (Dithered colors are not allowed with solid pens.)

When an application no longer requires the pen, it should call the DeleteObject function and delete the pen from the device context.

See Also

CreatePenIndirect DeleteObject ExtCreatePen GetObject SelectObject