如何使用Outlook中的UI自动化捕获Click事件?

时间:2015-10-20 07:33:44

标签: c# ui-automation microsoft-ui-automation

我想使用UI Automation捕获outlook的按钮事件。现在我能够获得“物业变化事件”#39;喜欢每当我最小化或最大化WINWORD窗口时,事件被提出而不是我希望在发送按钮点击上获得事件。

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");
    }

0 个答案:

没有答案