Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Dim pt As POINTAPI
Private Sub Timer1_Timer()
Dim hdc As Long, Col As Long
Dim R As Long, g As Long, b As Long
hdc = GetDC(0)
GetCursorPos pt
cor = GetPixel(hdc, pt.x, pt.y)
GetRGB cor, R, g, b
ReleaseDC Me.hwnd, hdc
Text1.Text = "R: " & R & " G:" & g & " B:" & b
End Sub
'得到一种颜色的r,g,b值
Private Sub GetRGB(ByVal Col As Long, ByRef R As Long, ByRef g As Long, ByRef b As Long)
R = Col Mod 256
g = ((Col And &HFF00&) \ 256&) Mod 256&
b = (Col And &HFF0000) \ 65536
End Sub