Solved

Selecting a dotted pen?

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

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
Change owner from userA to server Local Administrators 7 66
move a line in eclipse 3 107
tripleUp challenge 7 86
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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