rautomation 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +3 -3
  4. data/History.rdoc +17 -0
  5. data/README.rdoc +2 -1
  6. data/Rakefile +23 -6
  7. data/VERSION +1 -1
  8. data/ext/IAccessibleDLL/Release/IAccessibleDLL.dll +0 -0
  9. data/ext/UiaDll/Release/UiaDll.dll +0 -0
  10. data/ext/UiaDll/UiaDll/{AutomatedComboBox.cpp → AutomatedSelectList.cpp} +22 -11
  11. data/ext/UiaDll/UiaDll/{AutomatedComboBox.h → AutomatedSelectList.h} +17 -4
  12. data/ext/UiaDll/UiaDll/AutomatedTable.cpp +55 -13
  13. data/ext/UiaDll/UiaDll/AutomatedTable.h +16 -3
  14. data/ext/UiaDll/UiaDll/AutomationControl.cpp +28 -0
  15. data/ext/UiaDll/UiaDll/AutomationControl.h +56 -0
  16. data/ext/UiaDll/UiaDll/AutomationFinder.cpp +57 -0
  17. data/ext/UiaDll/UiaDll/AutomationFinder.h +48 -0
  18. data/ext/UiaDll/UiaDll/ControlMethods.cpp +15 -0
  19. data/ext/UiaDll/UiaDll/MenuItemSelector.h +2 -0
  20. data/ext/UiaDll/UiaDll/MenuMethods.cpp +58 -0
  21. data/ext/UiaDll/UiaDll/SelectListMethods.cpp +37 -0
  22. data/ext/UiaDll/UiaDll/SelectionItem.cpp +10 -0
  23. data/ext/UiaDll/UiaDll/SelectionItem.h +21 -0
  24. data/ext/UiaDll/UiaDll/StringHelper.cpp +33 -2
  25. data/ext/UiaDll/UiaDll/StringHelper.h +6 -0
  26. data/ext/UiaDll/UiaDll/StringMethods.cpp +8 -0
  27. data/ext/UiaDll/UiaDll/TableMethods.cpp +76 -0
  28. data/ext/UiaDll/UiaDll/Toggle.cpp +2 -0
  29. data/ext/UiaDll/UiaDll/Toggle.h +22 -0
  30. data/ext/UiaDll/UiaDll/UiaDll.cpp +96 -327
  31. data/ext/UiaDll/UiaDll/UiaDll.vcxproj +15 -4
  32. data/ext/UiaDll/UiaDll/UiaDll.vcxproj.filters +91 -22
  33. data/ext/UiaDll/UiaDll/dllmain.cpp +1 -1
  34. data/ext/UiaDll/UiaDll/stdafx.h +38 -21
  35. data/ext/WindowsForms/Release/WindowsForms.exe +0 -0
  36. data/ext/WindowsForms/WindowsForms.sln +10 -0
  37. data/ext/WindowsForms/WindowsForms/AutomatableMonthCalendar.cs +59 -0
  38. data/ext/WindowsForms/WindowsForms/AutomationHelpers/AutomationProvider.cs +91 -0
  39. data/ext/WindowsForms/WindowsForms/MainFormWindow.Designer.cs +32 -10
  40. data/ext/WindowsForms/WindowsForms/MainFormWindow.cs +10 -0
  41. data/ext/WindowsForms/WindowsForms/WindowsForms.csproj +15 -6
  42. data/lib/rautomation/adapter/ms_uia.rb +1 -0
  43. data/lib/rautomation/adapter/ms_uia/checkbox.rb +2 -10
  44. data/lib/rautomation/adapter/ms_uia/constants.rb +1 -0
  45. data/lib/rautomation/adapter/ms_uia/control.rb +14 -67
  46. data/lib/rautomation/adapter/ms_uia/functions.rb +2 -18
  47. data/lib/rautomation/adapter/ms_uia/list_box.rb +5 -27
  48. data/lib/rautomation/adapter/ms_uia/list_item.rb +2 -29
  49. data/lib/rautomation/adapter/ms_uia/radio.rb +1 -1
  50. data/lib/rautomation/adapter/ms_uia/select_list.rb +5 -6
  51. data/lib/rautomation/adapter/ms_uia/table.rb +15 -50
  52. data/lib/rautomation/adapter/ms_uia/text_field.rb +1 -1
  53. data/lib/rautomation/adapter/ms_uia/uia_dll.rb +226 -58
  54. data/lib/rautomation/adapter/ms_uia/value_control.rb +21 -0
  55. data/lib/rautomation/adapter/ms_uia/window.rb +6 -104
  56. data/lib/rautomation/adapter/win_32/functions.rb +0 -23
  57. data/lib/rautomation/adapter/win_32/keys.rb +64 -61
  58. data/rautomation.gemspec +6 -1
  59. data/spec/adapter/autoit/mouse_spec.rb +1 -1
  60. data/spec/adapter/ms_uia/select_list_spec.rb +0 -21
  61. data/spec/adapter/ms_uia/table_spec.rb +13 -11
  62. data/spec/adapter/ms_uia/text_field_spec.rb +15 -8
  63. data/spec/adapter/ms_uia/value_control_spec.rb +11 -0
  64. data/spec/adapter/ms_uia/window_spec.rb +7 -1
  65. data/spec/adapter/win_32/mouse_spec.rb +1 -1
  66. data/spec/adapter/win_32/text_field_spec.rb +5 -5
  67. data/spec/adapter/win_32/window_spec.rb +1 -1
  68. data/spec/text_field_spec.rb +18 -23
  69. data/spec/window_spec.rb +1 -3
  70. metadata +45 -34
  71. data/ext/UiaDll/UiaDll/ToggleStateHelper.cpp +0 -33
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd70f4859a5f1f16541465e836d116265af26eb4
4
+ data.tar.gz: 7bae3a8bc91207cdfa3e302ffdbde778ead2ac69
5
+ SHA512:
6
+ metadata.gz: ea5fd4f9d351eec5ffe23f207ab5f6679d861d410adc6fe908902497195c3ce776deff5c1428afd884c9bd8ef62a1f57d11da968bad26e2ca638afaea06dc529
7
+ data.tar.gz: f9c6a60d917eeef6178a4fdc9f3f68d8cbd04e8ee4d6194130859036d243cb842167a68900cc2ad811659099ca682c08ccfa30763f8aa6d0a1e4a491744e9d1c
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rautomation (0.7.3)
4
+ rautomation (0.9.0)
5
5
  ffi
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.1.3)
11
- ffi (1.1.5-x86-mingw32)
11
+ ffi (1.7.0-x86-mingw32)
12
12
  rake (0.9.2.2)
