Private Sub Form_Load()
Dim col As Long
MsgBox GetPixel(Form1.hWnd, 100, 100)
end sub
3 个解决方案
#1
Private Type POINTAPI
x As Long
y As Long
End Type
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 Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P
r = GetPixel(hD, P.x, P.y)
MsgBox Hex(r)
end sub
x As Long
y As Long
End Type
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 Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P
r = GetPixel(hD, P.x, P.y)
MsgBox Hex(r)
end sub
#2
hWnd怎么获取像素,要传递hDC。用GetDC获得,用完以后DeleteDC
#3
上面有一个GetDC, api 资料上说作用是: 获取指定窗口的设备场景是什么意思?
上面Form_click ()里面的代码与下面我这一段代码有什么区别?
Private Sub Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
r = GetPixel(h, P.x, P.y)
MsgBox Hex(r)
end sub
上面Form_click ()里面的代码与下面我这一段代码有什么区别?
Private Sub Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
r = GetPixel(h, P.x, P.y)
MsgBox Hex(r)
end sub
#1
Private Type POINTAPI
x As Long
y As Long
End Type
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 Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P
r = GetPixel(hD, P.x, P.y)
MsgBox Hex(r)
end sub
x As Long
y As Long
End Type
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 Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P
r = GetPixel(hD, P.x, P.y)
MsgBox Hex(r)
end sub
#2
hWnd怎么获取像素,要传递hDC。用GetDC获得,用完以后DeleteDC
#3
上面有一个GetDC, api 资料上说作用是: 获取指定窗口的设备场景是什么意思?
上面Form_click ()里面的代码与下面我这一段代码有什么区别?
Private Sub Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
r = GetPixel(h, P.x, P.y)
MsgBox Hex(r)
end sub
上面Form_click ()里面的代码与下面我这一段代码有什么区别?
Private Sub Form_click()
Dim lX As Long, lY As Long
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
h = WindowFromPoint(lX, lY)
r = GetPixel(h, P.x, P.y)
MsgBox Hex(r)
end sub