Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

painting pixels in a dialog

Posted on 1998-09-28
3
Medium Priority
?
303 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 100 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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: 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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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