Nedd help with CPen.Create

Posted on 1999-11-25
Medium Priority
Last Modified: 2013-11-20
  I can't figure out why my createpen is failing. I'm trying to create a green pen with a width of 40 pixels. The create pen method keeps returning 0


  const int GRAPH_HEIGHT = 100;      
      CPen        pen;                              // Pen object
      CRect        rect;
      LOGBRUSH  logBrush ;

      CDC *pDC = GetDC();

      logBrush.lbStyle = PS_SOLID | PS_GEOMETRIC | PS_ENDCAP_SQUARE;

      logBrush.lbColor = RGB( 0, 255, 0 );
      logBrush.lbHatch = 0;
      //Create a green pen
      BOOL bResult = pen.CreatePen( logBrush.lbStyle, 40, &logBrush, 0, NULL );

      // Set the pen.
      pDC->SelectObject( &pen );

Question by:pipe
  • 2
  • 2

Author Comment

ID: 2234997
Edited text of question.
LVL 23

Accepted Solution

chensu earned 400 total points
ID: 2235005
logBrush.lbStyle = BS_SOLID;
logBrush.lbColor = RGB(0, 255, 0);
logBrush.lbHatch = 0;

BOOL bResult = pen.CreatePen(PS_SOLID | PS_GEOMETRIC | PS_ENDCAP_SQUARE, 40, &logBrush, 0, NULL);

Author Comment

ID: 2235022
I gave you another 100 points. I have one more little question first. Using the  PS_ENDCAP_FLAT |PS_ENDCAP_SQUARE flags doesnt seem to make the ends of the lines square or flat. Do you know why this is?

LVL 23

Expert Comment

ID: 2235036
"Windows 95 and Windows 98: The PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE, PS_ENDCAP_FLAT, PS_JOIN_BEVEL, PS_JOIN_MITER, and PS_JOIN_ROUND styles are supported only for geometric pens when used to draw paths."

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question