Solved

painting pixels in a dialog

Posted on 1998-09-28
3
280 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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. …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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