Hello, does anybody know how to click/press the first button on the toolbar of an external application? The code below finds the button and presses it, but the event behind the button is not triggered. How can I trigger the event of that button?
Button is pressed, but event not triggered.
vb Code:
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, ByVal lParam As String) As Long 'Private Const BM_CLICK As Long = &HF5 Private Const WM_USER = &H400 Private Const TB_PRESSBUTTON = (WM_USER + 3) Private Sub Command1_Click() Dim hParent As Long Dim hChild As Long hParent = FindWindow("TfrmMain", vbNullString) Debug.Print hParent If hParent <> 0 Then hChild = FindWindowEx(hParent, 0&, "TPanel", vbNullString) hParent = FindWindowEx(hParent, hChild, "TPanel", vbNullString) hChild = FindWindowEx(hParent, 0&, "TPanel", vbNullString) hParent = FindWindowEx(hParent, hChild, "TPanel", vbNullString) hChild = FindWindowEx(hParent, 0&, "TToolbar", vbNullString) Debug.Print hChild If hChild <> 0 Then Call SendMessage(hChild, TB_PRESSBUTTON, 0, 0) End If End If End Sub





Reply With Quote