I am stupid, please help me with Getpixel 
Author Message
 I am stupid, please help me with Getpixel

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



Sat, 10 Dec 2005 00:56:39 GMT  
 I am stupid, please help me with Getpixel
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/



Sat, 10 Dec 2005 01:18:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

2. I am stupid but pleez help me

3. What am I doing wrong with GetPixel?

4. Please, please help, I am desperated...:(

5. PLEASE, PLEASE HELP, am I going MAD - Generating Totals

6. Am I that stupid ?

7. Am I too stupid to program VBA?

8. How stupid am I being

9. How stupid am I being?

10. Am I stupid or is it VB? [Recordsets]

11. Am I Stupid ???

12. Am I Stupid ?...

 

 
Powered by phpBB® Forum Software