Solved

painting pixels in a dialog

Posted on 1998-09-28
3
289 Views
Last Modified: 2013-11-20
I am trying to paint individual pixels in a dialog on mouse messages.  I have a picture control in the dialog of type rectangle where I am displaying bitmaps.  I want to be able to paint over part of these bitmaps by directly setting pixels in the dialog.  I have tried simple code like this:

// get a device context for the rectangle area
CWnd* pWnd = GetDlgItem(IDC_RECTANGLE_CONTROL);
CDC* pDC = pWnd->GetDC();

// now paint the pixel white where the mouse is
COLORREF colorOutline = 0x00ffffff;
pDC->SetPixelV(point,colorOutline);

// release the device context
pWnd->ReleaseDC(pDC);

Am I missing something??  this seems like a simple task.
0
Comment
Question by:klingej
[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
3 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 50 total points
ID: 1322653
The painting does work but you don't see the results. Am I right?

Your picture control is repainting itself over your pixels, and then again maybe the dialog's background also repaints over them.

Two solutions:

1) Make it so that your picture control won't repaint itself.  That solution can almost already be discarded because I'm sure you placed a bitmap there so it can be used.

2) "Remember" the pixels you set and repaint them on every OnPaint.  Note that your drawing over a child window and you want to draw your pixels after that window.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1322654
Yes, you're missing something. Your question is very incomplete: why doesn't your code work? What problem are you observing?  Exactly what did you expect the code you tried to do, and what did it really end up doing?

It's very hard to tell your intentions, since your text is about painting in the dialog but your code is about painting inside a control.  Which is it that you want to do?

In the meantime, I'd guess that you're complaining because your painting code didn't have any visible result.

The most likely cause for this is the fact that you're not properly painting the control. If you want to change the way a control paints, you should subclass the control and intercept the WM_PAINT message.  You should let the control's original implemnentation perform its regular painting, and then paint waht you want yourself before returning from your message handler.

What you're doing now is aynchronously painting into the control's window. The control may repaint itself at any time, and overpaint what you've changed.

The second most likely problem involves the way you find the point you're trying to paint. If you don't do your math right, or if you've called a function that returns screen-coordinates instead of client coordinates, your code will still paint--but its results will be clipped because they'll fall outside of the control's window.

B ekiM
0
 

Author Comment

by:klingej
ID: 1322655
I ended up solving my solution in a different way, but your answer was workable... thanks.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fizzArray  challenge 1 117
zeroMAx challenge 20 135
Line meaning 9 99
Remove Password Protection from pdf (with password) using an command line executable 5 105
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.

710 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