Solved

painting pixels in a dialog

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now