Results 1 to 5 of 5

Thread: [RESOLVED] Clicking first button on toolbar of external app

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Resolved [RESOLVED] Clicking first button on toolbar of external app

    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:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. 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
    3. 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
    4. 'Private Const BM_CLICK As Long = &HF5
    5.  
    6. Private Const WM_USER = &H400
    7. Private Const TB_PRESSBUTTON = (WM_USER + 3)
    8.  
    9. Private Sub Command1_Click()
    10.     Dim hParent As Long
    11.     Dim hChild As Long
    12.    
    13.     hParent = FindWindow("TfrmMain", vbNullString)
    14.     Debug.Print hParent
    15.    
    16.     If hParent <> 0 Then
    17.        
    18.         hChild = FindWindowEx(hParent, 0&, "TPanel", vbNullString)
    19.         hParent = FindWindowEx(hParent, hChild, "TPanel", vbNullString)
    20.         hChild = FindWindowEx(hParent, 0&, "TPanel", vbNullString)
    21.         hParent = FindWindowEx(hParent, hChild, "TPanel", vbNullString)
    22.         hChild = FindWindowEx(hParent, 0&, "TToolbar", vbNullString)
    23.         Debug.Print hChild
    24.        
    25.         If hChild <> 0 Then
    26.             Call SendMessage(hChild, TB_PRESSBUTTON, 0, 0)
    27.         End If
    28.     End If
    29. End Sub

  2. #2
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Clicking first button on toolbar of external app

    According to msdn:
    Code:
    lResult = SendMessage(           // returns LRESULT in lResult
            (HWND) hWndControl,              // handle to destination control
            (UINT) TB_PRESSBUTTON,           // message ID
            (WPARAM) wParam,                 // = (WPARAM) (int) idButton
            (LPARAM) lParam                  // = (LPARAM) MAKELONG (fPress, 0)
            );
    A good macro for MAKELONG is here.
    Good luck

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Clicking first button on toolbar of external app

    Thanks. fPress must be True or False, so should I use it like this?

    It doesn't trigger the event. It doesn't matter if I set it to True or False.

    vb Code:
    1. Call SendMessage(hChild, TB_PRESSBUTTON, 0, MakeLong(True, 0))

    vb Code:
    1. Private Function HiWord(dw As Long) As Integer
    2.  If dw And &H80000000 Then
    3.       HiWord = (dw \ 65535) - 1
    4.  Else
    5.     HiWord = dw \ 65535
    6.  End If
    7. End Function
    8.  
    9. Private Function LoWord(dw As Long) As Integer
    10.   If dw And &H8000& Then
    11.       LoWord = &H8000 Or (dw And &H7FFF&)
    12.    Else
    13.       LoWord = dw And &HFFFF&
    14.    End If
    15. End Function
    16.  
    17. Private Function MakeLong(ByVal LoWord As Integer, _
    18.   ByVal HiWord As Integer) As Long
    19.  
    20. MakeLong = ((HiWord * &H10000) + LoWord)
    21.  
    22. End Function

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Clicking first button on toolbar of external app

    Is there anybody who knows how to do this?

    In all these years that VB is around there must be somebody who has figured out a way to click a Toolbar button of another application. I'm sure I'm not the first one who is trying to do this.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Clicking first button on toolbar of external app

    This is resolved now. I'm using the code from the attached project posted here: http://www.vbforums.com/showpost.php...07&postcount=7

    So instead of using this, which doesn't work.

    Code:
    Call SendMessage(hChild, TB_PRESSBUTTON, 0, 0)
    I'm using this.

    Code:
    ClickMouseSilent 20, 20, hChild, True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width