S
Stacey
I've been trying for the last couple of days to read some pixel values
from a window of an independent application, but, even though I got
close, I just can't figure the last part out.
I am able to read the coordinates (GetWindowRect), but the GetPixel
always returns some weird incremental value. Is there something wrong
with my declarations, or do I need a different handle to access the
pixels of a window, as opposed to just the coordinates?
Here's the code I'm using:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim proctest As Process()
Dim hMW As IntPtr
Dim pix, xy, t, r, b, l As Long
Dim wR As New RECT
proctest = Process.GetProcessesByName("[process name]")
hMW = proctest(0).MainWindowHandle
GetWindowRect(hMW, wR) ' the data returned here is correct
Debug.Write(wR.left & ", " & wR.top & ", " & wR.right & ", " &
wR.bottom)
For xy = 50 To 100
pix = GetPixel(hMW.ToInt64, xy, xy)
Debug.Write(xy & ":" & Hex(pix) & vbCrLf)
' here I always get 32FFFFFFFF to 64FFFFFFFF...
Next
End Sub
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect"
(ByVal hWnd As IntPtr, ByRef rect As RECT) As IntPtr
Declare Function GetPixel Lib "gdi32" (ByVal hWnd As Long, ByVal X As
Integer, ByVal Y As Integer) As Long
from a window of an independent application, but, even though I got
close, I just can't figure the last part out.
I am able to read the coordinates (GetWindowRect), but the GetPixel
always returns some weird incremental value. Is there something wrong
with my declarations, or do I need a different handle to access the
pixels of a window, as opposed to just the coordinates?
Here's the code I'm using:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim proctest As Process()
Dim hMW As IntPtr
Dim pix, xy, t, r, b, l As Long
Dim wR As New RECT
proctest = Process.GetProcessesByName("[process name]")
hMW = proctest(0).MainWindowHandle
GetWindowRect(hMW, wR) ' the data returned here is correct
Debug.Write(wR.left & ", " & wR.top & ", " & wR.right & ", " &
wR.bottom)
For xy = 50 To 100
pix = GetPixel(hMW.ToInt64, xy, xy)
Debug.Write(xy & ":" & Hex(pix) & vbCrLf)
' here I always get 32FFFFFFFF to 64FFFFFFFF...
Next
End Sub
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect"
(ByVal hWnd As IntPtr, ByRef rect As RECT) As IntPtr
Declare Function GetPixel Lib "gdi32" (ByVal hWnd As Long, ByVal X As
Integer, ByVal Y As Integer) As Long