Module: SleipnirAPI::FFI::User32
Overview
:nodoc:
Constant Summary collapse
- GW_HWNDFIRST =
0- GW_HWNDLAST =
1- GW_HWNDNEXT =
2- GW_HWNDPREV =
3
Class Method Summary collapse
- .each_child_window(hwnd) ⇒ Object
- .find_child_window_by_classname(root_hwnd, classname) ⇒ Object
- .get_class_name(hwnd) ⇒ Object
- .get_first_child(hwnd) ⇒ Object
- .get_first_sibling(hwnd) ⇒ Object
- .get_last_sibling(hwnd) ⇒ Object
- .get_next_sibling(hwnd) ⇒ Object
- .get_prev_sibling(hwnd) ⇒ Object
- .get_top_window(hwnd) ⇒ Object
- .get_window(hwnd, cmd) ⇒ Object
- .get_window_process_id(hwnd) ⇒ Object
- .get_window_rect(hwnd) ⇒ Object
- .get_window_thread_id(hwnd) ⇒ Object
- .get_window_thread_process_id(hwnd) ⇒ Object
- .list_window(hwnd) ⇒ Object
- .with_window_dc(hwnd) ⇒ Object
Methods included from Base
Class Method Details
.each_child_window(hwnd) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 105 def each_child_window(hwnd) child = get_first_child(hwnd) if child yield child while child = get_next_sibling(child) yield child end end end |
.find_child_window_by_classname(root_hwnd, classname) ⇒ Object
123 124 125 126 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 123 def find_child_window_by_classname(root_hwnd, classname) w = list_window(root_hwnd).flatten w.find{|e| get_class_name(e) == classname} end |
.get_class_name(hwnd) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 29 def get_class_name(hwnd) buf = "\0" * 255 r = GetClassName(hwnd, buf, buf.length) raise Win32APIError, "GetClassName failed" if r.nil? or r.zero? buf[0...r] end |
.get_first_child(hwnd) ⇒ Object
85 86 87 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 85 def get_first_child(hwnd) get_top_window(hwnd) end |
.get_first_sibling(hwnd) ⇒ Object
89 90 91 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 89 def get_first_sibling(hwnd) get_window(hwnd, GW_HWNDFIRST) end |
.get_last_sibling(hwnd) ⇒ Object
93 94 95 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 93 def get_last_sibling(hwnd) get_window(hwnd, GW_HWNDLAST) end |
.get_next_sibling(hwnd) ⇒ Object
97 98 99 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 97 def get_next_sibling(hwnd) get_window(hwnd, GW_HWNDNEXT) end |
.get_prev_sibling(hwnd) ⇒ Object
101 102 103 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 101 def get_prev_sibling(hwnd) get_window(hwnd, GW_HWNDPREV) end |
.get_top_window(hwnd) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 67 def get_top_window(hwnd) r = GetTopWindow(hwnd) if r.nil? or r.zero? nil else r end end |
.get_window(hwnd, cmd) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 76 def get_window(hwnd, cmd) r = GetWindow(hwnd, cmd) if r.nil? or r.zero? nil else r end end |
.get_window_process_id(hwnd) ⇒ Object
46 47 48 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 46 def get_window_process_id(hwnd) get_window_thread_process_id(hwnd)[1] end |
.get_window_rect(hwnd) ⇒ Object
60 61 62 63 64 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 60 def get_window_rect(hwnd) buf = [0, 0, 0, 0].pack("L4") GetWindowRect(hwnd, buf) buf.unpack("L4") end |
.get_window_thread_id(hwnd) ⇒ Object
42 43 44 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 42 def get_window_thread_id(hwnd) get_window_thread_process_id(hwnd)[0] end |
.get_window_thread_process_id(hwnd) ⇒ Object
36 37 38 39 40 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 36 def get_window_thread_process_id(hwnd) n = [0].pack("L") th = GetWindowThreadProcessId(hwnd, n) return [th, n.unpack("L")[0]] end |
.list_window(hwnd) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 115 def list_window(hwnd) r = [hwnd] each_child_window(hwnd) {|child| r << list_window(child) } r end |
.with_window_dc(hwnd) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/sleipnir_api/ffi/user32.rb', line 50 def with_window_dc(hwnd) hdc = GetWindowDC(hwnd) raise Win32APIError, "GetDC failed" if hdc.nil? or hdc.zero? begin yield hdc ensure ReleaseDC(hwnd, hdc) end end |