Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_MOVE = &H1
Private Declare Function SetCursorPos Lib "user32" (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 GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
'不知道Findcolor能不能在Click指令内运行[尝试过hDC = GetDC(0)显示限制或不支持]
'请问只能单独运行嘛?加入到循环中可以吗(还未尝试)
'学校的书里api的用法没有关于此方面的教学(大部分代码是一位大佬告知的)
Private Sub Findcolor(ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
Dim x As Long, y As Long, col As Long
Dim hDC As Long, w As Long, h As Long
hDC = GetDC(0)
w = Screen.Width / Screen.TwipsPerPixelX
h = Screen.Height / Screen.TwipsPerPixelY
Findcolor 255, 0, 0'调用findcolor函数时传入需要查找的颜色RGB分量的位置和用法不知道对不对
For x = 0 To w - 1'获取全屏像素不是很理解,请问如何改成范围的
For y = 0 To h - 1'请问这个1是屏幕最大的宽和高吗,0.5w和0.5h就是缩减一半嘛
col = GetPixel(hDC, x, y)'x,y固定对比获取最左上角的像素颜色的坐标
If col = RGB(r, g, b) Then
SetCursorPos x, y'不知道怎么用指针指令使用获取到的颜色坐标
End If
Next
Next
ReleaseDC 0, hDC
End Sub
'谢谢
该回答引用GPTᴼᴾᴱᴺᴬᴵ
这段代码主要实现的功能是在全屏中查找指定的颜色,并将鼠标指针移动到第一个匹配的像素点处。
至于你的问题: