module RAutomation::Adapter::Win32::Functions
@private
Public Class Methods
activate_window(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 185 def activate_window(hwnd) set_foreground_window(hwnd) set_active_window(hwnd) bring_window_to_top(hwnd) within_foreground_thread(hwnd) do set_foreground_window(hwnd) set_active_window(hwnd) bring_window_to_top(hwnd) end end
Also aliased as: activate_control
child_window_locators(parent_hwnd, locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 145 def child_window_locators(parent_hwnd, locators) child_hwnd = locators[:hwnd] || child_hwnd(parent_hwnd, locators) if child_hwnd locators.merge!(:hwnd => child_hwnd) else popup_hwnd = get_window(parent_hwnd, Constants::GW_ENABLEDPOPUP) if popup_hwnd != parent_hwnd popup_properties = window_properties(popup_hwnd, locators) locators.merge!(:hwnd => popup_hwnd) if locators_match?(locators, popup_properties) end end locators end
close_window(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 173 def close_window(hwnd) _close_window(hwnd) closed = send_message_timeout(hwnd, Constants::WM_CLOSE, 0, nil, Constants::SMTO_ABORTIFHUNG, 1000, nil) # force it to close unless closed process_hwnd = open_process(Constants::PROCESS_ALL_ACCESS, false, window_pid(hwnd)) terminate_process(process_hwnd, 0) close_handle(process_hwnd) end end
control_click(control_hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 210 def control_click(control_hwnd) post_message(control_hwnd, Constants::BM_CLICK, 0, nil) end
control_hwnd(window_hwnd, locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 198 def control_hwnd(window_hwnd, locators) find_hwnd(locators, window_hwnd) do |hwnd| locators_match?(locators, control_properties(hwnd, locators)) end end
Also aliased as: child_hwnd
control_set?(control_hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 224 def control_set?(control_hwnd) get_button_state(control_hwnd) & Constants::STATE_SYSTEM_CHECKED != 0 end
control_value(control_hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 206 def control_value(control_hwnd) text_for(control_hwnd) end
get_cursor_pos()
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 114 def get_cursor_pos ptr = FFI::MemoryPointer.new(:long, 2) _get_cursor_pos(ptr) x, y = ptr.read_array_of_long(2) return {:x => x, :y => y} end
has_focus?(control_hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 228 def has_focus?(control_hwnd) get_button_state(control_hwnd) & Constants::STATE_SYSTEM_FOCUSED != 0 end
move_window(hwnd, x, y, width, height)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 110 def move_window(hwnd, x, y, width, height) _move_window(hwnd, x, y, width, height, true) end
retrieve_combobox_item_text(control_hwnd, item_no)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 236 def retrieve_combobox_item_text(control_hwnd, item_no) text_len = send_message(control_hwnd, Constants::CB_GETLBTEXTLEN, item_no, nil) string_buffer = FFI::MemoryPointer.new :char, text_len send_message(control_hwnd, Constants::CB_GETLBTEXT, item_no, string_buffer) string_buffer.read_string end
set_control_focus(control_hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 214 def set_control_focus(control_hwnd) within_foreground_thread control_hwnd do _set_control_focus(control_hwnd) end end
set_control_text(control_hwnd, text)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 220 def set_control_text(control_hwnd, text) send_message(control_hwnd, Constants::WM_SETTEXT, 0, text) end
window_class(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 165 def window_class(hwnd) class_name = FFI::MemoryPointer.new :char, 512 _window_class(hwnd, class_name, 512) class_name.read_string end
Also aliased as: control_class
window_hwnd(locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 139 def window_hwnd(locators) find_hwnd(locators) do |hwnd| window_visible(hwnd) && locators_match?(locators, window_properties(hwnd, locators)) end end
window_pid(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 159 def window_pid(hwnd) pid = FFI::MemoryPointer.new :int window_thread_process_id(hwnd, pid) pid.read_int end
window_rect(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 121 def window_rect(hwnd) x = FFI::MemoryPointer.new(:long, 4) _get_window_rect(hwnd, x) x.read_array_of_long(4) end
window_text(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 127 def window_text(hwnd) found_text = [] window_callback = FFI::Function.new(:bool, [:long, :pointer], {:convention => :stdcall}) do |child_hwnd, _| found_text << text_for(child_hwnd) true end enum_child_windows(hwnd, window_callback, nil) found_text.join(" ") end
Also aliased as: control_text
window_title(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 101 def window_title(hwnd) title_length = window_title_length(hwnd) + 1 title = FFI::MemoryPointer.new :char, title_length _window_title(hwnd, title, title_length) title.read_string end
Also aliased as: control_title
Private Class Methods
control_properties(hwnd, locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 259 def control_properties(hwnd, locators) element_properties(:control, hwnd, locators) end
element_properties(type, hwnd, locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 263 def element_properties(type, hwnd, locators) locators.inject({}) do |properties, locator| if locator[0] == :hwnd properties[locator[0]] = hwnd elsif locator[0] != :index properties[locator[0]] = self.send("#{type}_#{locator[0]}", hwnd) end properties end end
find_hwnd(locators, window_hwnd = nil) { |hwnd| ... }
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 281 def find_hwnd(locators, window_hwnd = nil) found_hwnd = nil found_index = -1 window_callback = FFI::Function.new(:bool, [:long, :pointer], {:convention => :stdcall}) do |hwnd, _| if yield(hwnd) found_index += 1 if locators[:index] found_hwnd = hwnd if locators[:index] == found_index else found_hwnd = hwnd end end !found_hwnd end unless window_hwnd enum_windows(window_callback, nil) else enum_child_windows(window_hwnd, window_callback, nil) end found_hwnd end
locators_match?(locators, properties)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 274 def locators_match?(locators, properties) locators.all? do |locator, value| locator == :index or value.is_a?(Regexp) ? properties[locator] =~ value : properties[locator] == value end end
text_for(hwnd)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 306 def text_for(hwnd) text_length = send_message(hwnd, Constants::WM_GETTEXTLENGTH, 0, nil) + 1 text = FFI::MemoryPointer.new :char, text_length send_message(hwnd, Constants::WM_GETTEXT, text_length, text) text.read_string end
window_properties(hwnd, locators)
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 255 def window_properties(hwnd, locators) element_properties(:window, hwnd, locators) end
within_foreground_thread(hwnd) { || ... }
click to toggle source
# File lib/rautomation/adapter/win_32/functions.rb, line 246 def within_foreground_thread(hwnd) foreground_thread = current_thread_id other_thread = window_thread_process_id(hwnd, nil) attach_thread_input(foreground_thread, other_thread, true) unless other_thread == foreground_thread yield ensure attach_thread_input(foreground_thread, other_thread, false) unless other_thread == foreground_thread end