1

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 ^'

誰でもこれらのエラーを解決するのを手伝ってくれませんか?

ありがとう。

4

2 に答える 2

0

これらのオブジェクトをキャストすることはできません。これを C# で行う方法の 1 つを次に示します。ここでメソッド名などを取得できます。必要なさまざまな定数は、次のようなものです。

C:\Program Files\Microsoft SDKs\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;
    }

例の定数はここからのもののようです: http://msdn.microsoft.com/en-us/library/dd757483.aspx

于 2012-07-21T21:26:18.743 に答える
0

ビルド エラーは、(InvokePattern) を "InvokePattern^" に変換することです。

私のテストでは、2 行目を以下のコードに更新すると、この問題が修正されます。

InvokePattern^ ipClickButton1 = ( InvokePattern^ )Select_connect_button->GetCurrentPattern(InvokePattern::Pattern);

于 2012-07-15T04:08:52.350 に答える