#StackBounty: #c# #winapi #ui-automation #user32 Click Button in Toolbar of Other Program

Bounty: 200

I’m trying to automate some stuff on a legacy application that I don’t have the source to. So I’m essentially trying to use the Windows API to click the buttons I’ll need on it.

There is a toolbar of type msvb_lib_toolbar that looks like this:


I can get a handle to it (I think) by using this code:

IntPtr window = FindWindow("ThunderRT6FormDC", "redacted");
IntPtr bar = FindWindowEx(window, IntPtr.Zero,"msvb_lib_toolbar",null);

Looking at the docs, it seems I should be able to use SendMessage and the TB_PRESSBUTTON message to click these buttons:

public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

However, I’m not sure how to go about setting the wParam and lParam to click the wanted button on the bar. The documentation doesn’t seem to be helping much either.

Could you please advise?

Based on comments, I’ve also tried UIAutomation. I can locate the toolbar using the following code:

AutomationElement mainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Migration Expert"));
AutomationElement toolbar = mainWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "msvb_lib_toolbar"));

But from here, I’m not sure what to do as Spy++ shows no further children of this object:


Loking at the Current property of this AutomationElement I can’t seen anything jumping out at me but the BoundingRectangle does seem to indicate that I’ve found the right element.


Using inspector.exe also doesn’t indicate any children on the toolbar.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.