Visual C++ and MFC Fundamentals Chapter 8 GDI Orientation and Transformations
The Win32 API provides the LOGPEN structure that you can use to individually specify
each characteristics of a pen. The LOGPEN structure is created as follows:
typedef struct tagLOGPEN {
UINT lopnStyle;
POINT lopnWidth;
COLORREF lopnColor;
} LOGPEN, *PLOGPEN;
To use this structure, declare a variable of LOGPEN type or a pointer. Then initialize
each member of the structure. If you do not, its default values would be used and the line
not be visible.
The lopnStyle argument follows the same rules we reviewed for the nPenStyle argument
of the second constructor and the CreatePen() method.
The lopnWidth argument is provided as a POINT or a CPoint value. Only the POINT::x
or the CPoint::x value is considered.
The lopnColor argument is a color and can be provided following the rules we reviewed
for colors.
After initializing the LOGPEN variable, call the CPen::CreatePenIndirect() member
function to create a pen. The syntax of the CreatePenIndirect() method is:
BOOL CreatePenIndirect(LPLOGPEN lpLogPen);
The LOGPEN value is passed to this method as a pointer. After this call, the new pen is
available and can be selected into a device context variable for use. Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPen NewPen;
LOGPEN LogPen;
LogPen.lopnStyle = PS_SOLID;