Getting a pixel from a window 
Author Message
 Getting a pixel from a window

Yo all.

First of all, I've had enough of asking really basic questions
and wasting your time in the process of replying.  Doesn't
there exist an FAQ with all the most obvious VC++ questions the
beginner VC++ programmer is likely to make ? (how do you load
a bitmap on screen, how do you refresh a window, how do you allow
for different child documents etc).

Just in case there isn't ...

How do I extract the colour of a pixel, say (25,45), from
an MDI child.  I obviously want to do this in a mouse handler.

Cheers
JP

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 25 Jun 2002 03:00:00 GMT  
 Getting a pixel from a window
You can use GetPixel() member of CDC, and all derived classes such
CClientDC. GetPixel() takes a CPoint argument (location of the pixel) and
returns RGB value of that pixel.
So if you want to test pixel on left mouse doubleclick you could do
something like this:

(you can also get this sample in a more practical example from "Programming
Windows with MFC" by Jeff Prosise)
void CMainWindow::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    // check the pixel color
    CClientDC dc(this);

    if(dc.GetPixel(point) == RGB(0,0,0))
        // do something with that pixel

Quote:
}

Adasiek
Quote:

> Yo all.

> First of all, I've had enough of asking really basic questions
> and wasting your time in the process of replying.  Doesn't
> there exist an FAQ with all the most obvious VC++ questions the
> beginner VC++ programmer is likely to make ? (how do you load
> a bitmap on screen, how do you refresh a window, how do you allow
> for different child documents etc).

> Just in case there isn't ...

> How do I extract the colour of a pixel, say (25,45), from
> an MDI child.  I obviously want to do this in a mouse handler.

> Cheers
> JP

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Tue, 25 Jun 2002 03:00:00 GMT  
 Getting a pixel from a window
You can check out my MVP Tips site for some interesting essays. They
are not FAQs, and there's only a couple dozen. However, doing a FAQ
for every newbie question would generate a FAQ file as long as the
MSDN documentation, and you wouldn't want to download it.

GetPixel is the answer that will probably work. Note the careful
wording. The performance could be so abysmal that you may want some
other means. Without knowing the nature of your problem, performance
constraints, size of bitmap, etc. it is hard to determine what the
answer is. It is not obvious, btw, that you want to do this in a mouse
handler--there's lots of reasons to get pixels from views or screens.
But your reason, as given, suggests you want to display it, such as in
the status bar or someplace, and GetPixel performance is probably
adequate for this purpose.
                                joe

Quote:

>Yo all.

>First of all, I've had enough of asking really basic questions
>and wasting your time in the process of replying.  Doesn't
>there exist an FAQ with all the most obvious VC++ questions the
>beginner VC++ programmer is likely to make ? (how do you load
>a bitmap on screen, how do you refresh a window, how do you allow
>for different child documents etc).

>Just in case there isn't ...

>How do I extract the colour of a pixel, say (25,45), from
>an MDI child.  I obviously want to do this in a mouse handler.

>Cheers
>JP

>Sent via Deja.com http://www.deja.com/
>Before you buy.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Wed, 26 Jun 2002 03:00:00 GMT  
 Getting a pixel from a window
P.S.,
P.S. the point of my last message, which may not be obvious, is that
this newsgroup is the real-time FAQ, and we expect people to ask these
kinds of questions!
                                joe

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Wed, 26 Jun 2002 03:00:00 GMT  
 Getting a pixel from a window
As for FAQ, I don't think getting a pixel from a mouse-click would qualify.
However, MSDN is probably the best source for VC++ and MFC FAQ.


Thu, 27 Jun 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Getting The Current Screen Resoultion In Pixels?

2. Getting Pixels From Bitmaps

3. getting the length of a text in pixels

4. Getting Twips Per Pixel

5. autoscrolling pixel by pixel RichEditCtrl

6. Scrolling text, pixel by pixel in a RichEditView

7. Pixel Plot 4 Borland C++ for Windows

8. Drawing pixels in a window

9. The size of a window in pixels

10. Get image pixels using Video For Window(VFW)

11. how align by step of 10 pixels my window when i move it

12. Getting window handle without matching window caption text

 

 
Powered by phpBB® Forum Software