0

I want to capture button event of outlook using UI Automation. Right now i am able to get 'Property Change Event' like whenever iam minimizing or maximizing the WINWORD window the the event is raised instead of that i want to get the event on Send button click.

private void SendButtonInvoke()
    {

        Process[] processes = Process.GetProcessesByName("WinWord");
        foreach (var item in processes)
        {
            aeOutLook = AutomationElement.FromHandle(item.MainWindowHandle);
        }

        AutomationElement buttonAddInstance =  aeOutLook.FindFirst(TreeScope.Descendants,
               new PropertyCondition(AutomationElement.NameProperty, "Create a new message"));

        if (buttonAddInstance == null)
        {
            MessageBox.Show("Add button instance not found");
        }
        else
        {
            AutomationPropertyChangedEventHandler ButtonEvent =
                    new AutomationPropertyChangedEventHandler(OnStartInvoke);

            Automation.AddAutomationPropertyChangedEventHandler(buttonAddInstance, TreeScope.Element,
                ButtonEvent, AutomationElement.NameProperty);   
        }
 } 
    private void OnStartInvoke(object src, AutomationEventArgs e)
    {
        //logic
        AutomationElement ar2 = src as AutomationElement;
        MessageBox.Show("Invoked Sucessfully");
    }
Ravi Kanth
  • 1,182
  • 13
  • 38
  • Check out this [thread](http://stackoverflow.com/questions/33164659/how-to-capture-send-button-event-for-outlook-using-ui-automation-in-c). It is not yet answered, but I believe it asks a similar question. – Vandal Oct 20 '15 at 07:37
  • 1
    Yup i gone through it but it haven't worked for me.when i tried with my own windows application i can able get the event triggered on button click. – Ravi Kanth Oct 20 '15 at 08:24

0 Answers0