Hi guys, this is a repost - thanks volte force and divil for your help so far...
this code is not returning the correct colors from the desktop.. can anyone see what im doing wrong?
thanks
heres the code...
this code is not returning the correct colors from the desktop.. can anyone see what im doing wrong?
thanks
heres the code...
Code:
GDI Functions
Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
User32 Functions
Public Declare Function GetDesktopWindow Lib "user32.dll" Alias "GetDesktopWindow" () As IntPtr
Public Declare Function GetWindowDC Lib "user32.dll" Alias "GetWindowDC" (ByVal ptr As Int32) As IntPtr
Public Declare Function ReleaseDC Lib "user32.dll" Alias "ReleaseDC" (ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr
Public Function checkPixel(ByVal X As Integer, ByVal Y As Integer) As Integer
Dim hDC As IntPtr
Get Desktop hDC
hDC = GetWindowDC(GetDesktopWindow().ToInt32)
Get Pixel
checkPixel = GetPixel(hDC, X, Y)
Release Desktop hDC
ReleaseDC(GetDesktopWindow(), hDC)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As New Color()
Dim i As Integer
get color integer value
i = checkPixel(100, 50)
convert to color and display
c = Color.FromArgb(i)
MsgBox("Color = " & CStr(i) & " - " & c.R & ", " & c.G & ", " & c.B)
End Sub