以下是引用shi781203在2016-6-4 00:13:12的发言:
你的要求,我已经做了,请问能再多给指点吗?
你的要求,我已经做了,请问能再多给指点吗?
不及时结贴,的确令人不爽。请楼主以后及时结贴。
今天闲来无事,也来凑凑热闹
程序代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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) Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Sub Command1_Click() '根据楼主需求,模拟点击计算器按键9 Dim hwnd As Long Dim BtHeight As Long BtHeight = GetSystemMetrics(4) hwnd = FindWindow(vbNullString, "计算器") If hwnd = 0 Then MsgBox "计算器没有运行!" Exit Sub End If Dim p1 As RECT GetWindowRect hwnd, p1'用了这个API,计算器窗口怎么移动,都可以实现点击它 SetCursorPos p1.Left + 110, p1.Top + BtHeight + 180 '鼠标移动到计算器9的按键上 mouse_event &H2 Or &H4, 0, 0, 0, 0'模拟按下了9 End Sub
===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================