How to get the Pixel color outside your form
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 'Graphics - How to get the Pixel color outside your form 'The picture box will be painted with the color of the pixel that found 'under the mouse cursor (no matter if the mouse cursor is inside or outside your form). 'The text box will show the color or Hex value. 'Add a Timer, a Picture Box and a Text Box to your form and set the Timer Interval property to 10. Declare Function CreateDC& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, _ ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Any) Declare Function DeleteDC& Lib "gdi32" (ByVal hdc As Long) Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Type POINTAPI x As Long y As Long End Type Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Dim z As POINTAPI Private Sub Timer1_Timer() Call GetCursorPos(z) screendc = CreateDC("DISPLAY", "", "", 0&) Text1 = Hex(GetPixel(screendc, z.x, z.y)) Picture1.BackColor = GetPixel(screendc, z.x, z.y) Call DeleteDC(screendc) End Sub |