vb点击其他程序上按钮的问题(SendMessage)

vb点击其他程序上按钮的问题(SendMessage),第1张

VB6.0,用右击任务栏,属性,打开的窗口进行测试,可以按取消按钮,成功Option Explicit

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 Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Const BM_CLICK As Long = &HF5Private Sub Command1_Click()

Dim hwnd As Long

hwnd = FindWindow(vbNullString, "任务姿滚栏和「开始」菜单属性") '我找的是任务栏属性窗口,这里换成你要找的窗口标题

'MsgBox hwnd

Dim btnhWnd As Long

btnhWnd = FindWindowEx(hwnd, 0, "Button", "取消") '取虚册春差耐消是按按钮的标题,你要换成自己的内容

MsgBox btnhWnd

SetActiveWindow hwndSendMessage btnhWnd, BM_CLICK, 0, 0End Sub

如果你的那个图标 和 菜单的位置是固定不变的话,可以用则轿 API函数

Public Declare Function SetCursorPos Lib "user32" (ByVal x As long, ByVal y As long) As long‘这个函数可以讲鼠标移动到任意(X,Y)位置

Public 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)’模拟鼠标单击

先找到你那个图标和菜单的位悔盯乎置X 和Y,然后

dim Ret as long

Ret=SetCursorPos(X,Y)'移动到那个位置

mouse_event(&H2, 0, 0, 0, 0)'碧悉鼠标左键按下

mouse_event(&H4, 0, 0, 0, 0)‘鼠标左键d起


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8272075.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存