Option Explicit
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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc 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
Dim dc As Long
Dim l As LongPrivate Sub Form_Load()
dc = GetDC(0)
End SubPrivate Sub Form_Unload(Cancel As Integer)
ReleaseDC dc, 0
End SubPrivate Sub Timer1_Timer()
Dim p As POINTAPI
GetCursorPos p
l = GetPixel(dc, p.x, p.y)
Picture1.BackColor = l
If l < 0 Then
l = l + 2 ^ 31
End If
Dim r As Byte
Dim g As Byte
Dim b As Byte
r = l Mod 256
g = (l \ 256) Mod 256
b = (l \ 65536) Mod 256
Me.Caption = Str(r) & ":" & Str(g) & Str(b) & " -- " & Hex(r) & ":" & Hex(g) & Hex(b)
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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc 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
Dim dc As Long
Dim l As LongPrivate Sub Form_Load()
dc = GetDC(0)
End SubPrivate Sub Form_Unload(Cancel As Integer)
ReleaseDC dc, 0
End SubPrivate Sub Timer1_Timer()
Dim p As POINTAPI
GetCursorPos p
l = GetPixel(dc, p.x, p.y)
Picture1.BackColor = l
If l < 0 Then
l = l + 2 ^ 31
End If
Dim r As Byte
Dim g As Byte
Dim b As Byte
r = l Mod 256
g = (l \ 256) Mod 256
b = (l \ 65536) Mod 256
Me.Caption = Str(r) & ":" & Str(g) & Str(b) & " -- " & Hex(r) & ":" & Hex(g) & Hex(b)
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货