lib/rautomation/adapter/ffi/functions.rb in rautomation-0.2.1 vs lib/rautomation/adapter/ffi/functions.rb in rautomation-0.3.0

- old
+ new

@@ -53,10 +53,12 @@ [:uchar, :uchar, :int, :pointer], :void attach_function :control_id, :GetDlgCtrlID, [:long], :int attach_function :_set_control_focus, :SetFocus, [:long], :long + attach_function :get_window, :GetWindow, + [:long, :uint], :long # kernel32 attach_function :open_process, :OpenProcess, [:int, :bool, :int], :long attach_function :terminate_process, :TerminateProcess, @@ -70,27 +72,45 @@ title = FFI::MemoryPointer.new :char, title_length _window_title(hwnd, title, title_length) title.read_string end + alias_method :control_title, :window_title + 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 end + alias_method :control_text, :window_text + def window_hwnd(locators) find_hwnd(locators) do |hwnd| window_visible(hwnd) && !window_text(hwnd).empty? && locators_match?(locators, window_properties(hwnd, locators)) end end + 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 + def window_pid(hwnd) pid = FFI::MemoryPointer.new :int window_thread_process_id(hwnd, pid) pid.read_int end @@ -129,9 +149,11 @@ def control_hwnd(window_hwnd, locators) find_hwnd(locators, window_hwnd) do |hwnd| locators_match?(locators, control_properties(hwnd, locators)) end end + + alias_method :child_hwnd, :control_hwnd def control_value(control_hwnd) text_for(control_hwnd) end \ No newline at end of file