Hi, does anybody know how to click the first Toolbar button on another app?
I've already asked this on several places, but nobody seems to know how to do it. I tried TB_PRESSBUTTON and it sets the first button to tbrPressed, but it doesn't run the Toolbar click event.

Code:
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, 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)
    
    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)
        
        If hChild <> 0 Then
            Call SendMessage(hChild, TB_PRESSBUTTON, 0, 0)
        End If
    End If
End Sub