HPEN CreatePenIndirect(lplgpn) | |||||
LOGPEN FAR* lplgpn; | /* address of structure with pen data | */ |
The CreatePenIndirect function creates a pen that has the style, width, and color given in the specified structure.
lplgpn
Points to the LOGPEN structure that contains information about the pen. The LOGPEN structure has the following form:
typedef struct tagLOGPEN { /* lgpn */
UINT lopnStyle;
POINT lopnWidth;
COLORREF lopnColor;
} LOGPEN;
For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.
The return value is the handle of the pen if the function is successful. Otherwise, it is NULL.
Pens whose width is greater than 1 pixel always have the PS_NULL, PS_SOLID, or PS_INSIDEFRAME style.
If a pen has the PS_INSIDEFRAME style and a color that does not match a color in the logical color table, the pen is drawn with a dithered color. The PS_INSIDEFRAME style is identical to PS_SOLID if the pen width is less than or equal to 1.
When it has finished using a pen created by CreatePenIndirect, an application should remove the pen by using the DeleteObject function.
The following example fills a LOGPEN structure with values defining a solid red pen 10 logical units wide, uses the CreatePenIndirect function to create this pen, selects the pen into a device context, and then uses the pen to draw a rectangle:
LOGPEN
lp; HPEN hpen, hpenOld; lp.lopnStyle = PS_SOLID; lp.lopnWidth.x = 10; lp.lopnWidth.y = 0; /* y-dimension not used */ lp.lopnColor = RGB(255, 0, 0); hpen = CreatePenIndirect(&lp); hpenOld = SelectObject(hdc, hpen); Rectangle(hdc, 10, 10, 100, 100);