Getpixel help. Thanks.

Started by
2 comments, last by carloshathcock 17 years ago
I use visual basic.net 2003 and i would like to read the HEX pixel value of a pixel under my mouse anywhere on my computer (not just in my program). I did this is visual basic 6 but i can not do it in .net. I am using windows API but it will not read the colors at all. Can someone please give me an example of how to read the hex pixel color? I know it is simple, i just cant seem to do it. :( Thanks.
Advertisement
I really do not understand. Here are my declared functions form the windows API.


Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long


Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long


Here is the code i am using in a timer:


Dim screen As Long = GetDC(0)
Me.Text = Hex(GetPixel(screen, Cursor.Position.x, Cursor.Position.y))

It is like the GetPixel Command is doing nothing. When a set me.text to the screen = GetDC(0) a bunch of numbers keep flowing so it seems the GetDC is working. Why is GetPixel not working?
I have also tried using GetDesktopWindow and using the handel it returns in the GetDC() API. GetDC() still works but GetPixel seems to be not be doing anything.
I do not understand what i am doing wrong. I know that i must be doing something wrong, but i do not understand what. Declarations in the GDI library have been tested for years so I know it is my error but i can not put on finger on what i am doing wrong. Please help.

This topic is closed to new replies.

Advertisement