• 主页

初学: 如何提取屏幕上某一点的颜色信息？

FranklinBHU 教师  2003-12-18 05:04:18

...全文
44 点赞 收藏 3

3 条回复

3661512 2003-12-18

http://www.21code.com/codebase/?pos=down&id=418

online 2003-12-18
lblData是控建数组

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type
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
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Sub Timer1_Timer()
Static lX As Long, lY As Long
On Local Error Resume Next
Dim P As POINTAPI, h As Long, hD As Long, r As Long
GetCursorPos P
If P.x = lX And P.y = lY Then Exit Sub
lX = P.x: lY = P.y
lblData(0).Caption = lX & "," & lY
h = WindowFromPoint(lX, lY)
lblData(1).Caption = h
hD = GetDC(h)
lblData(2).Caption = hD
ScreenToClient h, P
lblData(3).Caption = P.x & "," & P.y
r = GetPixel(hD, P.x, P.y)
If r = -1 Then
BitBlt Picture1.hdc, 0, 0, 1, 1, hD, P.x, P.y, vbSrcCopy
r = Picture1.Point(0, 0)
Else
Picture1.PSet (0, 0), r
End If
lblData(4).Caption = Hex\$(r)
Picture1.BackColor = r
End Sub

shwen 2003-12-18

VB基础类

7453

VB 基础类