I am stupid, please help me with Getpixel

I am stupid, please help me with Getpixel

Post by Steve » Wed, 25 Jun 2003 01:56:39



I am trying to use getpixel to read the color of a pixel
in an external application.  I open the application using
Shell, and then get the application's window handle. From
there unfortunately, I can't seem to either a) use
showwindow or setwindowpos to bring that window to the
front, or b) even if I manually restore the window, use
getpixel to read pixel color.  This doesn't seem like too
esoteric an application and yet despite a weekend of
pouring through books and what seems like the whole MSDN
library I can't find any code that does this.  I also
can't find any code that simply reads a pixel color off
the desktop.  I'm going crazy trying to figure this out
myself and would appreciate any help.

Thank You

 
 
 

I am stupid, please help me with Getpixel

Post by Mike D Sutto » Wed, 25 Jun 2003 02:18:57


Hi Steve,

Quote:> I am trying to use getpixel to read the color of a pixel
> in an external application.  I open the application using
> Shell, and then get the application's window handle. From
> there unfortunately, I can't seem to either a) use
> showwindow or setwindowpos to bring that window to the
> front, or b) even if I manually restore the window, use
> getpixel to read pixel color.  This doesn't seem like too
> esoteric an application and yet despite a weekend of
> pouring through books and what seems like the whole MSDN
> library I can't find any code that does this.

Depending on which OS you're using, this can be quite a tricky task (Since
too many developers misused it in the past..) however you'll find a pretty
good example of how to do this properly over on Http://www.mvps.org/vb/ ,
look for the "ForeFore.zip" demo.

Quote:> I also
> can't find any code that simply reads a pixel color off
> the desktop.  I'm going crazy trying to figure this out
> myself and would appreciate any help.

To read a pixel off the desktop, use this method:

'***
Private Declare Function GetPixel Lib "gdi32" _
    (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" _
    (ByVal hWnd As Long, ByVal hdc As Long) As Long

Private Function GetDeskPixel( _
    ByVal inX As Long, ByVal inY As Long) As Long
    Dim DeskWnd As Long, DeskDC As Long

    DeskWnd = GetDesktopWindow()
    DeskDC = GetDC(DeskDC)
    GetDeskPixel = GetPixel(DeskDC, inX, inY)
    Call ReleaseDC(DeskWnd, DeskDC)
End Function
'***

It seems like somewhat clunky behaviour for an application to fore a window
to the foreground to capture a pixel though, what are you trying to do with
this?
Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -

WWW: Http://www.mvps.org/EDais/

 
 
 

1. Am I stupid or is Adobe stupid?

After trying to figure out why my web pictures look so bad, I found yet
another thing that makes me wonder what the heck Adobe is thinking.

I have PS7 set to work in the Adobe RGB working space through the color
preferences panel.  I open up my Adobe RGB files, *CONVERT* them to sRGB,
then "Save for the Web", but Photoshop still saves these files in the Adobe
RGB color space because that is my working space!!  Thus, my web images look
like garbage.  If a file is converted to be sRGB, shouldn't Adobe think that
it should be saved out as sRGB, regardless of your working space??
Especially if you are "saving for web"???  Geez...

Setting my working space to sRGB fixes the problem, but I still think it's
stupid that you should have to do this.

2. 3d clipping problem

3. i am too stupid for that - help me

4. 3D Competition Extended

5. Please HELP Newbie with STUPID Question

6. New Pointing Device

7. PLease help with my stupid questions!!

8. Illustrator / problems offsetting path

9. Please help me (I must be stupid)

10. Stupid Beginner Question, but I am stuck!

11. Maybe I am just stupid

12. Am I just stupid or what?

13. Boy, am I stupid?