'声明必要的 API 例程:
Public Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Public Declare Function SetCursorPos Lib "user32" _
(ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function GetTickCount Lib "c:\windows\system\kernel32.dll " () _
As Long
Public Declare Function GetLastActivePopup Lib "user32" _
(ByVal hwndOwnder As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function GetDlgCtrlID Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function GetNextDlgGroupItem Lib "user32" _
(ByVal hDlg As Long, ByVal hCtl As Long, ByVal bPrevious As Long) As Long
Public Declare Function GetNextDlgTabItem Lib "user32" _
(ByVal hDlg As Long, ByVal hCtl As Long, ByVal bPrevious As Long) As Long
Public Const WM_USER = 1024
Public Const END_H10 = &H10
'/*********************************************************************/
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public ButtonPos As POINTAPI
'窗体中的代码
Dim l_Autoclick_Begin As Variant
Private Const EMPTY_TIME = "0:00:00"
Private Sub Command1_Click()
Dim lRt_msg As VbMsgBoxResult
l_Autoclick_Begin = EMPTY_TIME
l_Autoclick_Begin = Format(Now(), "yyyy-mm-dd hh:mm:ss")
Label2.Caption = l_Autoclick_Begin
'主要是为了得到返回值,根据返回值是vbok或vbcancel 进行相应处理
DoEvents
If lRt_msg = vbOK Then
MsgBox "进行处理!"
Else
If lRt_msg = vbCancel Then
MsgBox "取消处理!"
End If
End If
End Sub
Private Sub Form_Load()
Dim tmp As Long
With Command1
ButtonPos.X = (.Left + .Width / 2) / Screen.TwipsPerPixelX
ButtonPos.Y = (.Top + .Height / 2) / Screen.TwipsPerPixelY
End With
tmp = ClientToScreen(Me.hwnd, ButtonPos)
Label4.Caption = Format(Now, "yyyy-mm-dd hh:mm:ss")
End Sub
Private Sub mnuClickButton_Click()
'以下是对已知窗体和已知按钮控件的句柄进行自动电击
Const MoveStep As Integer = 50
Dim CursorPos As POINTAPI
Dim DistX As Double, DistY As Double
Dim tmp As Long
Dim i As Integer
Dim PosX As Integer, PosY As Integer
Dim TickCount As Long
tmp = GetCursorPos(CursorPos)
DistX = ButtonPos.X - CursorPos.X
DistY = ButtonPos.Y - CursorPos.Y
For i = 1 To MoveStep
PosX = CursorPos.X + DistX * i / MoveStep
PosY = CursorPos.Y + DistY * i / MoveStep
tmp = SetCursorPos(PosX, PosY)
Next i
tmp = SendMessage(Command1.hwnd, WM_LBUTTONDOWN, 0, 0)
TickCount = GetTickCount()
While GetTickCount() - TickCount < 200
tmp = DoEvents()
Wend
tmp = SendMessage(Command1.hwnd, WM_LBUTTONUP, 0, 0)
End Sub
Private Sub Timer1_Timer()
Const MoveStep As Integer = 50
Dim lhwnd As Long
Dim lhwnd2 As Long
Dim tmp As Long
Dim TickCount As Long
Dim CursorPos As POINTAPI
Dim DistX As Double, DistY As Double
Dim i As Integer
Dim PosX As Integer, PosY As Integer
Timer1.Enabled = False
If (Abs(DateDiff("s", l_Autoclick_Begin, Now()) > 60)) Then
基本过程如下:
private Timer1.timer()
if Time()<TimeYouWant then
msgbox(.....)'调用MSGBOX函数,其参数设置为具有“确定”及“取消”两个按钮。
else
msgbox(....)'参数设置为只用取消按钮。
end if
end sub