jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

access to hwnd on all classes #116

Closed richbai90 closed 6 years ago

richbai90 commented 7 years ago

It would be nice if on any class you could have read only access to the hwnd property of that control. This became a priority for me when I needed to recursively loop through tabs on an application, that is the main window is a tabbed window but each tab may contain additional tabs. To keep track of tabs visited I wanted to push their unique identifier to an array like this:

def loop_tabs(visited=[])
    i = 0
    while( tab_control = @window.tab_control( :index => i ) ) && tab_control.exists?
        tab_control.items.each do |tab|
            if item.selected?
                visited.push(item.hwnd)
            end
            item.select unless visited.includes? item.hwnd
            loop_tabs visted
        end
    i += 1
    end
end

I tried to monkey patch the TabItem class like so

module RAutomation
  module Adapter
    module MsUia
      class TabControl
        class TabItem
          attr_reader :hwnd
        end
      end
    end
  end
end

But upon careful inspection I realized that the TabItem class doesn't even hold a @hwnd variable.

jarmo commented 6 years ago

Closing this due to inactivity.