Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm trying to draw a thick line with CPen. The problem is that the ends are rounded. The lines look like sausages! Is there a way to make the end straight, so that it has right-angles, and effectively looks like a rectangle.

What I have tried:

Here is my code:

// CDC* m_CDC;
CPen* pen = new CPen;
int colour = RGB(0, 255, 0);
pen->CreatePen(PS_SOLID, 100000, (COLORREF)colour);
m_CDC->SelectObject(pen);
Posted
Updated 11-May-17 6:23am
v2

Have you tried ExtCreatePen with the PS_ENDCAP_FLAT flag set? There are a few other flags for the function that might be helpful. I recommend reading the docs for it.
 
Share this answer
 
Comments
Jackie Lloyd 11-May-17 11:51am    
Before I saw your message I just tried CreatePen(PS_SOLID | PS_ENDCAP_FLAT, ... which made no difference. I'll try ExtCreatePen(), thank you.
Thank you Rick, I did almost as you said, but you definitely set me in the right direction. I couldn't use the ExtCreatePen as it returns an HPEN, and I need a CPen. (I tried to find a way to convert but failed, maybe there is one?). So I used the other version of CreatePen:

LOGBRUSH lbrush;
lbrush.lbColor = colour;
lbrush.lbStyle = BS_SOLID;
pen->CreatePen(PS_SOLID | PS_GEOMETRIC | PS_ENDCAP_SQUARE, 500000, &lbrush);
m_CDC->SelectObject(pen);


However, I've no idea why the following didn't flatten the ends:
pen->CreatePen(PS_SOLID | PS_GEOMETRIC | PS_ENDCAP_FLAT, 500000, (COLORREF)colour);
m_CDC->SelectObject(pen);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900