Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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
C# MC++和C之间AutomationElement的FindAll的不同行为 我试图在托管C++中使用UI自动化找到DATAGRID控件的DealType。DATAIKE子项。以下代码段在已知的HWND值上从C开始工作: var automationElement=automationElement.FromHandlenew IntPtr0x000602AE; var propertyCondition=新的PropertyConditionAutomationElement.ControlTypeProperty,ControlType.DataItem; var dataItems=automationElement.FindAllTreeScope.Subtree,propertyCondition.Count; Console.WriteLineFound{0}数据项,数据项;_C#_Ui Automation_Managed C++_Uia - Fatal编程技术网

C# MC++和C之间AutomationElement的FindAll的不同行为 我试图在托管C++中使用UI自动化找到DATAGRID控件的DealType。DATAIKE子项。以下代码段在已知的HWND值上从C开始工作: var automationElement=automationElement.FromHandlenew IntPtr0x000602AE; var propertyCondition=新的PropertyConditionAutomationElement.ControlTypeProperty,ControlType.DataItem; var dataItems=automationElement.FindAllTreeScope.Subtree,propertyCondition.Count; Console.WriteLineFound{0}数据项,数据项;

C# MC++和C之间AutomationElement的FindAll的不同行为 我试图在托管C++中使用UI自动化找到DATAGRID控件的DealType。DATAIKE子项。以下代码段在已知的HWND值上从C开始工作: var automationElement=automationElement.FromHandlenew IntPtr0x000602AE; var propertyCondition=新的PropertyConditionAutomationElement.ControlTypeProperty,ControlType.DataItem; var dataItems=automationElement.FindAllTreeScope.Subtree,propertyCondition.Count; Console.WriteLineFound{0}数据项,数据项;,c#,ui-automation,managed-c++,uia,C#,Ui Automation,Managed C++,Uia,这将产生以下输出: Found 2 DataItem(s) 将代码转换为MC++将产生零结果。以下是转换后的MC++代码: auto automationElement=automationElement::FromHandleIntPtr0x000602AE; auto propertyCondition=gcnew PropertyConditionAutomationElement::ControlTypeProperty,ControlType::DataItem; 自动数据项=自动元

这将产生以下输出:

Found 2 DataItem(s)
将代码转换为MC++将产生零结果。以下是转换后的MC++代码:

auto automationElement=automationElement::FromHandleIntPtr0x000602AE; auto propertyCondition=gcnew PropertyConditionAutomationElement::ControlTypeProperty,ControlType::DataItem; 自动数据项=自动元素->FindAllTreeScope::子树,属性条件->计数; 控制台::WriteLineFound{0}数据项,数据项;

有没有其他人使用托管C++的UI自动化来解决这个问题?我在过去使用过MC++for UIA,这是我在使用C时遇到的第一个区别。提前感谢您提供的任何信息。

我不知道为什么会发生这种情况,但每当我将UI自动化代码提取到另一个类中并像那样调用它时,它都会起作用。我并不声称自己是MC++或它如何加载.NET framework方面的专家,但这就是我解决问题的方法

创建AutomatedTable类 可自动化的

布拉格语一次 使用名称空间系统; 使用命名空间System::Windows::Automation; ref类可自动化{ 公众: AutomatedTableconst HWND windowHandle; 属性int行计数{ int-get; } 私人: AutomationElement^\u tableElement; }; AutomatedTable.cpp

包括StdAfx.h 包括AutomatedTable.h AutomatedTable::AutomatedTableconst HWND windowHandle{ _tableElement=AutomationElement::fromHandleIntPtrIndowHandle; } int AutomatedTable::RowCount::get{ auto dataItemProperty=gcnew Property条件AutomationElement::ControlTypeProperty,ControlType::DataItem; 返回_tableElement->FindAllTreeScope::子树,dataItemProperty->Count; } 从main.cpp调用 main.cpp

包括stdafx.h 包括AutomatedTable.h int main数组^args{ auto automatedTable=gcnew AutomatedTableHWND0x000602AE; 控制台::WriteLineFound{0}数据项,automatedTable->RowCount; 返回0; } 输出 如果您能深入了解这一差异的原因,我们将不胜感激:-

Found 2 DataItem(s)