rautomation 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd70f4859a5f1f16541465e836d116265af26eb4
4
- data.tar.gz: 7bae3a8bc91207cdfa3e302ffdbde778ead2ac69
3
+ metadata.gz: d60457345affb72ade2ec56f93991a918cb39cd8
4
+ data.tar.gz: d136c890f577984d093d2831aa6f19559a54a271
5
5
  SHA512:
6
- metadata.gz: ea5fd4f9d351eec5ffe23f207ab5f6679d861d410adc6fe908902497195c3ce776deff5c1428afd884c9bd8ef62a1f57d11da968bad26e2ca638afaea06dc529
7
- data.tar.gz: f9c6a60d917eeef6178a4fdc9f3f68d8cbd04e8ee4d6194130859036d243cb842167a68900cc2ad811659099ca682c08ccfa30763f8aa6d0a1e4a491744e9d1c
6
+ metadata.gz: 562a850a9175f49764a49927a6dd86666afc248065a1c9cee6e4ba739702f613777f71fbb354074b071af979b60399d4d59abe61ed3ce283bc4e188f43b3d7ca
7
+ data.tar.gz: a26f7646d7b025c58584906fc9808bd0eeca4321f3b3caf53f2a8fd4ab8e02b2fc50cb8b69976e6dbfb6e0438226aeaac30ba61ef584a7bfc9fa699b79490484
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rautomation (0.9.0)
4
+ rautomation (0.9.1)
5
5
  ffi
6
6
 
7
7
  GEM
data/History.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.9.1
2
+
3
+ === MsUia adapter
4
+ * Ability to interact with controls that do not have native window handles (for example WPF applications).
5
+
1
6
  == 0.9.0 / 2013-04-22
2
7
 
3
8
  === MsUia adapter
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
Binary file
@@ -17,6 +17,16 @@ array<String^>^ AutomatedSelectList::Selection::get() {
17
17
  return selections;
18
18
  }
19
19
 
20
+ int AutomatedSelectList::GetOptions(const char* options[]) {
21
+ auto selectionItems = SelectionItems;
22
+
23
+ if( NULL != options ) {
24
+ StringHelper::CopyNames(selectionItems, options);
25
+ }
26
+
27
+ return selectionItems->Count;
28
+ }
29
+
20
30
  bool AutomatedSelectList::SelectByIndex(const int whichItem)
21
31
  {
22
32
  try {
@@ -12,6 +12,7 @@ public:
12
12
  bool SelectByIndex(const int whichItem);
13
13
  bool SelectByValue(const char* whichItem);
14
14
  bool GetValueByIndex(const int whichItem, char* comboValue, const int comboValueSize);
15
+ int GetOptions(const char* options[]);
15
16
 
16
17
  property array<String^>^ Selection {
17
18
  array<String^>^ get();
@@ -1,10 +1,6 @@
1
1
  #include "StdAfx.h"
2
2
  #include "AutomationClicker.h"
3
3
 
4
- AutomationClicker::AutomationClicker(const HWND windowHandle) {
5
- _automationElement = AutomationElement::FromHandle(IntPtr(windowHandle));
6
- }
7
-
8
4
  void AutomationClicker::Click() {
9
5
  if( CanInvoke() ) {
10
6
  return Invoke();
@@ -18,33 +14,33 @@ void AutomationClicker::Click() {
18
14
  }
19
15
 
20
16
  void AutomationClicker::MouseClick() {
21
- _automationElement->SetFocus();
22
- auto clickablePoint = _automationElement->GetClickablePoint();
23
- Cursor::Position = Point((int)clickablePoint.X, (int)clickablePoint.Y);
17
+ _control->SetFocus();
18
+ auto clickablePoint = _control->GetClickablePoint();
19
+ Cursor::Position = System::Drawing::Point((int)clickablePoint.X, (int)clickablePoint.Y);
24
20
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
25
21
  mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
26
22
  }
27
23
 
28
24
  bool AutomationClicker::CanInvoke() {
29
- return (bool)(_automationElement->GetCurrentPropertyValue(AutomationElement::IsInvokePatternAvailableProperty));
25
+ return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsInvokePatternAvailableProperty));
30
26
  }
31
27
 
32
28
  void AutomationClicker::Invoke() {
33
- dynamic_cast<InvokePattern^>(_automationElement->GetCurrentPattern(InvokePattern::Pattern))->Invoke();
29
+ dynamic_cast<InvokePattern^>(_control->GetCurrentPattern(InvokePattern::Pattern))->Invoke();
34
30
  }
35
31
 
36
32
  bool AutomationClicker::CanToggle() {
37
- return (bool)(_automationElement->GetCurrentPropertyValue(AutomationElement::IsTogglePatternAvailableProperty));
33
+ return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsTogglePatternAvailableProperty));
38
34
  }
39
35
 
40
36
  void AutomationClicker::Toggle() {
41
- dynamic_cast<TogglePattern^>(_automationElement->GetCurrentPattern(TogglePattern::Pattern))->Toggle();
37
+ dynamic_cast<TogglePattern^>(_control->GetCurrentPattern(TogglePattern::Pattern))->Toggle();
42
38
  }
43
39
 
44
40
  bool AutomationClicker::CanSelect() {
45
- return (bool)(_automationElement->GetCurrentPropertyValue(AutomationElement::IsSelectionItemPatternAvailableProperty));
41
+ return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsSelectionItemPatternAvailableProperty));
46
42
  }
47
43
 
48
44
  void AutomationClicker::Select() {
49
- dynamic_cast<SelectionItemPattern^>(_automationElement->GetCurrentPattern(SelectionItemPattern::Pattern))->Select();
45
+ dynamic_cast<SelectionItemPattern^>(_control->GetCurrentPattern(SelectionItemPattern::Pattern))->Select();
50
46
  }
