Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am using Microsoft's UI Automation library for quite a while now, and I have been able to manipulate textboxes and buttons. However, I have problems with some of the controls.

I have a program that I want to automate, which have a picture box and a link label that functions like a button click. This means that if I clicked on the picture box or the link label, I will trigger an event, and be directed to another page.

I have tried using the invoke method, which buttons have, but was unsuccessful. Is there any other way to trigger the click event or something similar for a picture box or link label?
Thanks in advance.

Microsoft's UI Automation library:
http://msdn.microsoft.com/en-us/library/ms747327.aspx[^]

The guide I am using:
UI Automation Framework using WPF[^]
Posted
Updated 7-May-11 2:20am
v2

1 solution

If you don't mind straying out of the UI Automation system:

If you can locate the window-handle of the control you want to click (I believe the automation system gives access to the window-handles), you could use the windows api to send a mouse-button down, and mouse-button-up message to the controls handle.... this is much the same as actually clicking the control.

Its not the most elegant solution though.


XML
/// <summary>
/// sends a windows message to the specified window handle.
/// </summary>
/// <param name="hWnd">the window handle</param>
/// <param name="Msg">the message constant</param>
/// <param name="wParam">w parameter</param>
/// <param name="lParam">l parameter</param>
/// <returns>IntPtr Result</returns>
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);


C#
public const int WM_LBUTTONDOWN = 0x201 ;
public const int WM_LBUTTONUP = 0x202  ;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900