Class: Autogui::EnumerateDesktopWindows

Inherits:
Object
  • Object
show all
Includes:
Logging, Enumerable, Windows::Window
Defined in:
lib/win32/autogui/window.rb

Overview

Enumerate desktop child windows

Start at the desktop and work down through all the child windows

Constant Summary

Constants included from Logging

Logging::DEBUG, Logging::ERROR, Logging::FATAL, Logging::INFO, Logging::STANDARD_LOGGER, Logging::WARN

Constants included from Windows::Window

Windows::Window::SC_CLOSE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ EnumerateDesktopWindows

Returns a new instance of EnumerateDesktopWindows.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :timeout (Number) — default: 0

    maximum seconds to continue enumerating windows



24
25
26
# File 'lib/win32/autogui/window.rb', line 24

def initialize(options ={})
  @timeout = options[:timeout] || 0
end

Instance Attribute Details

#timeoutNumber

Returns timeout (0) in seconds.

Returns:

  • (Number)

    timeout (0) in seconds



21
22
23
# File 'lib/win32/autogui/window.rb', line 21

def timeout
  @timeout
end

Instance Method Details

#eachObject



48
49
50
51
52
53
# File 'lib/win32/autogui/window.rb', line 48

def each
  child_after = 0
  while (child_after = FindWindowEx(nil, child_after, nil, nil)) > 0 do
    yield Window.new child_after
  end
end

#find(ifnone = nil) ⇒ Object

redefine Enumerable’s find to continue looping until a timeout reached



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/win32/autogui/window.rb', line 29

def find(ifnone = nil)
  return to_enum :find, ifnone unless block_given?

  begin
    Timeout.timeout(timeout, FindTimeout) do
      begin
        each { |o| return o if yield(o) }
        sleep 0.2 unless (timeout == 0)
        #logger.debug "find looping" unless (timeout == 0)
      end until (timeout == 0)
    end
  rescue FindTimeout
    logger.warn "EnumerateDesktopWindows.find timeout"
    nil
  end

  ifnone.call if ifnone
end