以下是引用不说也罢在2016-6-4 14:57:08的发言:
不及时结贴,的确令人不爽。请楼主以后及时结贴。
今天闲来无事,也来凑凑热闹
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
请问能不能用以下代码取替?
***************************************
Public Const WM_MOUSEMOVE = &H200
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
x As Long
y As Long
End Type
Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
*********************************************(上述为GetWindowPlacement这个API函数要用到模块)
(以下代码实现模拟鼠标在指定窗体移动到中央,请问以下语句错误在哪里?)
……
GetWindowPlacement WinID, Wt
PostMessage WinID, WM_MOUSEMOVE, 0, Wt.rcNormalPosition.Right / 2 + Wt.rcNormalPosition.Bottom / 2
……