CreatePen (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function creates a logical pen that has the specified style, width, and color. The pen can subsequently be selected into a device context and used to draw lines and curves.

HPEN CreatePen( 
  int fnPenStyle, 
  int nWidth, 
  COLORREF crColor


[in] Specifies the pen style. It can be any one of the following values.
PS_SOLIDPen is solid.
PS_DASHPen is dashed.

This style is valid only when the pen width is one or less in device units.

PS_NULLPen is invisible.
[in] Specifies the width of the pen, in logical units.

If nWidth is zero, the pen is a single pixel wide, regardless of the current transformation.

CreatePen returns a pen with the specified width bit with the PS_SOLID style if you specify a width greater than one for the PS_DASH style.

[in] Specifies a color reference for the pen color.

Return Values

Handle to a logical pen indicates success. NULL indicates failure. To get extended error information, call GetLastError.


After 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 the nWidth parameter is zero, a line drawn with the created pen will always be a single pixel wide regardless of the current transformation.

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

User-specified endcap styles, such as PS_ENDCAP_ROUND, are not supported.

When you no longer need the pen, call the DeleteObject function to delete it.


OS Versions: Windows CE 2.0 and later.
Header: Windows.h.
Link Library: Coredll.lib.

See Also

CreatePenIndirect | DeleteObject | SelectObject | GDI Functions

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.