@@ -3,16 +3,17 @@ using namespace System::Windows::Automation;
3
3
  using namespace System::Windows::Forms;
4
4
  using namespace System::Drawing;
5
5
 
6
- ref class AutomationClicker
6
+ #include "AutomationControl.h"
7
+
8
+ ref class AutomationClicker : AutomationControl
7
9
  {
8
10
  public:
9
- AutomationClicker(const HWND windowHandle);
11
+ AutomationClicker(const HWND windowHandle) : AutomationControl(windowHandle) {}
12
+ AutomationClicker(const FindInformation& findInformation) : AutomationControl(findInformation) {}
10
13
  void Click();
11
14
  void MouseClick();
12
15
 
13
16
  private:
14
- AutomationElement^ _automationElement;
15
-
16
17
  bool CanInvoke();
17
18
  void Invoke();
18
19
 
@@ -22,6 +22,14 @@ public:
22
22
  String^ get() { return _control->Current.ClassName; }
23
23
  }
24
24
 
25
+ property bool IsEnabled {
26
+ bool get() { return _control->Current.IsEnabled; }
27
+ }
28
+
29
+ property bool IsFocused {
30
+ bool get() { return _control->Current.HasKeyboardFocus; }
31
+ }
32
+
25
33
  property Rect BoundingRectangle {
26
34
  Rect get() { return _control->Current.BoundingRectangle; }
27
35
  }
@@ -3,13 +3,13 @@
3
3
  #include "StringHelper.h"
4
4
 
