Solved

Selecting a dotted pen?

Posted on 2002-04-12
4
716 Views
Last Modified: 2013-11-20
How to obtain a dotted pen for drawing in a device context?

this is my base code:

CRect rect(40,40,240,180);
CPen pen;
pen.CreatePen(PS_DOT, 1, RGB(0x80, 0x80, 0x80));
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->Rectangle(rect);
pDC->SelectObject(pOldPen);

but the PS_DOT style is not what i want.
I realise that with this style, the dots and spaces of the line are more than one pixel large. I want a real dotted line, meaning the color changes every pixel.

i also tried PS_ALTERNATE, but it doesnt work either.
i also tried with PS_USERSTYLE and an array DWORD Style[2] = {1,1};
but it is not clear from the MSDN how this should work.
I tried several possibilites, but all give either a solid pen or a transparent.

Does anybody out there know how to get that dotted pen??
Please help.
0
Comment
Question by:scrontch
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6938484
Gives me a green dotted line.

LOGBRUSH brush = {BS_SOLID, RGB(0,0xff,0), NULL};
HPEN hPen = ExtCreatePen(PS_ALTERNATE|PS_COSMETIC, 1, &brush, 0, NULL);
::SelectObject(hDC, hPen);
::MoveToEx(hDC, 10,50, NULL);
::LineTo(hDC, 120,120);

But note that PS_COSMETIC is not supported on Win95


0
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 100 total points
ID: 6938486
BTW you can easily get a nice dotted rectange with DrawFocusRect?
0
 
LVL 2

Author Comment

by:scrontch
ID: 6941326
Well, that first tipp doesn't work on my system!
Gives me a solid black line!
I use this in my CView::OnDraw function, where i replaced
hDC with pDC->m_hDC, where pDC is the pointer to CDC passed to the function.
I'm using Win98.

But your second post is exactly what i was looking for, since all i want to do is draw a dotted rectangle.
Thank you.

I'll leave the question open for some more days, to see if someone finds a solution for drawing dotted lines (just for interest).
0
 
LVL 2

Author Comment

by:scrontch
ID: 6950838
Thanks again.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 63
isEverywhere  challenge 19 64
Execute multiple curl cmds with sleep and send output to file 10 80
mapAB Challlenge 35 85
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now