module Uia::Library
Public Class Methods
attach_throwable_function(name_alias, name, arg_types, return_type, &block)
click to toggle source
# File lib/uia/library.rb, line 22 def self.attach_throwable_function(name_alias, name, arg_types, return_type, &block) attach_function name, arg_types + [:pointer, :int], return_type define_singleton_method(name_alias) do |*args| result = can_throw(name, *args) return block.call(result) if block result end end
can_throw(method, *args)
click to toggle source
# File lib/uia/library.rb, line 183 def self.can_throw(method, *args) try_catch {|s, n| send method, *(args << s << n) } end
control_type_condition(*control_types)
click to toggle source
# File lib/uia/library.rb, line 84 def self.control_type_condition(*control_types) control_type_ids = control_types.flatten.map(&:to_control_type_const) Condition_ControlType control_type_ids.count, *control_type_ids.to_var_args(:int) end
elements_from(name_alias, name, arg_types, &block)
click to toggle source
# File lib/uia/library.rb, line 31 def self.elements_from(name_alias, name, arg_types, &block) attach_function name, arg_types + [:pointer, :pointer, :int], :int define_singleton_method(name_alias) do |*args| elements_pointer = FFI::MemoryPointer.new :pointer can_throw(name, *(args << elements_pointer)).times.collect do |which_element| pointer = elements_pointer.read_pointer + which_element * ManagedElementStruct.size Uia::Element.new(ManagedElementStruct.new(pointer)) end end end
find_all(element, scope, *conditions)
click to toggle source
# File lib/uia/library.rb, line 192 def self.find_all(element, scope, *conditions) elements_pointer = FFI::MemoryPointer.new :pointer result = try_catch {|s, n| FindAll element, elements_pointer, scope, s, n, conditions.count, *conditions.to_var_args(:pointer) } result.times.collect do |which_element| pointer = elements_pointer.read_pointer + which_element * ManagedElementStruct.size Uia::Element.new(ManagedElementStruct.new(pointer)) end end
find_by_runtime_id(id)
click to toggle source
# File lib/uia/library.rb, line 167 def self.find_by_runtime_id(id) p = FFI::MemoryPointer.new :int, id.count p.write_array_of_int(id) result = can_throw(:Element_FindByRuntimeId, p, id.count) Uia::Element.new(result) unless result.empty? end
find_first(element, scope, *conditions)
click to toggle source
# File lib/uia/library.rb, line 187 def self.find_first(element, scope, *conditions) result = try_catch {|s, n| FindFirst element, scope, s, n, conditions.count, *conditions.to_var_args(:pointer) } Uia::Element.new(result) unless result.empty? end
get_text(element)
click to toggle source
# File lib/uia/library.rb, line 147 def self.get_text(element) length = can_throw(:Text_GetText, element, nil, 0) + 1 p = FFI::MemoryPointer.new :pointer, length can_throw(:Text_GetText, element, p, length) p.read_string end
pattern_condition(*patterns)
click to toggle source
# File lib/uia/library.rb, line 77 def self.pattern_condition(*patterns) try_catch do |s, n| pattern_strings = patterns.flatten.map(&:to_pattern_available_property) Condition_Pattern s, n, pattern_strings.count, *pattern_strings.to_var_args(:string) end end
try_catch(&block)
click to toggle source
# File lib/uia/library.rb, line 174 def self.try_catch(&block) buffer_size = 4096 string_buffer = FFI::MemoryPointer.new :char, buffer_size result = block.call(string_buffer, buffer_size) error_info = string_buffer.read_string raise error_info unless error_info.empty? result end
uia_directory()
click to toggle source
# File lib/uia/library.rb, line 9 def self.uia_directory File.dirname(__FILE__) + '/../../ext/UiaDll/Release' end