win-user32-ruby 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,3 +1,5 @@
1
- == WinUser32Ruby
1
+ = WinUser32Ruby
2
2
 
3
- win-user32-ruby is a Ruby wrapper for common user32.dll functions. It will provide the foundation for building a Ruby based automated GUI test suite. The goal is for the user of this library to not have to be a Win32 expert in order to script GUIs.
3
+ ==0.1.3
4
+ * Fix Window#get_window-rect to prevent it from out of range values when a window's position is negative
5
+ * Reorganized source to avoid namespace conflicts
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'spec/rake/spectask'
13
13
 
14
14
  spec = Gem::Specification.new do |s|
15
15
  s.name = 'win-user32-ruby'
16
- s.version = '0.1.1'
16
+ s.version = '0.1.3'
17
17
  s.has_rdoc = true
18
18
  s.extra_rdoc_files = ['README', 'LICENSE']
19
19
  s.summary = 'Ruby wrapper for the user32.dll on Windows.'
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Constants related to the Win32 API
5
5
 
6
- module WinAPISys
6
+ module WinUser32Ruby
7
7
  WM_MOVE = 0x0003
8
8
  WM_SIZE = 0x0005
9
9
  WM_ACTIVATE = 0x0006
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # System level function for wrapping the Win32API
5
5
 
6
- module WinAPISys
6
+ module WinUser32Ruby
7
7
  require 'win32/api'
8
8
  include Win32
9
9
  # IMPORTANT: Using Win32 requires some special considerations. Native C
@@ -20,7 +20,7 @@ module WinAPISys
20
20
  #
21
21
  # See rdoc for win32-api
22
22
 
23
- require 'system_const'
23
+ require 'user32/system_const'
24
24
  # Defines a bunch of constants from windows.h and winuser.h
25
25
 
26
26
  # Wrap the API call to functions in 'user32.dll' so we don't have to call
@@ -3,12 +3,10 @@
3
3
  #
4
4
  # Functions for simulating window interactions.
5
5
 
6
- require 'winapisys'
6
+ require 'user32/user32_system'
7
7
  require 'timeout'
8
8
 
9
9
  module WinUser32Ruby
10
- include WinAPISys
11
-
12
10
  class Window
13
11
  TIMEOUT = 10
14
12
  @handle = nil
@@ -18,9 +16,8 @@ module WinUser32Ruby
18
16
  @handle = hwnd
19
17
  end
20
18
 
21
- def text
19
+ # =Class Methods
22
20
 
23
- end
24
21
  # Wrapper for +FindWindow+.
25
22
  # +title+:: is the title of the window we are trying to find
26
23
  # +class_name+: is the predefined registered control-class name, generally not used
@@ -37,8 +34,22 @@ module WinUser32Ruby
37
34
  Window.new wnd
38
35
  end
39
36
 
37
+ # Wrapper for +GetForegroundWindow+.
38
+ # *Returns*:: WinUser32Ruby::Window
39
+ def self.get_foreground_window
40
+ b = user32 'GetForegroundWindow', 'V', 'L'
41
+
42
+ r = b.call
43
+
44
+ sleep 0.5
45
+ r = Window.new(r)
46
+ end
47
+
48
+ # =Instance Methods
49
+
40
50
  # Wrapper for +FindWindowEx+.
41
51
  # +title+:: is the title of the window we are trying to find
52
+ # +child+:: handle to _child_ from which to start the search
42
53
  # +class_name+: is the predefined registered control-class name, generally not used
43
54
  # *Return*:: window handle
44
55
  def find_window_ex(title, child = 0, class_name = nil)
@@ -56,8 +67,6 @@ module WinUser32Ruby
56
67
  end
57
68
 
58
69
  # Wrapper for +GetTopWindow+.
59
- # +title+:: is the title of the window we are trying to find
60
- # +class_name+: is the predefined registered control-class name, generally not used
61
70
  # *Return*:: window handle
62
71
  def get_top_window
63
72
  parent = @handle
@@ -68,22 +77,7 @@ module WinUser32Ruby
68
77
  Window.new wnd
69
78
  end
70
79
 
71
- # Wrapper for +GetTopWindow+.
72
- # +title+:: is the title of the window we are trying to find
73
- # +class_name+: is the predefined registered control-class name, generally not used
74
- # *Return*:: window handle
75
- def self.get_top_window
76
- parent = 0
77
- fw= user32 'GetTopWindow', 'L', 'L'
78
-
79
- wnd = timeout(TIMEOUT) {sleep 0.2 while (h = fw.call parent) <= 0; h}
80
-
81
- Window.new wnd
82
- end
83
-
84
80
  # Wrapper for +GetWindow+.
85
- # +hwnd+:: handle to window on which +cmd+ will be called
86
- # +cmd+: command to issue to +hwnd+
87
81
  # *Return*:: handle to window according to +cmd+
