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
Solved

painting pixels in a dialog

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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
only14 challenge 19 81
Execute multiple curl cmds with sleep and send output to file 10 104
sumHeights2  challenge 7 117
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 104
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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