Class: Win32::Screenshot::Util
- Inherits:
-
Object
- Object
- Win32::Screenshot::Util
- Defined in:
- lib/win32/util.rb
Class Method Summary collapse
- .all_desktop_windows ⇒ Object
- .dimensions_for(hwnd) ⇒ Object
- .get_info(hwnd) ⇒ Object
- .location_of(hwnd) ⇒ Object
- .window_class(hwnd) ⇒ Object
- .window_hwnd(title_query) ⇒ Object
- .window_process_id(hwnd) ⇒ Object
- .window_title(hwnd) ⇒ Object
-
.windows_hierarchy(with_info = false) ⇒ Object
just returns a long list of hwnd’s…
Class Method Details
.all_desktop_windows ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/win32/util.rb', line 6 def all_desktop_windows titles = [] window_callback = FFI::Function.new(:bool, [ :long, :pointer ], { :convention => :stdcall }) do |hwnd, param| titles << [window_title(hwnd), hwnd] true end BitmapMaker.enum_windows(window_callback, nil) titles end |
.dimensions_for(hwnd) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/win32/util.rb', line 79 def dimensions_for(hwnd) rect = [0, 0, 0, 0].pack('L4') BitmapMaker.client_rect(hwnd, rect) _, _, width, height = rect.unpack('L4') return width, height end |
.get_info(hwnd) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/win32/util.rb', line 45 def get_info hwnd {:title => window_title(hwnd), :class => window_class(hwnd), :dimensions => dimensions_for(hwnd), :starting_coordinates => location_of(hwnd) } end |
.location_of(hwnd) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/win32/util.rb', line 72 def location_of(hwnd) rect = [0, 0, 0, 0].pack('L4') BitmapMaker.window_rect(hwnd, rect) x, y, width, height = rect.unpack('L4') return x, y end |
.window_class(hwnd) ⇒ Object
60 61 62 63 64 |
# File 'lib/win32/util.rb', line 60 def window_class hwnd title = FFI::MemoryPointer.new :char, 100 BitmapMaker.class_name(hwnd, title, 99) title.read_string end |
.window_hwnd(title_query) ⇒ Object
66 67 68 69 70 |
# File 'lib/win32/util.rb', line 66 def window_hwnd(title_query) hwnd = BitmapMaker.hwnd(title_query) raise "window with title '#{title_query}' was not found!" unless hwnd hwnd end |
.window_process_id(hwnd) ⇒ Object
86 87 88 |
# File 'lib/win32/util.rb', line 86 def window_process_id(hwnd) BitmapMaker.get_process_id_from_hwnd(hwnd) end |
.window_title(hwnd) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/win32/util.rb', line 53 def window_title hwnd title_length = BitmapMaker.window_text_length(hwnd) + 1 title = FFI::MemoryPointer.new :char, title_length BitmapMaker.window_text(hwnd, title, title_length) title.read_string end |
.windows_hierarchy(with_info = false) ⇒ Object
just returns a long list of hwnd’s… unless with_info is true then it will return all hwnds with full info about each window
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/win32/util.rb', line 20 def windows_hierarchy with_info = false all = {} desktop_hwnd = BitmapMaker.desktop_window root = {:hwnd => desktop_hwnd, :children => []} root.merge!(get_info(desktop_hwnd)) if with_info parents = [] parents << root window_callback = FFI::Function.new(:bool, [ :long, :pointer ], { :convention => :stdcall }) do |hwnd, param| # this is a child of the most recent parent myself = {:hwnd => hwnd, :children => []} myself.merge!(get_info(hwnd)) if with_info parents[-1][:children] << myself parents << myself if !all[hwnd] all[hwnd] = true BitmapMaker.enum_child_windows(hwnd, window_callback, nil) end parents.pop true end BitmapMaker.enum_child_windows(desktop_hwnd, window_callback, nil) root end |