7,787
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As String) As Long
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
'在窗口列表中寻找与指定条件相符的第一个子窗口
Private Declare Function FindWindowEx _
Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Const BM_CLICK As Long = &HF5
Private Sub Command1_Click()
Dim h1 As Long, h2 As Long
h1 = FindWindow(0&, "Windows Internet Explorer")
h2 = FindWindowEx(h1, 0, "Button", "确定")
SendMessage h2, BM_CLICK, 0, ByVal 0&
SendMessage h2, BM_CLICK, 0, ByVal 0&
End Sub
'接上,将一个新的程序设置成这样.
'在用的时候,注意,一定要先运行此程序.
'在运行你那个要自动单击的程序的时候,一定要让那个程序在最上方(窗口的最前方)
Private Const LB_DELETESTRING = &H182
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const LB_ADDSTRING = &H180
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Const GW_MAX = 5
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y 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) '定义鼠标事件
Dim chWnd As Long
Dim listHwnd As Long
Private Sub Timer1_Timer()
Dim chGwnd As Long
Dim clsname As String * 256
chWnd = FindWindow(vbNullString, "Microsoft Internet Explorer") '"fvflove"改为窗口的名称要用全称
chGwnd = GetWindow(chWnd, GW_CHILD)
GetClassName chGwnd, clsname, 256
Label1.Caption = clsname
If InStr(1, clsname, "Button") Then
listHwnd = chGwnd '此处是返回的TextBox的句柄 ,你可以放入一个集合或数组
GoTo LAA
End If
Label1.Caption = clsname
While chGwnd <> 0
Label1.Caption = clsname
chGwnd = GetWindow(chGwnd, GW_HWNDNEXT)
GetClassName chGwnd, clsname, 256
If InStr(1, clsname, "Button") Then
listHwnd = chGwnd '此处是返回的TextBox的句柄 ,你可以放入一个集合或数组
GoTo LAA
End If
Wend
Me.Caption = listHwnd
LAA:
If listHwnd <> 0 Then
Dim lpRect As RECT
GetWindowRect listHwnd, lpRect
Print lpRect.Left
Print lpRect.Top
Print lpRect.Bottom
Print lpRect.Right
Call SetCursorPos(lpRect.Left + (lpRect.Right - lpRect.Left) / 2, lpRect.Top + (lpRect.Bottom - lpRect.Top) / 2)
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Timer1.Enabled = False '此处设置只执行单击一次事件.
End If
End Sub
'建立一个程序
'以下是程序中的代码 此程序只有一个Timer1的控件.
'Timer1.Enabled = True
'Timer1.Interval = 100
'在你运行你那个自运投注的程序的时候,先让此程序运行.
'以下代码经过调试,成功
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub Timer1_Timer()
Dim hwnd
hwnd = FindWindow(0&, "Microsoft Internet Explorer") '此处你为什么要用 "FORM1" 为什么不用
SendMessage hwnd, WM_CLOSE, 0&, 0&
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
'先用
Hwnd=FindWindow(0&,"要关闭的窗口标题(注意一定要完整的)")
'再发送关闭信息
sendMessage Hwnd , WM_Close ,0&,0&