|
-
May 10th, 2007, 01:54 PM
#1
Clicking Toolbar button on another app
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
-
May 10th, 2007, 09:28 PM
#2
Re: Clicking Toolbar button on another app
You are only doing one action. You need to press it, wait a few miliseconds and then release it.
I thought 0 was false, so it only looks like you are releasing it.
-
May 10th, 2007, 09:59 PM
#3
Re: Clicking Toolbar button on another app
Do you mean like this?
Code:
Call SendMessage(hChild, TB_PRESSBUTTON, 0, True)
Sleep (200)
Call SendMessage(hChild, TB_PRESSBUTTON, 0, False)
It makes no difference. The button is pressed and stays pressed. Nothing else happens.
-
May 12th, 2007, 02:04 AM
#4
Re: Clicking Toolbar button on another app
if i can still remember, you have to send WM_COMMAND message to the parent window together with the button command id and the toolbar window handle.
Busy 
-
May 12th, 2007, 03:28 PM
#5
Re: Clicking Toolbar button on another app
After some searching I found this and it works fine with Internet Explorer.
http://www.vbforums.com/showpost.php...04&postcount=4
But if I replace the data in the "TestClickingToolbarButton" sub with my data, then it doesn't work.
Code:
Private Sub TestClickingToolbarButton()
Dim hParent As Long
Dim hChild As Long
hParent = FindWindow("TfrmMain", vbNullString)
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)
ClickToolbarButtonByIndex hChild, 1
End Sub
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
|