13
13
  rspec (2.8.0)
14
14
  rspec-core (~> 2.8.0)
data/History.rdoc CHANGED
@@ -1,3 +1,20 @@
1
+ == 0.9.0 / 2013-04-22
2
+
3
+ === MsUia adapter
4
+
5
+ * Add support for :name locator.
6
+ * Add support for Window#value_control.
7
+ * Add Table#headers.
8
+ * Add Table#values.
9
+ * Control#exists? uses now uia code.
10
+ * ControlType.Document is also considered as a TextField.
11
+ * Table#select and Table#selected? use 0-based indexing.
12
+ * Table#select supports value too.
13
+
14
+ === Win32 adapter
15
+
16
+ * Add support for "[", "]" and "'" characters when using Window#send_keys. Fixes #61.
17
+
1
18
  == 0.8.0 / 2012-12-26
2
19
 
3
20
  === MsUia adapter
data/README.rdoc CHANGED
@@ -1,9 +1,10 @@
1
1
  = RAutomation
2
+ {<img src="https://badge.fury.io/rb/rautomation.png" alt="Gem Version" />}[http://badge.fury.io/rb/rautomation]
2
3
 
3
4
  * Web: http://www.github.com/jarmo/RAutomation
4
5
  * Author: Jarmo Pertman (mailto:jarmo.p[at]gmail.com)
5
6
 
6
- {<img alt='Click here to lend your support to: RAutomation and make a donation at www.pledgie.com !' src='https://www.pledgie.com/campaigns/16196.png?skin_name=chrome' />}[https://www.pledgie.com/campaigns/16196]
7
+ {<img alt='Click here to lend your support to: RAutomation and make a donation at www.pledgie.com !' src='https://pledgie.com/campaigns/16196.png?skin_name=chrome' />}[https://pledgie.com/campaigns/16196]
7
8
 
8
9
  RAutomation is a small and easy to use library for helping out to automate windows and their controls
9
10
  for automated testing.
data/Rakefile CHANGED
@@ -3,18 +3,31 @@ require 'bundler'
3
3
 
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
+ def ext_dependencies(name)
7
+ FileList["ext/#{name}/**/*"].reject { |file| file =~ /\b(Release|Debug)\b/ }
8
+ end
9
+
10
+ def ms_build(name)
11
+ name = File.basename(name, File.extname(name))
12
+ sh "msbuild /property:Configuration=Release ext\\#{name}\\#{name}.sln"
13
+ end
14
+
6
15
  namespace :build do
7
16
  build_tasks = [
8
- {:name => :uia_dll, :path => "UiaDll"},
9
- {:name => :i_accessible_dll, :path => "IAccessibleDLL"},
10
- {:name => :windows_forms, :path => "WindowsForms"}
17
+ {:name => :uia_dll, :path => "UiaDll", :ext => "dll"},
18
+ {:name => :i_accessible_dll, :path => "IAccessibleDLL", :ext => "dll"},
19
+ {:name => :windows_forms, :path => "WindowsForms", :ext => "exe"}
11
20
  ]
12
21
 
13
22
  build_tasks.each do |build_task|
14
- desc "Build #{build_task[:path]}"
15
- task build_task[:name] do
16
- sh "msbuild /property:Configuration=Release ext\\#{build_task[:path]}\\#{build_task[:path]}.sln"
23
+ full_ext_path = "ext/#{build_task[:path]}/Release/#{build_task[:path]}.#{build_task[:ext]}"
24
+
25
+ file full_ext_path => ext_dependencies(build_task[:path]) do |t|
26
+ ms_build t.name
17
27
  end
28
+
29
+ desc "Build #{build_task[:path]}"
30
+ task build_task[:name] => full_ext_path
18
31
  end
19
32
 
20
33
  desc "Build all external dependencies"
@@ -51,3 +64,7 @@ require 'yard'
51
64
  YARD::Rake::YardocTask.new
52
65
 
53
66
  task :default => "spec:all"
67
+
68
+ task :release => "spec:all"
69
+
70
+ task :install => :build
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
Binary file
@@ -1,15 +1,26 @@
1
1
  #include "StdAfx.h"
2
- #include "AutomatedComboBox.h"
2
+ #include "AutomatedSelectList.h"
3
3
 
4
- AutomatedComboBox::AutomatedComboBox(const HWND windowHandle)
5
- {
6
- _comboControl = AutomationElement::FromHandle(IntPtr(windowHandle));
4
+ AutomatedSelectList::AutomatedSelectList(const HWND windowHandle) : AutomationControl(windowHandle)
5
+ { }
6
+
7
+ AutomatedSelectList::AutomatedSelectList(const FindInformation& findInformation) : AutomationControl(findInformation)
8
+ { }
9
+
10
+ array<String^>^ AutomatedSelectList::Selection::get() {
11
+ auto selectedElements = AsSelectionPattern->Current.GetSelection();
12
+ auto selections = gcnew array<String^>(selectedElements.Length);
13
+ auto whichOne = 0;
14
+ for each(auto element in selectedElements) {
15
+ selections[whichOne++] = element->Current.Name;
16
+ }
17
+ return selections;
7
18
  }
8
19
 
9
- bool AutomatedComboBox::SelectByIndex(const int whichItem)
20
+ bool AutomatedSelectList::SelectByIndex(const int whichItem)
10
21
  {
11
22
  try {
12
- auto selectionItems = _comboControl->FindAll(System::Windows::Automation::TreeScope::Subtree, SelectionCondition);
23
+ auto selectionItems = _control->FindAll(System::Windows::Automation::TreeScope::Subtree, SelectionCondition);
13
24
  Select(selectionItems[whichItem]);
14
25
  return true;
15
26
  } catch(Exception^ e) {
@@ -18,13 +29,13 @@ bool AutomatedComboBox::SelectByIndex(const int whichItem)
18
29
  }
19
30
  }
20
31
 
21
- bool AutomatedComboBox::SelectByValue(const char* whichItem)
32
+ bool AutomatedSelectList::SelectByValue(const char* whichItem)
22
33
  {
23
34
  try {
24
35
  auto nameCondition = gcnew PropertyCondition(AutomationElement::NameProperty, gcnew String(whichItem));
25
36
  auto selectionAndNameCondition = gcnew AndCondition(SelectionCondition, nameCondition);
26
37
 
27
- Select(_comboControl->FindFirst(System::Windows::Automation::TreeScope::Subtree, selectionAndNameCondition));
38
+ Select(_control->FindFirst(System::Windows::Automation::TreeScope::Subtree, selectionAndNameCondition));
28
39
  return true;
29
40
  } catch(Exception^ e) {
30
41
  Console::WriteLine(e->ToString());
@@ -32,7 +43,7 @@ bool AutomatedComboBox::SelectByValue(const char* whichItem)
32
43
  }
33
44
  }
34
45
 
35
- bool AutomatedComboBox::GetValueByIndex(const int whichItem, char* comboValue, const int comboValueSize)
46
+ bool AutomatedSelectList::GetValueByIndex(const int whichItem, char* comboValue, const int comboValueSize)
36
47
  {
37
48
  try {
38
49
  auto selectionItem = SelectionItems[whichItem];
@@ -46,7 +57,7 @@ bool AutomatedComboBox::GetValueByIndex(const int whichItem, char* comboValue, c
46
57
  }
47
58
  }
48
59
 
49
- int AutomatedComboBox::SelectedIndex::get() {
60
+ int AutomatedSelectList::SelectedIndex::get() {
50
61
  int selectedIndex = 0;
51
62
  for each(AutomationElement^ selectionItem in SelectionItems) {
52
63
  auto selectionPattern = dynamic_cast<SelectionItemPattern^>(selectionItem->GetCurrentPattern(SelectionItemPattern::Pattern));
@@ -59,7 +70,7 @@ int AutomatedComboBox::SelectedIndex::get() {
59
70
  }
60
71
 
61
72
 
62
- void AutomatedComboBox::Select(AutomationElement^ itemToSelect)
73
+ void AutomatedSelectList::Select(AutomationElement^ itemToSelect)
63
74
  {
64
75
  auto selectionPattern = dynamic_cast<SelectionItemPattern^>(itemToSelect->GetCurrentPattern(SelectionItemPattern::Pattern));
65
76
  selectionPattern->Select();
@@ -1,14 +1,22 @@
1
1
  #pragma once
2
+ #include "AutomationControl.h"
3
+ #include "StringHelper.h"
4
+
2
5
  using namespace System::Windows::Automation;
3
6
 
4
- public ref class AutomatedComboBox
7
+ ref class AutomatedSelectList : public AutomationControl
5
8
  {
6
9
  public:
7
- AutomatedComboBox(const HWND windowHandle);
10
+ AutomatedSelectList(const HWND windowHandle);
11
+ AutomatedSelectList(const FindInformation& findInformation);
8
12
  bool SelectByIndex(const int whichItem);
9
13
  bool SelectByValue(const char* whichItem);
10
14
  bool GetValueByIndex(const int whichItem, char* comboValue, const int comboValueSize);
11
15
 
16
+ property array<String^>^ Selection {
17
+ array<String^>^ get();
18
+ }
19
+
12
20
  property int Count {
13
21
  int get() { return SelectionItems->Count; }
14
22
  }
@@ -18,11 +26,16 @@ public:
18
26
  }
19
27
 
20
28
  private:
21
- AutomationElement^ _comboControl;
22
29
  void Select(AutomationElement^ itemToSelect);
23
30
 
31
+ property SelectionPattern^ AsSelectionPattern {
32
+ SelectionPattern^ get() {
33
+ return dynamic_cast<SelectionPattern^>(_control->GetCurrentPattern(SelectionPattern::Pattern));
34
+ }
35
+ }
36
+
24
37
  property AutomationElementCollection^ SelectionItems {
25
- AutomationElementCollection^ get() { return _comboControl->FindAll(System::Windows::Automation::TreeScope::Subtree, SelectionCondition); }
38
+ AutomationElementCollection^ get() { return _control->FindAll(System::Windows::Automation::TreeScope::Subtree, SelectionCondition); }
26
39
  }
27
40
 
28
41
  property PropertyCondition^ SelectionCondition {
@@ -1,20 +1,42 @@
1
1
  #include "StdAfx.h"
2
2
  #include "AutomatedTable.h"
3
3
 
4
- AutomatedTable::AutomatedTable(const HWND windowHandle)
4
+ AutomatedTable::AutomatedTable(const HWND windowHandle) : AutomationControl(windowHandle)
5
5
  {
6
- _tableControl = AutomationElement::FromHandle(IntPtr(windowHandle));
6
+ _finder = gcnew AutomationFinder(_control);
7
7
  }
8
8
 
9
- int AutomatedTable::RowCount::get()
9
+ AutomatedTable::AutomatedTable(const FindInformation& finderInformation) : AutomationControl(finderInformation)
10
10
  {
11
- auto tablePattern = dynamic_cast<TablePattern^>(_tableControl->GetCurrentPattern(TablePattern::Pattern));
12
- return tablePattern->Current.RowCount;
11
+ _finder = gcnew AutomationFinder(_control);
12
+ }
13
+
14
+ int AutomatedTable::GetHeaders(const char* headers[])
15
+ {
16
+ auto headerItems = _finder->Find(AutomationFinder::IsHeaderItem);
17
+
18
+ if( NULL != headers ) {
19
+ StringHelper::CopyNames(headerItems, headers);
20
+ }
21
+
22
+ return headerItems->Count;
23
+ }
24
+
25
+ int AutomatedTable::GetValues(const char* values[])
26
+ {
27
+ auto tableItems = _finder->Find(gcnew OrCondition(AutomationFinder::IsTableItem, AutomationFinder::IsListItem));
28
+
29
+ if( NULL != values ) {
30
+ StringHelper::CopyNames(tableItems, values);
31
+ }
32
+
33
+ return tableItems->Count;
13
34
  }
14
35
 
15
- bool AutomatedTable::Exists(const char* whichItem)
36
+ int AutomatedTable::RowCount::get()
16
37
  {
17
- return Exists(gcnew PropertyCondition(AutomationElement::NameProperty, gcnew String(whichItem)));
38
+ auto tablePattern = dynamic_cast<TablePattern^>(_control->GetCurrentPattern(TablePattern::Pattern));
39
+ return tablePattern->Current.RowCount;
18
40
  }
19
41
 
20
42
  bool AutomatedTable::Exists(const int whichItemIndex, const int whichColumnIndex)
@@ -29,22 +51,42 @@ String^ AutomatedTable::ValueAt(const int whichItemIndex, const int whichItemCol
29
51
 
30
52
  AutomationElement^ AutomatedTable::DataItemAt(const int whichItemIndex, const int whichItemColumn)
31
53
  {
32
- auto dataItemProperty = gcnew PropertyCondition(AutomationElement::IsTableItemPatternAvailableProperty, true);
33
54
  auto indexProperty = gcnew PropertyCondition(TableItemPattern::RowProperty, whichItemIndex);
34
55
  auto columnProperty = gcnew PropertyCondition(TableItemPattern::ColumnProperty, whichItemColumn);
35
- return _tableControl->FindFirst(System::Windows::Automation::TreeScope::Subtree, gcnew AndCondition(dataItemProperty, indexProperty, columnProperty));
56
+ return _finder->FindFirst(AutomationFinder::IsTableItem, indexProperty, columnProperty);
36
57
  }
37
58
 
38
59
  bool AutomatedTable::Exists(Condition^ condition)
39
60
  {
40
- auto dataItemProperty = gcnew PropertyCondition(AutomationElement::IsTableItemPatternAvailableProperty, true);
41
- return _tableControl->FindAll(System::Windows::Automation::TreeScope::Subtree, gcnew AndCondition(dataItemProperty, condition))->Count > 0;
61
+ return _finder->Find(AutomationFinder::IsTableItem, condition)->Count > 0;
42
62
  }
43
63
 
44
64
  void AutomatedTable::Select(const int dataItemIndex)
45
65
  {
46
- auto dataItemProperty = gcnew PropertyCondition(AutomationElement::ControlTypeProperty, ControlType::DataItem);
47
- auto dataItem = _tableControl->FindAll(System::Windows::Automation::TreeScope::Subtree, dataItemProperty)[dataItemIndex];
66
+ try {
67
+ Select(_finder->Find(AutomationFinder::IsDataItem)[dataItemIndex]);
68
+ } catch(IndexOutOfRangeException^ e) {
69
+ throw gcnew ArgumentException(String::Format("Table item at index {0} does not exist", dataItemIndex));
70
+ }
71
+ }
72
+
73
+ bool AutomatedTable::IsSelected(const int dataItemIndex) {
74
+
75
+ return AsSelectionItem(_finder->FindAt(dataItemIndex, AutomationFinder::IsSelectionItem))->Current.IsSelected;
76
+ }
77
+
78
+ void AutomatedTable::Select(const char* dataItemValue)
79
+ {
80
+ try {
81
+ auto nameCondition = gcnew PropertyCondition(AutomationElement::NameProperty, gcnew String(dataItemValue));
82
+ Select(_finder->Find(AutomationFinder::IsDataItem, nameCondition)[0]);
83
+ } catch(IndexOutOfRangeException^ e) {
84
+ throw gcnew ArgumentException(String::Format("Table item with the value \"{0}\" was not found", gcnew String(dataItemValue)));
85
+ }
86
+ }
87
+
88
+ void AutomatedTable::Select(AutomationElement^ dataItem)
89
+ {
48
90
  auto selectionItemPattern = dynamic_cast<SelectionItemPattern^>(dataItem->GetCurrentPattern(SelectionItemPattern::Pattern));
49
91
  selectionItemPattern->Select();
50
92
  }
@@ -1,22 +1,35 @@
1
1
  #pragma once
2
+ #include "AutomationControl.h"
3
+ #include "AutomationFinder.h"
4
+ #include "StringHelper.h"
5
+
2
6
  using namespace System::Windows::Automation;
3
7
 
4
- ref class AutomatedTable
8
+ ref class AutomatedTable : AutomationControl
5
9
  {
6
10
  public:
7
11
  AutomatedTable(const HWND windowHandle);
8
- bool Exists(const char* whichItem);
12
+ AutomatedTable(const FindInformation& finderInformation);
9
13
  bool Exists(const int whichItemIndex, const int whichColumnIndex);
10
14
  String^ ValueAt(const int whichItemIndex, const int whichColumnIndex);
11
15
  void Select(const int dataItemIndex);
16
+ void Select(const char* dataItemValue);
17
+ bool IsSelected(const int dataItemIndex);
18
+ int GetHeaders(const char* headers[]);
19
+ int GetValues(const char* values[]);
12
20
 
13
21
  property int RowCount {
14
22
  int get();
15
23
  }
16
24
 
17
25
  private:
18
- AutomationElement^ _tableControl;
26
+ AutomationFinder^ _finder;
19
27
  bool Exists(Condition^ condition);
20
28
  AutomationElement^ DataItemAt(const int whichItemIndex, const int whichItemRow);
29
+ void Select(AutomationElement^ dataItem);
30
+
31
+ SelectionItemPattern^ AsSelectionItem(AutomationElement^ automationElement) {
32
+ return dynamic_cast<SelectionItemPattern^>(automationElement->GetCurrentPattern(SelectionItemPattern::Pattern));
33
+ }
21
34
  };
22
35
 
@@ -0,0 +1,28 @@
1
+ #include "StdAfx.h"
2
+ #include "AutomationControl.h"
3
+ #include "AutomationFinder.h"
4
+
5
+ AutomationControl::AutomationControl(const HWND windowHandle)
6
+ {
7
+ _control = AutomationElement::FromHandle(IntPtr(windowHandle));
8
+ }
9
+
10
+ AutomationControl::AutomationControl(const FindInformation& findInformation)
11
+ {
12
+ try {
13
+ auto rootElement = AutomationElement::FromHandle(IntPtr(findInformation.rootWindow));
14
+ auto finder = gcnew AutomationFinder(rootElement);
15
+ _control = finder->Find(findInformation);
16
+ }
17
+ catch(Exception^ e) {
18
+ Debug::WriteLine("AutomationControl error: {0}", e->Message);
19
+ }
20
+ }
21
+
22
+ void AutomationControl::Value::set(String^ value) {
23
+ AsValuePattern->SetValue(value);
24
+ }
25
+
26
+ String^ AutomationControl::Value::get() {
27
+ return AsValuePattern->Current.Value;
28
+ }
@@ -0,0 +1,56 @@
1
+ #pragma once
2
+
3
+ using namespace System::Windows::Automation;
4
+ using namespace System::Windows;
5
+ using namespace System::Diagnostics;
6
+
7
+ ref class AutomationControl
8
+ {
9
+ public:
10
+ AutomationControl(const HWND windowHandle);
11
+ AutomationControl(const FindInformation& findInformation);
12
+
13
+ property AutomationElement^ Element {
14
+ AutomationElement^ get() { return _control; }
15
+ }
16
+
17
+ property String^ Name {
18
+ String^ get() { return _control->Current.Name; }
19
+ }
20
+
21
+ property String^ ClassName {
22
+ String^ get() { return _control->Current.ClassName; }
23
+ }
24
+
25
+ property Rect BoundingRectangle {
26
+ Rect get() { return _control->Current.BoundingRectangle; }
27
+ }
28
+
29
+ property System::Windows::Automation::ControlType^ ControlType {
30
+ System::Windows::Automation::ControlType^ get() { return _control->Current.ControlType; }
31
+ }
32
+
33
+ property int ProcessId {
34
+ int get() { return _control->Current.ProcessId; }
35
+ }
36
+
37
+ property String^ Value {
38
+ String^ get();
39
+ void set(String^ value);
40
+ }
41
+
42
+ property bool Exists {
43
+ bool get() { return nullptr != _control; }
44
+ }
45
+
46
+ protected:
47
+ AutomationElement^ _control;
48
+
49
+ private:
50
+ property ValuePattern^ AsValuePattern {
51
+ ValuePattern^ get() {
52
+ return dynamic_cast<ValuePattern^>(_control->GetCurrentPattern(ValuePattern::Pattern));
53
+ }
54
+ }
55
+ };
56
+