VB sendmessage 模拟按键

已知一个按钮的句柄,用SendMessage发送什么消息可以模拟这个按钮按下,然后触发事件?... 已知一个按钮的句柄,用SendMessage发送什么消息可以模拟这个按钮按下,然后触发事件? 展开
 我来答
zx001z7d53
2011-08-14 · TA获得超过2万个赞
知道大有可为答主
回答量:2.4万
采纳率:52%
帮助的人:5698万
展开全部
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 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 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 Sub Form_Load()
Shell "calc.exe", vbNormalNoFocus
End Sub

Private Sub Command1_Click()
Dim Hwnd1 As Long
Dim Hwnd2 As Long
Hwnd1 = FindWindow("SciCalc", "计算器")
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "1")
SendMessage Hwnd2, WM_LBUTTONDOWN, ByVal 0&, ByVal 0&
SendMessage Hwnd2, WM_LBUTTONUP, ByVal 0&, ByVal 0&
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式