Thomas LEBRUN

Hi all,

I'm using the code below:

// On demarre le processus

Process p = Process.Start("notepad");

Thread.Sleep(2000);

if (p.MainWindowHandle != IntPtr.Zero)

{

// On recupere l'AutomationElement depuis l'ID du processus

AutomationElement element = AutomationElement.FromHandle(p.MainWindowHandle);

// On verifie que l'on peut appliquer un TransformPattern sur cet element

TransformPattern tranform = element.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

if (tranform != null)

{

// Si c'est OK, on redimensionne et on deplace.

tranform.Resize(this.Width, this.Height);

tranform.Move(this.Left + this.Width + 25, this.Top);

}

PropertyCondition fileMenu = new PropertyCondition(AutomationElement.NameProperty, "File");

AutomationElement fileElementMenu = element.FindFirst(TreeScope.Descendants, fileMenu);

if (fileElementMenu != null)

{

object patternObject;

fileElementMenu.TryGetCurrentPattern(InvokePattern.Pattern, out patternObject);

InvokePattern pattern = patternObject as InvokePattern;

if (pattern != null)

{

pattern.Invoke();

}

}

}

But every time, my object pattern is null. I've tried with GetCurrentPattern and I'm geeting an exception ("The pattern is not supported by the element").

Is there a way to do what I want (eg invoking the clic on a button of a Win32 app)

Thanks !




Re: Microsoft UI Automation TryGetCurrentPattern & Invoke Pattern returns null ?

Thomas LEBRUN

Found it (with UISpy): it was a ExpandCollapsePattern not and InvokePattern...

Bye