|
-
Sep 4th, 2007, 09:32 AM
#1
Thread Starter
Frenzied Member
[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:
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
-
Sep 4th, 2007, 09:38 AM
#2
Addicted Member
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
-
Sep 4th, 2007, 10:16 AM
#3
Thread Starter
Frenzied Member
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:
Call SendMessage(hChild, TB_PRESSBUTTON, 0, MakeLong(True, 0))
vb Code:
Private Function HiWord(dw As Long) As Integer
If dw And &H80000000 Then
HiWord = (dw \ 65535) - 1
Else
HiWord = dw \ 65535
End If
End Function
Private Function LoWord(dw As Long) As Integer
If dw And &H8000& Then
LoWord = &H8000 Or (dw And &H7FFF&)
Else
LoWord = dw And &HFFFF&
End If
End Function
Private Function MakeLong(ByVal LoWord As Integer, _
ByVal HiWord As Integer) As Long
MakeLong = ((HiWord * &H10000) + LoWord)
End Function
-
Sep 6th, 2007, 12:19 PM
#4
Thread Starter
Frenzied Member
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.
-
Sep 6th, 2007, 05:15 PM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|