88
82
  def get_next_child
89
83
  hwnd, cmd = @handle, GW_CHILD
@@ -93,7 +87,6 @@ module WinUser32Ruby
93
87
  end
94
88
 
95
89
  # Wrapper for +WM_GETTEXT+.
96
- # +hwnd+:: handle to the window whose text we want
97
90
  # *Return*:: window text
98
91
  def get_window_text
99
92
  hwnd = @handle
@@ -106,7 +99,6 @@ module WinUser32Ruby
106
99
 
107
100
 
108
101
  # Wrapper for +GetWindowRect+.
109
- # +hwnd+:: handle the window whose rectangle we are trying to get
110
102
  # *Return*:: [left, top, right, bottom]
111
103
  def get_window_rect
112
104
  hwnd = @handle
@@ -118,14 +110,18 @@ module WinUser32Ruby
118
110
 
119
111
  left, top, right, bottom = rect.unpack("L*")
120
112
 
121
- [left, top, right, bottom]
113
+ [left, top, right, bottom].map{|e| [e].pack('L').unpack('l').first}
122
114
  end
123
115
 
116
+ # Gets the coordinates to the center of this window
117
+ # *Returns*:: <tt>[x, y]</tt>
124
118
  def get_center
125
119
  r = get_window_rect
126
120
  [(r[0] + r[2]) / 2, (r[1] + r[3]) / 2]
127
121
  end
128
122
 
123
+ # Centers cursor on this window
124
+ # *Returns*:: non-zero on success, zero otherwise
129
125
  def cursor_center
130
126
  set_cursor_pos(*get_center)
131
127
  end
@@ -136,7 +132,7 @@ module WinUser32Ruby
136
132
  end
137
133
 
138
134
  # Wrapper for +BringWindowToTop+.
139
- # +hwnd+:: handle to window
135
+ # *Returns*:: non-zero on success, zero otherwise
140
136
  def bring_window_to_top
141
137
  hwnd = @handle
142
138
  b = user32 'BringWindowToTop', 'L', 'I'
@@ -144,8 +140,7 @@ module WinUser32Ruby
144
140
  end
145
141
 
146
142
  # Wrapper for +SetFocus+.
147
- # +hwnd+:: handle to window
148
- # *Return*:: window handle
143
+ # *Returns*:: non-zero on success, zero otherwise
149
144
  def set_focus
150
145
  hwnd = @handle
151
146
  b = user32 'SetFocus', 'L', 'L'
@@ -153,8 +148,7 @@ module WinUser32Ruby
153
148
  end
154
149
 
155
150
  # Wrapper for +SetForegroundWindow+.
156
- # +hwnd+:: handle to window
157
- # *Return*:: true if successful
151
+ # *Returns*:: non-zero on success, zero otherwise
158
152
  def set_foreground_window
159
153
  hwnd = @handle
160
154
  b = user32 'SetForegroundWindow', 'L', 'I'
@@ -165,18 +159,8 @@ module WinUser32Ruby
165
159
  r
166
160
  end
167
161
 
168
- def self.get_foreground_window
169
- b = user32 'GetForegroundWindow', 'V', 'L'
170
-
171
- r = b.call
172
-
173
- sleep 0.5
174
- r
175
- end
176
-
177
162
  # Wrapper for +ShowWindow+.
178
- # +hwnd+:: handle to window
179
- # *Return*:: true if successful
163
+ # *Returns*:: non-zero on success, zero otherwise
180
164
  def show_window
181
165
  hwnd = @handle
182
166
  b = user32 'ShowWindow', 'LI', 'I'
@@ -184,7 +168,7 @@ module WinUser32Ruby
184
168
  end
185
169
 
186
170
  # Helper to Post Message to close window
187
- # +hwnd+:: handle to the window to close
171
+ # *Returns*:: non-zero on success, zero otherwise
188
172
  def exit!
189
173
  hwnd = @handle
190
174
  send_message hwnd, WM_CLOSE, 0, 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win-user32-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Fernholz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-04 00:00:00 -07:00
12
+ date: 2009-06-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,10 +35,10 @@ files:
35
35
  - LICENSE
36
36
  - README
37
37
  - Rakefile
38
- - lib/helpers.rb
39
- - lib/system_const.rb
38
+ - lib/user32
39
+ - lib/user32/system_const.rb
40
+ - lib/user32/user32_system.rb
40
41
  - lib/win-user32-ruby.rb
41
- - lib/winapisys.rb
42
42
  has_rdoc: true
43
43
  homepage:
44
44
  post_install_message:
@@ -1,12 +0,0 @@
1
- class Object
2
- protected
3
- def current_method
4
- "#{self.class}::#{caller[0][/`([^']*)'/, 1]}"
5
- end
6
- end
7
-
8
- class Numeric
9
- def to_hex
10
- sprintf("0x%x", self)
11
- end
12
- end