Solved

Selecting a dotted pen?

Posted on 2002-04-12
4
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

623 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