VB获取鼠标位置的颜色值
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VB获取鼠标位置的颜色值:
界面如下:
代码如下:
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long ‘API
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
Dim a As POINTAPI, Myhwnd As Long, MyDC As Long, r1 As Long GetCursorPos a
MyDC = GetDC(Myhwnd)
r1 = GetPixel(MyDC, a.x, a.y)
If r1 = -1 Then
BitBlt Picture1.hdc, 0, 0, 1, 1, MyDC, a.x, a.y, vbSrcCopy
r1 = Picture1.Point(0, 0)
Else
Picture1.PSet (0, 0), r1
End If
Me.Caption = "RGB= " + Hex$(r1)
Picture1.BackColor = r1 End Sub
Private Sub Command1_Click()
Unload Me
End Sub
运行效果如下: