Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 在VC的Winform应用程序中使用UI自动化单击按钮++_Winforms_Visual Studio 2010_Visual C++_Ui Automation - Fatal编程技术网

Winforms 在VC的Winform应用程序中使用UI自动化单击按钮++

Winforms 在VC的Winform应用程序中使用UI自动化单击按钮++,winforms,visual-studio-2010,visual-c++,ui-automation,Winforms,Visual Studio 2010,Visual C++,Ui Automation,我想使用UI自动化单击一个按钮。我正在Winform VC++中使用UI自动化 这是我的密码 AutomationElement^ Select_connect_button= aeForm->FindFirst(TreeScope::Children,gcnew PropertyCondition(AutomationElement::NameProperty, "Select/Connect")); InvokePattern^ ipClickButton1 = (InvokePa

我想使用UI自动化单击一个按钮。我正在Winform VC++中使用UI自动化

这是我的密码

 AutomationElement^  Select_connect_button= aeForm->FindFirst(TreeScope::Children,gcnew PropertyCondition(AutomationElement::NameProperty, "Select/Connect"));
InvokePattern^ ipClickButton1 = (InvokePattern)Select_connect_button->GetCurrentPattern(InvokePattern::Pattern);
 ipClickButton1->Invoke();
但它显示了这些错误:

error C2440: 'type cast' : cannot convert from 'System::Object ^' to 'System::Windows::Automation::InvokePattern'

error C2440: 'initializing' : cannot convert from 'System::Windows::Automation::InvokePattern' to 'System::Windows::Automation::InvokePattern ^'
有人能帮我解决这些错误吗


谢谢。

生成错误是您将InvokePattern转换为InvokePattern^

在我的测试中,将第二行更新为以下代码将解决此问题:

InvokePattern^ipClickButton1=InvokePattern^选择连接按钮->GetCurrentPatternInvokePattern::Pattern


不能使用这些对象进行强制转换。这里有一种在C中实现的方法。您可以在这里获得方法名等。您需要的各种常量如下所示:

C:\Program Files\Microsoft SDK\Windows\v7.0\Include\UIAutomationClient.h 可能是v7.1目录

public static IUIAutomationInvokePattern elementToInvokePattern(this IUIAutomationElement element)
    {
        var conditionInvokePattern = auto.CreatePropertyCondition(
                                                        WindowsConstants.UIA_IsInvokePatternAvailablePropertyId,
                                                        true);

        var cacheRequest = auto.CreateCacheRequest();
        cacheRequest.AddPattern(WindowsConstants.UIA_InvokePatternId);

        var cachedElement = element.FindFirstBuildCache(TreeScope.TreeScope_Element,
                                            conditionInvokePattern,
                                            cacheRequest);

        var invokePattern = (IUIAutomationInvokePattern)
            cachedElement.GetCachedPattern(WindowsConstants.UIA_InvokePatternId);
        return invokePattern;
    }
示例中的常量如下所示: