Does anyone have some code that would take a one pixel screen shot of the area the mouse is over, then determine the color of that pixel... could someone write me the code or even has just a part of it
Thnx in advance
Printable View
Does anyone have some code that would take a one pixel screen shot of the area the mouse is over, then determine the color of that pixel... could someone write me the code or even has just a part of it
Thnx in advance
use the GetPixel API, it returns the Red, Green and Blue value of a single pixel at specified co-ordinates - which you can use as the mouse x and y :)
This is the API declaration...
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
what do we fill in hdc?
the handle to the device context that you want to use.
i.e.
Form.hDC
but the problem I am having with this method is that I would like to get the actual screen pixel there. This method will not do that if the object whose device context is being called is behind another object. I would like for the pixel value returned to be that of the frontmost object.
Is that possible?
Add the following to a Form with a Timer. Set it's Interval to 1 (or a higher number).
VB Code:
Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Sub Timer1_Timer() Dim dc As Long, pt As POINTAPI GetCursorPos pt dc = GetWindowDC(GetDesktopWindow) colour = GetPixel(dc, pt.x, pt.y) Me.BackColor = colour End Sub
i think GetWindowDC(0) will get the desktop dc so you dont need GetDesktopWindow