Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Selecting a dotted pen?

Posted on 2002-04-12
4
Medium Priority
?
725 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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

926 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