How can I use Getpixel() on not active window?

Hi,

Someone on here maybe can help my to create a code: I need to get a Color of Pixel from not active Window.

What do I wrong? (Visual Studio 2005, Win XP SP2):

DeclareFunction FindWindowLib"user32"Alias"FindWindowA" (ByVal lpClassNameAsString,ByVal lpWindowNameAsString)AsInteger

DeclareFunction GetPixelLib"gdi32" (ByVal hdcAsInteger,ByVal xAsInteger,ByVal yAsInteger)AsInteger

DeclareFunction GetDCLib"user32" (ByVal hwndAsInteger)AsInteger

Public dcAsInteger

Public WHDCAsInteger

Sub Main()

WHDC = FindWindow("Forge9MDIClass","SONY SOUND FORGE 9.0")

' it is Sample. Class and Window Name isCorrect. whdc <>0

dc = GetDC(WHDC) ' dc <>0

Static colrAs UInt32

colr = GetPixel(dc, 803, 720) ' on that step i got message "Arithmetic operation resulted in an overflow",

' and programmstop.

MsgBox(colr)

EndSub

Can someone help my? Sorry for bad english.

This code work. But so a can get a pixel only from active window:

dc = GetDC(0)

Static colrAs UInt32

colr = GetPixel(dc, 803, 720)

MsgBox(colr)

[2995 byte] By [Ruslan2000] at [2008-1-10]
# 1
It has nothing to do with the active window. Your declare statements are wrong. GetPixel() returns an UInt32, not an Integer. The other two return an IntPtr.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Why use the Windows API?

Code Snippet

Private Function GetPixelColor(ByVal X As Integer, ByVal Y As Integer) As Color

Dim Bmp As New Bitmap(1, 1)

Dim G As Graphics = Graphics.FromImage(Bmp)

G.CopyFromScreen(X, Y, 0, 0, New Size(1, 1))

GetPixelColor = Bmp.GetPixel(0, 0)

G.Dispose()

Bmp.Dispose()

End Function

JohnWein at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...