Class: Autogui::Window
- Inherits:
-
Object
- Object
- Autogui::Window
- Includes:
- Input, Logging, Windows::Window, Windows::Window::Classes, Windows::Window::Message
- Defined in:
- lib/win32/autogui/window.rb
Overview
Wrapper for window
Constant Summary
Constants included from Input
Input::KEYBD_EVENT_KEYDOWN, Input::KEYBD_EVENT_KEYUP, Input::KEYBD_KEYDELAY, Input::VK_0, Input::VK_1, Input::VK_2, Input::VK_3, Input::VK_4, Input::VK_5, Input::VK_6, Input::VK_7, Input::VK_8, Input::VK_9, Input::VK_A, Input::VK_ADD, Input::VK_APPS, Input::VK_B, Input::VK_BACK, Input::VK_C, Input::VK_CANCEL, Input::VK_CLEAR, Input::VK_CONTROL, Input::VK_D, Input::VK_DECIMAL, Input::VK_DELETE, Input::VK_DIVIDE, Input::VK_DOWN, Input::VK_E, Input::VK_END, Input::VK_ESCAPE, Input::VK_EXECUTE, Input::VK_F, Input::VK_F1, Input::VK_F10, Input::VK_F11, Input::VK_F12, Input::VK_F2, Input::VK_F3, Input::VK_F4, Input::VK_F5, Input::VK_F6, Input::VK_F7, Input::VK_F8, Input::VK_F9, Input::VK_G, Input::VK_H, Input::VK_HELP, Input::VK_HOME, Input::VK_I, Input::VK_INSERT, Input::VK_J, Input::VK_K, Input::VK_L, Input::VK_LBUTTON, Input::VK_LCONTROL, Input::VK_LEFT, Input::VK_LMENU, Input::VK_LSHIFT, Input::VK_LWIN, Input::VK_M, Input::VK_MENU, Input::VK_MULTIPLY, Input::VK_N, Input::VK_NEXT, Input::VK_NUMLOCK, Input::VK_NUMPAD0, Input::VK_NUMPAD1, Input::VK_NUMPAD2, Input::VK_NUMPAD3, Input::VK_NUMPAD4, Input::VK_NUMPAD5, Input::VK_NUMPAD6, Input::VK_NUMPAD7, Input::VK_NUMPAD8, Input::VK_NUMPAD9, Input::VK_O, Input::VK_OEM_1, Input::VK_OEM_2, Input::VK_OEM_3, Input::VK_OEM_4, Input::VK_OEM_5, Input::VK_OEM_6, Input::VK_OEM_7, Input::VK_OEM_8, Input::VK_OEM_COMMA, Input::VK_OEM_EQU, Input::VK_OEM_MINUS, Input::VK_OEM_PERIOD, Input::VK_OEM_PLUS, Input::VK_P, Input::VK_PAUSE, Input::VK_PRIOR, Input::VK_Q, Input::VK_R, Input::VK_RBUTTON, Input::VK_RCONTROL, Input::VK_RETURN, Input::VK_RIGHT, Input::VK_RMENU, Input::VK_RSHIFT, Input::VK_RWIN, Input::VK_S, Input::VK_SCROLL, Input::VK_SELECT, Input::VK_SEPARATOR, Input::VK_SHIFT, Input::VK_SNAPSHOT, Input::VK_SPACE, Input::VK_SUBTRACT, Input::VK_T, Input::VK_TAB, Input::VK_U, Input::VK_UP, Input::VK_V, Input::VK_W, Input::VK_X, Input::VK_Y, Input::VK_Z
Constants included from Logging
Logging::DEBUG, Logging::ERROR, Logging::FATAL, Logging::INFO, Logging::STANDARD_LOGGER, Logging::WARN
Constants included from Windows::Window
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
-
#children ⇒ Object
enumerable immeadiate child windows.
-
#close(options = {}) ⇒ Object
PostMessage SC_CLOSE and optionally wait for the window to close.
-
#combined_text ⇒ String
The window text including all child windows joined together with newlines.
-
#initialize(handle) ⇒ Window
constructor
A new instance of Window.
-
#inspect ⇒ String
Debugging information.
-
#is_window? ⇒ Boolean
Determines whether the specified window handle identifies an existing window.
-
#parent ⇒ Object
Window or nil.
-
#pid ⇒ Integer
The identifier (pid) of the process that created the window.
-
#set_focus ⇒ Number
Brings the window into the foreground and activates it.
-
#text(max_length = 2048) ⇒ String
(also: #title)
Window text (WM_GETTEXT).
-
#thread_id ⇒ Integer
The identifier of the thread that created the window.
-
#visible? ⇒ Boolean
Determines the visibility state of the window.
-
#wait_for_close(options = {}) ⇒ Object
Wait for the window to close.
-
#window_class ⇒ String
The Windows ClassName.
Methods included from Input
Methods included from Logging
Constructor Details
#initialize(handle) ⇒ Window
Returns a new instance of Window.
91 92 93 |
# File 'lib/win32/autogui/window.rb', line 91 def initialize(handle) @handle = handle end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
89 90 91 |
# File 'lib/win32/autogui/window.rb', line 89 def handle @handle end |
Instance Method Details
#children ⇒ Object
enumerable immeadiate child windows
99 100 101 |
# File 'lib/win32/autogui/window.rb', line 99 def children Children.new(self) end |
#close(options = {}) ⇒ Object
PostMessage SC_CLOSE and optionally wait for the window to close
116 117 118 119 |
# File 'lib/win32/autogui/window.rb', line 116 def close(={}) PostMessage(handle, WM_SYSCOMMAND, SC_CLOSE, 0) wait_for_close() if ([:wait_for_close] == true) end |
#combined_text ⇒ String
The window text including all child windows joined together with newlines. Faciliates matching text. Text from any given window is limited to 2048 characters
233 234 235 236 237 238 239 240 241 |
# File 'lib/win32/autogui/window.rb', line 233 def combined_text return unless is_window? t = [] t << text unless text == '' children.each do |w| t << w.combined_text unless w.combined_text == '' end t.join("\n") end |
#inspect ⇒ String
Debugging information
246 247 248 249 250 251 252 |
# File 'lib/win32/autogui/window.rb', line 246 def inspect c = [] children.each do |w| c << w.inspect end s = super + " #{self.class}=<window_class:#{window_class} pid:#{pid} thread_id:#{thread_id} title:\"#{title}\" children=<" + c.join("\n") + ">>" end |
#is_window? ⇒ Boolean
Determines whether the specified window handle identifies an existing window
161 162 163 |
# File 'lib/win32/autogui/window.rb', line 161 def is_window? (handle != 0) && (IsWindow(handle) != 0) end |
#parent ⇒ Object
Returns Window or nil.
105 106 107 108 |
# File 'lib/win32/autogui/window.rb', line 105 def parent h = GetParent(handle) Window.new h if h > 0 end |
#pid ⇒ Integer
The identifier (pid) of the process that created the window
205 206 207 208 209 210 |
# File 'lib/win32/autogui/window.rb', line 205 def pid return nil unless is_window? process_id = 0.chr * 4 GetWindowThreadProcessId(handle, process_id) process_id = process_id.unpack('L').first end |
#set_focus ⇒ Number
Brings the window into the foreground and activates it. Keyboard input is directed to the window, and various visual cues are changed for the user.
A process can set the foreground window only if one of the following conditions is true:
* The process is the foreground process.
* The process was started by the foreground process.
* The process received the last input event.
* There is no foreground process.
* The foreground process is being debugged.
* The foreground is not locked.
* The foreground lock time-out has expired.
* No menus are active.
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/win32/autogui/window.rb', line 190 def set_focus if is_window? # if current process was the last to receive input, we can be sure that # SetForegroundWindow will be allowed. Send the shift key to whatever has # the focus now. This allows IRB to set_focus. keystroke(VK_SHIFT) ret = SetForegroundWindow(handle) logger.warn("SetForegroundWindow failed") if ret == 0 end end |
#text(max_length = 2048) ⇒ String Also known as: title
Window text (WM_GETTEXT)
150 151 152 153 154 |
# File 'lib/win32/autogui/window.rb', line 150 def text(max_length = 2048) buffer = "\0" * max_length length = SendMessageA(handle, WM_GETTEXT, buffer.length, buffer) length == 0 ? '' : buffer[0..length - 1] end |
#thread_id ⇒ Integer
The identifier of the thread that created the window
216 217 218 219 |
# File 'lib/win32/autogui/window.rb', line 216 def thread_id return nil unless is_window? GetWindowThreadProcessId(handle, nil) end |
#visible? ⇒ Boolean
Determines the visibility state of the window
169 170 171 |
# File 'lib/win32/autogui/window.rb', line 169 def visible? is_window? && (IsWindowVisible(handle) != 0) end |
#wait_for_close(options = {}) ⇒ Object
Wait for the window to close
126 127 128 129 130 131 132 133 134 |
# File 'lib/win32/autogui/window.rb', line 126 def wait_for_close(={}) seconds = [:timeout] || 5 timeout(seconds) do begin yield if block_given? sleep 0.05 end until 0 == IsWindow(handle) end end |
#window_class ⇒ String
Returns the Windows ClassName.
138 139 140 141 142 |
# File 'lib/win32/autogui/window.rb', line 138 def window_class buffer = "\0" * 255 length = GetClassName(handle, buffer, buffer.length) length == 0 ? '' : buffer[0..length - 1] end |