Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

 

 

 


' 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

Posted

robby - thanks.. but that doesnt work.. the getPixel returns an integer value, but it doesnt convert to the correct color

 

maybe the way im trying to convert it is wrong?

 

thanks

Posted

thanks robby... okay one value that comes up is

 

14610415

 

but it seems to come up no matter what the pixel color is at the X,Y coordinates..

 

you could cut and paste my above code into a form if you need the example.. thats all the code i have..

 

thanks

danny.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...