Solved

Selecting a dotted pen?

Posted on 2002-04-12
4
719 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
Question regarding Copy/Paste 16 96
Perl Awk Need Help 3 119
Pressing cancel button with C# UI Automation 3 70
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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