vb 如何向已知句柄的按钮发送鼠标点击?
用api怎么做?PrivateDeclareFunctionPostMessageLib"user32"Alias"PostMessageA"(ByValhwndAsLo...
用api怎么做?Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim dHwnd As Long, tHwnd As Long
tHwnd = FindWindow("WindowsForms10.Window.8.app.0.378734a", "标题"
If tHwnd > 0 Then
PostMessage tHwnd ,WM_LBUTTONDOWN, 0, 0
PostMessage tHwnd, WM_LBUTTONUP, 0, 0
End If
End Sub 展开
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim dHwnd As Long, tHwnd As Long
tHwnd = FindWindow("WindowsForms10.Window.8.app.0.378734a", "标题"
If tHwnd > 0 Then
PostMessage tHwnd ,WM_LBUTTONDOWN, 0, 0
PostMessage tHwnd, WM_LBUTTONUP, 0, 0
End If
End Sub 展开
展开全部
向按钮发送坐标1,1的左键按下左键弹起消息就是了
其中WM_LBUTTONDOWN,WM_LBUTTONUP的常量值以及PostMessage的声明可以在api浏览器查。Gwnd是句柄
PostMessage Gwnd, WM_LBUTTONDOWN, 0, ByVal (1 + 1 * 65536)
PostMessage Gwnd, WM_LBUTTONUP, 0, ByVal (1 +1 * 65536)
其中WM_LBUTTONDOWN,WM_LBUTTONUP的常量值以及PostMessage的声明可以在api浏览器查。Gwnd是句柄
PostMessage Gwnd, WM_LBUTTONDOWN, 0, ByVal (1 + 1 * 65536)
PostMessage Gwnd, WM_LBUTTONUP, 0, ByVal (1 +1 * 65536)
追问
如果不是顶层窗口为什么就没用了呢,就是说窗口最小化或不是当前窗口点击就没用是怎么回事
追答
窗口最小化或不是当前窗口都可以用啊,只要是GDI的窗口就可以用,最后的0改成ByVal (1 +1 * 65536)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询