Как определить цвет определённой точки в окне с известным hWnd
Сделал через PrtScr, но это не нормально.
Private Declare Function GetPixel Lib "gdi32" (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
Private Sub Command1_Click()
a = GetPixel(GetDC(Me.hwnd), 100, 100) 'rgb
MsgBox (a)
End Sub
Private Declare Function GetPixel Lib "gdi32" (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
Private Sub Command1_Click()
a = GetPixel(GetDC(Me.hwnd), 100, 100) 'rgb
Debug.Print "RED="; RedFromRGB(a); "GREEN="; GreenFromRGB(a); "BLUE="; BlueFromRGB(a)
End Sub
' Paste these functions into the Declarations section
' of the Form or Code Module.
Private Function RedFromRGB(ByVal rgb As Long) _
As Integer
' The ampersand after &HFF coerces the number as a
' long, preventing Visual Basic from evaluating the
' number as a negative value. The logical And is
' used to return bit values.
RedFromRGB = &HFF& And rgb
End Function
Private Function GreenFromRGB(ByVal rgb As Long) _
As Integer
' The result of the And operation is divided by
' 256, to return the value of the middle bytes.
' Note the use of the Integer divisor.
GreenFromRGB = (&HFF00& And rgb) \ 256
End Function
Private Function BlueFromRGB(ByVal rgb As Long) _
As Integer
' This function works like the GreenFromRGB above,
' except you don't need the ampersand. The
' number is already a long. The result divided by
' 65536 to obtain the highest bytes.
BlueFromRGB = (&HFF0000 And rgb) \ 65536
End Function
Сейчас этот форум просматривают: SemrushBot, Yandex-бот и гости: 1