新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'下面是屏幕找色实例,请根据实际情况进行验证。
宣州网站建设公司创新互联建站,宣州网站设计制作,有大型网站制作公司丰富经验。已为宣州上千多家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的宣州做网站的公司定做!
Option Explicit
'定义一个POINTAPI
Private Type POINTAPI
x As Long
y As Long
End Type
'定义一个找色区域
Private Type RECT
Left As Long '区域坐标x
Top As Long '区域坐标y
Right As Long '区域宽
Bottom As Long '区域高
End Type
'Windows API 声明
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 Function ifColor(x As RECT, ByVal color As Long) As POINTAPI
On Error Resume Next
Dim nTmpColor As Long, i As Long, j As Long
For i = x.Left To x.Left + x.Right
For j = x.Top To x.Top + x.Bottom
nTmpColor = GetPixel(GetDC(0), i, j)
If color = nTmpColor Then
ifColor.x = i
ifColor.y = j
Exit Function
End If
DoEvents
Next
Next
End Function
Private Sub Command1_Click() '全屏幕找色,时间花费较长
Dim t As POINTAPI, m As RECT
With m
.Top = 0
.Left = 0
.Bottom = Screen.Height / Screen.TwipsPerPixelY
.Right = Screen.Width / Screen.TwipsPerPixelX
End With
t = ifColor(m, 1447073)
Debug.Print t.x, t.y
End Sub
Private Sub Command2_Click() '某区域找色,时间花费少
Dim t As POINTAPI, m As RECT
With m
.Top = 300
.Left = 300
.Bottom = 100
.Right = 100
End With
t = ifColor(m, RGB(0, 125, 125))
Debug.Print t.x, t.y
End Sub
呵呵,是不是类似于按键精灵找图的脚本?
这个程序你经常要用的话,建议你找到老版本的按键精灵,使用VB来查看里面的dll,研究一下,很简单的。
我搜集了资料,目前还没有着手研究。如果你需要老版本的按键精灵,请在百度里给我发信息
IO.Directory.GetFiles
获取指定目录中的所有文件,比对文件名就行了。如果包括多层子目录,需要递归
要想实现这个,很复杂.因为这个不是图片对比,而是要在屏幕区域搜索和原始图像相似的区域.不好弄.