
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/