5
5
  extern "C" {
6
- __declspec ( dllexport ) void Control_GetValue(const HWND windowHandle, char* theValue, const int maximumLength) {
7
- auto control = gcnew AutomationControl(windowHandle);
6
+ __declspec ( dllexport ) void Control_GetValue(const FindInformation& findInformation, char* theValue, const int maximumLength) {
7
+ auto control = gcnew AutomationControl(findInformation);
8
8
  StringHelper::CopyToUnmanagedString(control->Value, theValue, maximumLength);
9
9
  }
10
10
 
11
- __declspec ( dllexport ) void Control_SetValue(const HWND windowHandle, const char* theValue) {
12
- auto control = gcnew AutomationControl(windowHandle);
11
+ __declspec ( dllexport ) void Control_SetValue(const FindInformation& findInformation, const char* theValue) {
12
+ auto control = gcnew AutomationControl(findInformation);
13
13
  control->Value = gcnew String(theValue);
14
14
  }
15
15
  }
@@ -2,37 +2,37 @@
2
2
  #include "ExpandCollapseHelper.h"
3
3
 
4
4
 
5
- void ExpandCollapseHelper::ExpandByValue(const HWND windowHandle, const char* whichItem)
5
+ void ExpandCollapseHelper::ExpandByValue(const FindInformation& findInformation, const char* whichItem)
6
6
  {
7
- Expand(ExpandableItem(windowHandle, whichItem));
7
+ Expand(ExpandableItem(findInformation, whichItem));
8
8
  }
9
9
 
10
- void ExpandCollapseHelper::ExpandByIndex(const HWND windowHandle, const int whichItemIndex)
10
+ void ExpandCollapseHelper::ExpandByIndex(const FindInformation& findInformation, const int whichItemIndex)
11
11
  {
12
- auto expandableItem = ExpandableItems(windowHandle)[whichItemIndex];
12
+ auto expandableItem = ExpandableItems(findInformation)[whichItemIndex];
13
13
  Expand(expandableItem);
14
14
  }
15
15
 
16
- void ExpandCollapseHelper::CollapseByValue(const HWND windowHandle, const char* whichItem)
16
+ void ExpandCollapseHelper::CollapseByValue(const FindInformation& findInformation, const char* whichItem)
17
17
  {
18
- Collapse(ExpandableItem(windowHandle, whichItem));
18
+ Collapse(ExpandableItem(findInformation, whichItem));
19
19
  }
20
20
 
21
- void ExpandCollapseHelper::CollapseByIndex(const HWND windowHandle, const int whichItemIndex)
21
+ void ExpandCollapseHelper::CollapseByIndex(const FindInformation& findInformation, const int whichItemIndex)
22
22
  {
23
- auto expandableItem = ExpandableItems(windowHandle)[whichItemIndex];
23
+ auto expandableItem = ExpandableItems(findInformation)[whichItemIndex];
24
24
  Collapse(expandableItem);
25
25
  }
26
26
 
27
- AutomationElementCollection^ ExpandCollapseHelper::ExpandableItems(const HWND windowHandle)
27
+ AutomationElementCollection^ ExpandCollapseHelper::ExpandableItems(const FindInformation& findInformation)
28
28
  {
29
- auto automationElement = AutomationElement::FromHandle(IntPtr(windowHandle));
29
+ auto automationElement = (gcnew AutomationControl(findInformation))->Element;
30
30
  return automationElement->FindAll(System::Windows::Automation::TreeScope::Subtree, IsExpandable);
31
31
  }
32
32
 
33
- AutomationElement^ ExpandCollapseHelper::ExpandableItem(const HWND windowHandle, const char* whichItem)
33
+ AutomationElement^ ExpandCollapseHelper::ExpandableItem(const FindInformation& findInformation, const char* whichItem)
34
34
  {
35
- auto automationElement = AutomationElement::FromHandle(IntPtr(windowHandle));
35
+ auto automationElement = (gcnew AutomationControl(findInformation))->Element;
36
36
  auto andTheNameMatches = gcnew PropertyCondition(AutomationElement::NameProperty, gcnew String(whichItem));
37
37
  return automationElement->FindFirst(System::Windows::Automation::TreeScope::Subtree, gcnew AndCondition(IsExpandable, andTheNameMatches));
38
38
  }
@@ -1,17 +1,20 @@
1
1
  #pragma once
2
+
3
+ #include "AutomationControl.h"
4
+
2
5
  using namespace System::Windows::Automation;
3
6
 
4
7
  ref class ExpandCollapseHelper
5
8
  {
6
9
  public:
7
- void ExpandByValue(const HWND windowHandle, const char* whichItem);
8
- void ExpandByIndex(const HWND windowHandle, const int whichItemIndex);
9
- void CollapseByValue(const HWND windowHandle, const char* whichItem);
10
- void CollapseByIndex(const HWND windowHandle, const int whichItemIndex);
10
+ void ExpandByValue(const FindInformation& findInformation, const char* whichItem);
11
+ void ExpandByIndex(const FindInformation& findInformation, const int whichItemIndex);
12
+ void CollapseByValue(const FindInformation& findInformation, const char* whichItem);
13
+ void CollapseByIndex(const FindInformation& findInformation, const int whichItemIndex);
11
14
 
12
15
  private:
13
- AutomationElementCollection^ ExpandableItems(const HWND windowHandle);
14
- AutomationElement^ ExpandableItem(const HWND windowHandle, const char* whichItem);
16
+ AutomationElementCollection^ ExpandableItems(const FindInformation& findInformation);
17
+ AutomationElement^ ExpandableItem(const FindInformation& findInformation, const char* whichItem);
15
18
  void Expand(AutomationElement^ automationElement);
16
19
  void Collapse(AutomationElement^ automationElement);
17
20
 
@@ -8,8 +8,13 @@ extern "C" {
8
8
  return autoSelectList->Count;
9
9
  }
10
10
 
11
- __declspec ( dllexport ) int SelectList_SelectedIndex(const HWND windowHandle) {
12
- auto autoSelectList = gcnew AutomatedSelectList(windowHandle);
11
+ __declspec ( dllexport ) int SelectList_Options(const FindInformation& findInformation, const char* options[]) {
12
+ auto selectList = gcnew AutomatedSelectList(findInformation);
13
+ return selectList->GetOptions(options);
14
+ }
15
+
16
+ __declspec ( dllexport ) int SelectList_SelectedIndex(const FindInformation& findInformation) {
17
+ auto autoSelectList = gcnew AutomatedSelectList(findInformation);
13
18
  return autoSelectList->SelectedIndex;
14
19
  }
15
20
 
@@ -20,8 +25,8 @@ extern "C" {
20
25
  StringHelper::CopyToUnmanagedString(firstSelection, selection, selectionLength);
21
26
  }
22
27
 
23
- __declspec ( dllexport ) bool SelectList_ValueAt(const HWND windowHandle, const int whichItem, char* comboValue, const int comboValueSize) {
24
- auto autoSelectList = gcnew AutomatedSelectList(windowHandle);
28
+ __declspec ( dllexport ) bool SelectList_ValueAt(const FindInformation& findInformation, const int whichItem, char* comboValue, const int comboValueSize) {
29
+ auto autoSelectList = gcnew AutomatedSelectList(findInformation);
25
30
  return autoSelectList->GetValueByIndex(whichItem, comboValue, comboValueSize);
26
31
  }
27
32
 
@@ -3,13 +3,13 @@
3
3
 
4
4
  extern "C" {
5
5
 
6
- __declspec ( dllexport ) int Table_GetHeaders(const HWND windowHandle, const char* headers[]) {
7
- auto tableControl = gcnew AutomatedTable(windowHandle);
6
+ __declspec ( dllexport ) int Table_GetHeaders(const FindInformation& findInformation, const char* headers[]) {
7
+ auto tableControl = gcnew AutomatedTable(findInformation);
8
8
  return tableControl->GetHeaders(headers);
9
9
  }
10
10
 
11
- __declspec ( dllexport ) int Table_GetValues(const HWND windowHandle, const char* values[]) {
12
- auto tableControl = gcnew AutomatedTable(windowHandle);
11
+ __declspec ( dllexport ) int Table_GetValues(const FindInformation& findInformation, const char* values[]) {
12
+ auto tableControl = gcnew AutomatedTable(findInformation);
13
13
  return tableControl->GetValues(values);
14
14
  }
15
15
 
@@ -18,18 +18,18 @@ extern "C" {
18
18
  return tableControl->GetValues(values);
19
19
  }
20
20
 
21
- __declspec ( dllexport ) int Table_RowCount(const HWND windowHandle) {
21
+ __declspec ( dllexport ) int Table_RowCount(const FindInformation& findInformation) {
22
22
  try {
23
- auto tableControl = gcnew AutomatedTable(windowHandle);
23
+ auto tableControl = gcnew AutomatedTable(findInformation);
24
24
  return tableControl->RowCount;
25
25
  } catch(Exception^ e) {
26
26
  Console::WriteLine(e->ToString());
27
27
  }
28
28
  }
29
29
 
30
- __declspec ( dllexport ) bool Table_CoordinateIsValid(const HWND windowHandle, const int whichItemIndex, const int whichColumnIndex) {
30
+ __declspec ( dllexport ) bool Table_CoordinateIsValid(const FindInformation& findInformation, const int whichItemIndex, const int whichColumnIndex) {
31
31
  try {
32
- auto tableControl = gcnew AutomatedTable(windowHandle);
32
+ auto tableControl = gcnew AutomatedTable(findInformation);
33
33
  return tableControl->Exists(whichItemIndex, whichColumnIndex);
34
34
  } catch(Exception^ e) {
35
35
  Console::WriteLine(e->ToString());
@@ -37,9 +37,9 @@ extern "C" {
37
37
  }
38
38
  }
39
39
 
40
- __declspec ( dllexport ) void Table_ValueAt(const HWND windowHandle, const int row, const int column, char *foundValue, const int foundValueLength) {
40
+ __declspec ( dllexport ) void Table_ValueAt(const FindInformation& findInformation, const int row, const int column, char *foundValue, const int foundValueLength) {
41
41
  try {
42
- auto tableControl = gcnew AutomatedTable(windowHandle);
42
+ auto tableControl = gcnew AutomatedTable(findInformation);
43
43
  auto rowValue = tableControl->ValueAt(row, column);
44
44
  StringHelper::CopyToUnmanagedString(rowValue, foundValue, foundValueLength);
45
45
  } catch(Exception^ e) {
@@ -47,27 +47,27 @@ extern "C" {
47
47
  }
48
48
  }
49
49
 
50
- __declspec ( dllexport ) void Table_SelectByIndex(const HWND windowHandle, const int dataItemIndex) {
50
+ __declspec ( dllexport ) void Table_SelectByIndex(const FindInformation& findInformation, const int dataItemIndex) {
51
51
  try {
52
- auto tableControl = gcnew AutomatedTable(windowHandle);
52
+ auto tableControl = gcnew AutomatedTable(findInformation);
53
53
  tableControl->Select(dataItemIndex);
54
54
  } catch(Exception^ e) {
55
55
  Console::WriteLine(e->ToString());
56
56
  }
57
57
  }
58
58
 
59
- __declspec ( dllexport ) bool Table_IsSelectedByIndex(const HWND windowHandle, const int dataItemIndex) {
59
+ __declspec ( dllexport ) bool Table_IsSelectedByIndex(const FindInformation& findInformation, const int dataItemIndex) {
60
60
  try {
61
- auto tableControl = gcnew AutomatedTable(windowHandle);
61
+ auto tableControl = gcnew AutomatedTable(findInformation);
62
62
  return tableControl->IsSelected(dataItemIndex);
63
63
  } catch(Exception^ e) {
64
64
  Console::WriteLine(e->ToString());
65
65
  }
66
66
  }
67
67
 
68
- __declspec ( dllexport ) void Table_SelectByValue(const HWND windowHandle, const char* dataItemValue) {
68
+ __declspec ( dllexport ) void Table_SelectByValue(const FindInformation& findInformation, const char* dataItemValue) {
69
69
  try {
70
- auto tableControl = gcnew AutomatedTable(windowHandle);
70
+ auto tableControl = gcnew AutomatedTable(findInformation);
71
71
  tableControl->Select(dataItemValue);
72
72
  } catch(Exception^ e) {
73
73
  Console::WriteLine(e->ToString());
@@ -14,12 +14,12 @@ IUIAutomation* getGlobalIUIAutomation() ;
14
14
 
15
15
  extern "C" {
16
16
 
17
- __declspec ( dllexport ) bool ElementExists(const FindInformation& findInformation) {
18
- auto automationElement = gcnew AutomationControl(findInformation);
19
- return automationElement->Exists;
20
- }
17
+ __declspec ( dllexport ) bool ElementExists(const FindInformation& findInformation) {
18
+ auto automationElement = gcnew AutomationControl(findInformation);
19
+ return automationElement->Exists;
20
+ }
21
21
 
22
- __declspec ( dllexport ) int BoundingRectangle(const FindInformation& findInformation, long *rectangle) {
22
+ __declspec ( dllexport ) int BoundingRectangle(const FindInformation& findInformation, long *rectangle) {
23
23
  try {
24
24
  auto automationElement = gcnew AutomationControl(findInformation);
25
25
  auto boundary = automationElement->BoundingRectangle;
@@ -34,9 +34,9 @@ extern "C" {
34
34
  Console::WriteLine("BoundingRectangle: {0}", e->Message);
35
35
  return 0;
36
36
  }
37
- }
37
+ }
38
38
 
39
- __declspec ( dllexport ) int ControlType(const FindInformation& findInformation) {
39
+ __declspec ( dllexport ) int ControlType(const FindInformation& findInformation) {
40
40
  try {
41
41
  auto automationElement = gcnew AutomationControl(findInformation);
42
42
  return automationElement->ControlType->Id;
@@ -44,7 +44,7 @@ extern "C" {
44
44
  Console::WriteLine("ControlType: {0}", e->Message);
45
45
  return 0;
46
46
  }
47
- }
47
+ }
48
48
 
49
49
  __declspec ( dllexport ) int ProcessId(const FindInformation& findInformation) {
50
50
  try {
@@ -57,21 +57,49 @@ extern "C" {
57
57
  }
58
58
 
59
59
  __declspec ( dllexport ) void Name(const FindInformation& findInformation, char* name, const int nameLength) {
60
- try {
61
- auto control = gcnew AutomationControl(findInformation);
62
- StringHelper::CopyToUnmanagedString(control->Name, name, nameLength);
63
- } catch(Exception^ e) {
60
+ try {
61
+ auto control = gcnew AutomationControl(findInformation);
62
+ StringHelper::CopyToUnmanagedString(control->Name, name, nameLength);
63
+ } catch(Exception^ e) {
64
64
  Console::WriteLine("Name: {0}", e->Message);
65
- }
65
+ }
66
66
  }
67
67
 
68
68
  __declspec ( dllexport ) void ClassName(const FindInformation& findInformation, char* className, const int classNameLength) {
69
- try {
70
- auto control = gcnew AutomationControl(findInformation);
71
- StringHelper::CopyToUnmanagedString(control->ClassName, className, classNameLength);
72
- } catch(Exception^ e) {
69
+ try {
70
+ auto control = gcnew AutomationControl(findInformation);
71
+ StringHelper::CopyToUnmanagedString(control->ClassName, className, classNameLength);
72
+ } catch(Exception^ e) {
73
73
  Console::WriteLine("ClassName: {0}", e->Message);
74
- }
74
+ }
75
+ }
76
+
77
+ __declspec ( dllexport ) bool IsEnabled(const FindInformation& findInformation) {
78
+ try {
79
+ return (gcnew AutomationControl(findInformation))->IsEnabled;
80
+ } catch(Exception^ e) {
81
+ Console::WriteLine("IsEnabled: {0}", e->Message);
82
+ return false;
83
+ }
84
+ }
85
+
86
+ __declspec ( dllexport ) bool IsFocused(const FindInformation& findInformation) {
87
+ try {
88
+ return (gcnew AutomationControl(findInformation))->IsFocused;
89
+ } catch(Exception^ e) {
90
+ Console::WriteLine("IsFocused: {0}", e->Message);
91
+ return false;
92
+ }
93
+ }
94
+
95
+ __declspec ( dllexport ) bool SetControlFocus(const FindInformation& findInformation) {
96
+ try {
97
+ (gcnew AutomationControl(findInformation))->Element->SetFocus();
98
+ return true;
99
+ } catch(Exception^ e) {
100
+ Console::WriteLine("IsFocused: {0}", e->Message);
101
+ return false;
102
+ }
75
103
  }
76
104
 
77
105
  __declspec ( dllexport ) int GetClassNames(const FindInformation& findInformation, const char* classNames[]) {
@@ -87,173 +115,165 @@ extern "C" {
87
115
  return allChildren->Count;
88
116
  }
89
117
 
90
- __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromHandle(HWND hwnd) {
91
- IUIAutomationElement *pElement ;
92
-
93
- HRESULT hr = getGlobalIUIAutomation()->ElementFromHandle(hwnd, &pElement) ;
94
- if (SUCCEEDED(hr))
95
- return pElement ;
96
- else {
97
- printf("RA_ElementFromHandle: Cannot find element from handle 0x%x. HRESULT was 0x%x\r\n", hwnd, hr) ;
98
- return NULL ;
99
- }
100
- }
101
-
102
- __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromPoint(int xCoord, int yCoord) {
103
- IUIAutomationElement *pElement ;
104
- POINT point;
105
-
106
- point.x = xCoord;
107
- point.y = yCoord;
108
-
109
- HRESULT hr = getGlobalIUIAutomation()->ElementFromPoint(point, &pElement) ;
110
- if (SUCCEEDED(hr))
111
- return pElement ;
112
- else {
113
- printf("RA_ElementFromPoint: Cannot find element from point %d , %d. HRESULT was 0x%x\r\n", xCoord, yCoord, hr) ;
114
- return NULL ;
115
- }
116
- }
117
-
118
- __declspec ( dllexport ) IUIAutomationElement *RA_FindChildById(IUIAutomationElement *pElement, char *automationId) {
119
- IUIAutomationCondition *pCondition ;
120
- VARIANT varProperty ;
121
-
122
- VariantInit(&varProperty) ;
123
- varProperty.vt = VT_BSTR ;
124
- varProperty.bstrVal = _bstr_t(automationId) ;
125
-
126
- HRESULT hr = getGlobalIUIAutomation()->CreatePropertyCondition(UIA_AutomationIdPropertyId, varProperty, &pCondition) ;
127
- if (SUCCEEDED(hr)) {
128
- IUIAutomationElement *pFound ;
129
-
130
- hr = pElement->FindFirst(TreeScope_Descendants, pCondition, &pFound) ;
131
- if (SUCCEEDED(hr)) {
132
- if (pFound == NULL)
133
- printf("RA_FindChildById: Element with automation id %s was not found\r\n", automationId) ;
134
-
135
- return pFound ;
136
- } else {
137
- printf("RA_FindChildById: FindFirst for children looking for %s failed. hr = 0x%x\r\n", automationId, hr) ;
138
- return NULL ;
139
- }
140
- } else {
141
- printf("RA_FindChildById: Cannot create search condition. hr = 0x%x\r\n", hr) ;
142
- return NULL ;
143
- }
144
- }
145
-
146
- __declspec ( dllexport ) HWND RA_CurrentNativeWindowHandle(IUIAutomationElement *pElement) {
147
- UIA_HWND uia_hwnd ;
148
-
149
- if (pElement == NULL) {
150
- printf("RA_CurrentNativeWindowHandle: Cannot operate on NULL element\r\n") ;
151
- return (HWND)0 ;
152
- }
153
-
154
- pElement->get_CurrentNativeWindowHandle(&uia_hwnd) ;
155
- return (HWND)uia_hwnd ;
156
- }
157
-
158
- __declspec ( dllexport ) BOOL RA_SetFocus(IUIAutomationElement *pElement) {
159
- HRESULT hr = pElement->SetFocus() ;
160
- if (hr != S_OK)
161
- printf("RA_SetFocus: SetFocus on element returned 0x%x\r\n", hr) ;
162
-
163
- return SUCCEEDED(hr) ;
164
- }
165
-
166
- __declspec ( dllexport ) int RA_GetCurrentControlType(IUIAutomationElement *pElement) {
167
- CONTROLTYPEID control_type ;
168
-
169
- HRESULT hr = pElement->get_CurrentControlType(&control_type) ;
170
- if (SUCCEEDED(hr))
171
- return control_type ;
172
- else {
173
- printf("RA_GetCurrentControlType: CurrentControlType returned 0x%x\r\n", hr) ;
174
- return 0 ;
175
- }
176
- }
177
-
178
- __declspec ( dllexport ) long RA_ClickMouse() {
179
- mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
180
- mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
181
- return 0;
182
- }
183
-
184
- __declspec ( dllexport ) long RA_MoveMouse(int x, int y) {
185
- return SetCursorPos(x,y);
186
- }
187
-
188
- __declspec ( dllexport ) int RA_CurrentIsOffscreen(IUIAutomationElement *pElement, int *visible) {
189
- BOOL offscreen;
190
-
191
- HRESULT hr = pElement->get_CurrentIsOffscreen(&offscreen) ;
192
- if (SUCCEEDED(hr)) {
193
- if(offscreen){
194
- *visible = 1;
195
- }
196
- else
197
- {
198
- *visible = 0;
199
- }
200
- return 1;
201
- }
202
- else {
203
- printf("RA_CurrentIsOffscreen: get_CurrentIsOffscreen failed 0x%x\r\n", hr) ;
204
- return 0 ;
205
- }
206
- }
207
-
208
- __declspec ( dllexport ) int RA_FindChildren(IUIAutomationElement *pElement, IUIAutomationElement *pChildren[]) {
209
- IUIAutomationCondition *pTrueCondition ;
210
- IUIAutomationElementArray *pElementArray ;
211
- int element_count ;
212
-
213
- HRESULT hr = getGlobalIUIAutomation()->CreateTrueCondition(&pTrueCondition) ;
214
- if (FAILED(hr)) {
215
- printf("RA_FindChildren: Could not create true condition 0x%x\r\n", hr) ;
216
- return 0 ;
217
- }
218
-
219
- hr = pElement->FindAll(TreeScope_Children, pTrueCondition, &pElementArray) ;
220
- if (FAILED(hr)) {
221
- printf("RA_FindChildren: FindAll failed 0x%x\r\n", hr) ;
222
- return 0 ;
223
- }
224
-
225
- hr = pElementArray->get_Length(&element_count) ;
226
- if (FAILED(hr)) {
227
- printf("RA_FindChildren: get_length failed 0x%x\r\n", hr) ;
228
- return 0 ;
229
- }
230
-
231
- if (pChildren != NULL) {
232
- // given some memory get the details
233
- for (int index = 0; index < element_count; index++) {
234
- IUIAutomationElement *pElement ;
235
-
236
- hr = pElementArray->GetElement(index, &pElement) ;
237
- if (FAILED(hr)) {
238
- printf("RA_FindChildren: GetElement failed 0x%x\r\n", hr) ;
239
- } else {
240
- pChildren[index] = pElement ;
241
- }
242
- }
243
- }
244
-
245
- return element_count ;
246
- }
247
-
248
- __declspec ( dllexport ) bool RA_GetControlName(const HWND windowHandle, char* windowName, const int windowNameLength) {
249
- try {
250
- auto control = gcnew AutomationControl(windowHandle);
251
- StringHelper::CopyToUnmanagedString(control->Name, windowName, windowNameLength);
252
- return true;
253
- } catch(Exception^ e) {
254
- return false;
255
- }
256
- }
118
+ __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromHandle(HWND hwnd) {
119
+ IUIAutomationElement *pElement ;
120
+
121
+ HRESULT hr = getGlobalIUIAutomation()->ElementFromHandle(hwnd, &pElement) ;
122
+ if (SUCCEEDED(hr))
123
+ return pElement ;
124
+ else {
125
+ printf("RA_ElementFromHandle: Cannot find element from handle 0x%x. HRESULT was 0x%x\r\n", hwnd, hr) ;
126
+ return NULL ;
127
+ }
128
+ }
129
+
130
+ __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromPoint(int xCoord, int yCoord) {
131
+ IUIAutomationElement *pElement ;
132
+ POINT point;
133
+
134
+ point.x = xCoord;
135
+ point.y = yCoord;
136
+
137
+ HRESULT hr = getGlobalIUIAutomation()->ElementFromPoint(point, &pElement) ;
138
+ if (SUCCEEDED(hr))
139
+ return pElement ;
140
+ else {
141
+ printf("RA_ElementFromPoint: Cannot find element from point %d , %d. HRESULT was 0x%x\r\n", xCoord, yCoord, hr) ;
142
+ return NULL ;
143
+ }
144
+ }
145
+
146
+ __declspec ( dllexport ) IUIAutomationElement *RA_FindChildById(IUIAutomationElement *pElement, char *automationId) {
147
+ IUIAutomationCondition *pCondition ;
148
+ VARIANT varProperty ;
149
+
150
+ VariantInit(&varProperty) ;
151
+ varProperty.vt = VT_BSTR ;
152
+ varProperty.bstrVal = _bstr_t(automationId) ;
153
+
154
+ HRESULT hr = getGlobalIUIAutomation()->CreatePropertyCondition(UIA_AutomationIdPropertyId, varProperty, &pCondition) ;
155
+ if (SUCCEEDED(hr)) {
156
+ IUIAutomationElement *pFound ;
157
+
158
+ hr = pElement->FindFirst(TreeScope_Descendants, pCondition, &pFound) ;
159
+ if (SUCCEEDED(hr)) {
160
+ if (pFound == NULL)
161
+ printf("RA_FindChildById: Element with automation id %s was not found\r\n", automationId) ;
162
+
163
+ return pFound ;
164
+ } else {
165
+ printf("RA_FindChildById: FindFirst for children looking for %s failed. hr = 0x%x\r\n", automationId, hr) ;
166
+ return NULL ;
167
+ }
168
+ } else {
169
+ printf("RA_FindChildById: Cannot create search condition. hr = 0x%x\r\n", hr) ;
170
+ return NULL ;
171
+ }
172
+ }
173
+
174
+ __declspec ( dllexport ) HWND RA_CurrentNativeWindowHandle(IUIAutomationElement *pElement) {
175
+ UIA_HWND uia_hwnd ;
176
+
177
+ if (pElement == NULL) {
178
+ printf("RA_CurrentNativeWindowHandle: Cannot operate on NULL element\r\n") ;
179
+ return (HWND)0 ;
180
+ }
181
+
182
+ pElement->get_CurrentNativeWindowHandle(&uia_hwnd) ;
183
+ return (HWND)uia_hwnd ;
184
+ }
185
+
186
+ __declspec ( dllexport ) int RA_GetCurrentControlType(IUIAutomationElement *pElement) {
187
+ CONTROLTYPEID control_type ;
188
+
189
+ HRESULT hr = pElement->get_CurrentControlType(&control_type) ;
190
+ if (SUCCEEDED(hr))
191
+ return control_type ;
192
+ else {
193
+ printf("RA_GetCurrentControlType: CurrentControlType returned 0x%x\r\n", hr) ;
194
+ return 0 ;
195
+ }
196
+ }
197
+
198
+ __declspec ( dllexport ) long RA_ClickMouse() {
199
+ mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
200
+ mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
201
+ return 0;
202
+ }
203
+
204
+ __declspec ( dllexport ) long RA_MoveMouse(int x, int y) {
205
+ return SetCursorPos(x,y);
206
+ }
207
+
208
+ __declspec ( dllexport ) int RA_CurrentIsOffscreen(IUIAutomationElement *pElement, int *visible) {
209
+ BOOL offscreen;
210
+
211
+ HRESULT hr = pElement->get_CurrentIsOffscreen(&offscreen) ;
212
+ if (SUCCEEDED(hr)) {
213
+ if(offscreen){
214
+ *visible = 1;
215
+ }
216
+ else
217
+ {
218
+ *visible = 0;
219
+ }
220
+ return 1;
221
+ }
222
+ else {
223
+ printf("RA_CurrentIsOffscreen: get_CurrentIsOffscreen failed 0x%x\r\n", hr) ;
224
+ return 0 ;
225
+ }
226
+ }
227
+
228
+ __declspec ( dllexport ) int RA_FindChildren(IUIAutomationElement *pElement, IUIAutomationElement *pChildren[]) {
229
+ IUIAutomationCondition *pTrueCondition ;
230
+ IUIAutomationElementArray *pElementArray ;
231
+ int element_count ;
232
+
233
+ HRESULT hr = getGlobalIUIAutomation()->CreateTrueCondition(&pTrueCondition) ;
234
+ if (FAILED(hr)) {
235
+ printf("RA_FindChildren: Could not create true condition 0x%x\r\n", hr) ;
236
+ return 0 ;
237
+ }
238
+
239
+ hr = pElement->FindAll(TreeScope_Children, pTrueCondition, &pElementArray) ;
240
+ if (FAILED(hr)) {
241
+ printf("RA_FindChildren: FindAll failed 0x%x\r\n", hr) ;
242
+ return 0 ;
243
+ }
244
+
245
+ hr = pElementArray->get_Length(&element_count) ;
246
+ if (FAILED(hr)) {
247
+ printf("RA_FindChildren: get_length failed 0x%x\r\n", hr) ;
248
+ return 0 ;
249
+ }
250
+
251
+ if (pChildren != NULL) {
252
+ // given some memory get the details
253
+ for (int index = 0; index < element_count; index++) {
254
+ IUIAutomationElement *pElement ;
255
+
256
+ hr = pElementArray->GetElement(index, &pElement) ;
257
+ if (FAILED(hr)) {
258
+ printf("RA_FindChildren: GetElement failed 0x%x\r\n", hr) ;
259
+ } else {
260
+ pChildren[index] = pElement ;
261
+ }
262
+ }
263
+ }
264
+
265
+ return element_count ;
266
+ }
267
+
268
+ __declspec ( dllexport ) bool RA_GetControlName(const HWND windowHandle, char* windowName, const int windowNameLength) {
269
+ try {
270
+ auto control = gcnew AutomationControl(windowHandle);
271
+ StringHelper::CopyToUnmanagedString(control->Name, windowName, windowNameLength);
272
+ return true;
273
+ } catch(Exception^ e) {
274
+ return false;
275
+ }
276
+ }
257
277
 
258
278
  __declspec ( dllexport ) bool IsSet(const FindInformation& findInformation) {
259
279
  try {
@@ -275,78 +295,78 @@ extern "C" {
275
295
  }
276
296
  }
277
297
 
278
- __declspec ( dllexport ) int RA_Select(IUIAutomationElement *pElement) {
279
- ISelectionItemProvider *pSelectionPattern ;
280
- HRESULT hr = pElement->GetCurrentPattern(UIA_SelectionItemPatternId, (IUnknown**)&pSelectionPattern) ;
281
- if (FAILED(hr)) {
282
- printf("RA_GetIsSelected: getCurrentPattern failed 0x%x\r\n") ;
283
- return FALSE ;
284
- }
285
-
286
- hr = pSelectionPattern->Select();
287
- if (FAILED(hr)) {
288
- printf("RA_Select: Select failed 0x%x\r\n", hr) ;
289
- return 0 ;
290
- }
291
-
292
- return 1;
293
- }
294
-
295
- __declspec ( dllexport ) void RA_Click(const HWND windowHandle, char* errorInfo, const int errorInfoSize) {
296
- try {
297
- auto automationClicker = gcnew AutomationClicker(windowHandle);
298
- automationClicker->Click();
299
- } catch(Exception^ e) {
300
- if( errorInfo ) {
301
- StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
302
- }
303
- }
304
- }
305
-
306
- __declspec ( dllexport ) void RA_PointAndClick(const HWND windowHandle, char* errorInfo, const int errorInfoSize) {
307
- try {
308
- auto automationClicker = gcnew AutomationClicker(windowHandle);
309
- automationClicker->MouseClick();
310
- } catch(Exception^ e) {
311
- if( errorInfo ) {
312
- StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
313
- }
314
- }
315
- }
316
-
317
- __declspec ( dllexport ) void RA_ExpandItemByValue(const HWND windowHandle, const char* whichItem) {
318
- try {
319
- auto expandCollapseHelper = gcnew ExpandCollapseHelper();
320
- expandCollapseHelper->ExpandByValue(windowHandle, whichItem);
321
- } catch(Exception^ e) {
322
- Console::WriteLine(e->ToString());
323
- }
324
- }
325
-
326
- __declspec ( dllexport ) void RA_ExpandItemByIndex(const HWND windowHandle, const int whichItemIndex) {
327
- try {
328
- auto expandCollapseHelper = gcnew ExpandCollapseHelper();
329
- expandCollapseHelper->ExpandByIndex(windowHandle, whichItemIndex);
330
- } catch(Exception^ e) {
331
- Console::WriteLine(e->ToString());
332
- }
333
- }
334
-
335
- __declspec ( dllexport ) void RA_CollapseItemByValue(const HWND windowHandle, const char* whichItem) {
336
- try {
337
- auto expandCollapseHelper = gcnew ExpandCollapseHelper();
338
- expandCollapseHelper->CollapseByValue(windowHandle, whichItem);
339
- } catch(Exception^ e) {
340
- Console::WriteLine(e->ToString());
341
- }
342
- }
343
-
344
- __declspec ( dllexport ) void RA_CollapseItemByIndex(const HWND windowHandle, const int whichItemIndex) {
345
- try {
346
- auto expandCollapseHelper = gcnew ExpandCollapseHelper();
347
- expandCollapseHelper->CollapseByIndex(windowHandle, whichItemIndex);
348
- } catch(Exception^ e) {
349
- Console::WriteLine(e->ToString());
350
- }
351
- }
298
+ __declspec ( dllexport ) int RA_Select(IUIAutomationElement *pElement) {
299
+ ISelectionItemProvider *pSelectionPattern ;
300
+ HRESULT hr = pElement->GetCurrentPattern(UIA_SelectionItemPatternId, (IUnknown**)&pSelectionPattern) ;
301
+ if (FAILED(hr)) {
302
+ printf("RA_GetIsSelected: getCurrentPattern failed 0x%x\r\n") ;
303
+ return FALSE ;
304
+ }
305
+
306
+ hr = pSelectionPattern->Select();
307
+ if (FAILED(hr)) {
308
+ printf("RA_Select: Select failed 0x%x\r\n", hr) ;
309
+ return 0 ;
310
+ }
311
+
312
+ return 1;
313
+ }
314
+
315
+ __declspec ( dllexport ) void RA_Click(const FindInformation& findInformation, char* errorInfo, const int errorInfoSize) {
316
+ try {
317
+ auto automationClicker = gcnew AutomationClicker(findInformation);
318
+ automationClicker->Click();
319
+ } catch(Exception^ e) {
320
+ if( errorInfo ) {
321
+ StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
322
+ }
323
+ }
324
+ }
325
+
326
+ __declspec ( dllexport ) void RA_PointAndClick(const HWND windowHandle, char* errorInfo, const int errorInfoSize) {
327
+ try {
328
+ auto automationClicker = gcnew AutomationClicker(windowHandle);
329
+ automationClicker->MouseClick();
330
+ } catch(Exception^ e) {
331
+ if( errorInfo ) {
332
+ StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
333
+ }
334
+ }
335
+ }
336
+
337
+ __declspec ( dllexport ) void RA_ExpandItemByValue(const FindInformation& findInformation, const char* whichItem) {
338
+ try {
339
+ auto expandCollapseHelper = gcnew ExpandCollapseHelper();
340
+ expandCollapseHelper->ExpandByValue(findInformation, whichItem);
341
+ } catch(Exception^ e) {
342
+ Console::WriteLine(e->ToString());
343
+ }
344
+ }
345
+
346
+ __declspec ( dllexport ) void RA_ExpandItemByIndex(const FindInformation& findInformation, const int whichItemIndex) {
347
+ try {
348
+ auto expandCollapseHelper = gcnew ExpandCollapseHelper();
349
+ expandCollapseHelper->ExpandByIndex(findInformation, whichItemIndex);
350
+ } catch(Exception^ e) {
351
+ Console::WriteLine(e->ToString());
352
+ }
353
+ }
354
+
355
+ __declspec ( dllexport ) void RA_CollapseItemByValue(const FindInformation& findInformation, const char* whichItem) {
356
+ try {
357
+ auto expandCollapseHelper = gcnew ExpandCollapseHelper();
358
+ expandCollapseHelper->CollapseByValue(findInformation, whichItem);
359
+ } catch(Exception^ e) {
360
+ Console::WriteLine(e->ToString());
361
+ }
362
+ }
363
+
364
+ __declspec ( dllexport ) void RA_CollapseItemByIndex(const FindInformation& findInformation, const int whichItemIndex) {
365
+ try {
366
+ auto expandCollapseHelper = gcnew ExpandCollapseHelper();
367
+ expandCollapseHelper->CollapseByIndex(findInformation, whichItemIndex);
368
+ } catch(Exception^ e) {
369
+ Console::WriteLine(e->ToString());
370
+ }
371
+ }
352
372
  }