vb点击其他程序上按钮的问题(SendMessage)
|
admin
2014年4月9日 16:20
本文热度 5835
|
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 = &HF5
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "任务栏和「开始」菜单属性") '我找的是任务栏属性窗口,这里换成你要找的窗口标题
'MsgBox hwnd
Dim btnhWnd As Long
btnhWnd = FindWindowEx(hwnd, 0, "Button", "取消") '取消是按按钮的标题,你要换成自己的内容
MsgBox btnhWnd
SetActiveWindow hwnd
SendMessage btnhWnd, BM_CLICK, 0, 0
End Sub
该文章在 2014/4/9 16:20:17 编辑过