win_gui 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +59 -1
- data/VERSION +1 -1
- data/lib/win_gui/constants.rb +63 -52
- data/lib/win_gui/def_api.rb +76 -25
- data/lib/win_gui/win_gui.rb +249 -105
- data/spec/spec_helper.rb +32 -25
- data/spec/win_gui/def_api_spec.rb +172 -121
- data/spec/win_gui/win_gui_spec.rb +9 -1
- data/win_gui.gemspec +2 -2
- metadata +2 -2
data/lib/win_gui/win_gui.rb
CHANGED
@@ -1,92 +1,138 @@
|
|
1
|
-
require 'Win32/api'
|
2
1
|
require 'string_extensions'
|
3
2
|
require 'constants'
|
4
3
|
require 'def_api'
|
5
4
|
require 'window'
|
6
5
|
|
7
|
-
|
6
|
+
#:stopdoc:
|
7
|
+
# TODO - When calling API functions, win_handle arg should default to instance var @handle of the host class
|
8
8
|
# TODO - Giving a hash of "named args" to def_api, like this:
|
9
9
|
# TODO def_api 'ShowWindow', 'LI' , 'I', :args=>{1=>:handle=>, 2=>[:cmd, :command]}
|
10
10
|
# TODO - Giving a hash of "defaults" to def_api, like this:
|
11
11
|
# TODO def_api 'ShowWindow', 'LI' , 'I', :defaults=>{1=>1234, 2=>'String2'}
|
12
12
|
# TODO - Option :class_method should define CLASS method instead of instance
|
13
|
+
#:startdoc:
|
13
14
|
|
14
15
|
module WinGui
|
15
|
-
|
16
|
+
extend DefApi
|
17
|
+
|
16
18
|
|
17
19
|
# Windows GUI API definitions:
|
18
20
|
|
21
|
+
##
|
19
22
|
# Tests whether the specified window handle identifies an existing window.
|
20
23
|
# A thread should not use IsWindow for a window that it did not create because the window
|
21
24
|
# could be destroyed after this function was called. Further, because window handles are
|
22
25
|
# recycled the handle could even point to a different window.
|
23
26
|
#
|
27
|
+
# :call-seq:
|
28
|
+
# window?( win_handle )
|
29
|
+
#
|
24
30
|
def_api 'IsWindow', 'L', 'L'
|
25
31
|
|
32
|
+
##
|
26
33
|
# Tests if the specified window, its parent window, its parent's parent window, and so forth,
|
27
34
|
# have the WS_VISIBLE style. Because the return value specifies whether the window has the
|
28
35
|
# WS_VISIBLE style, it may be true even if the window is totally obscured by other windows.
|
29
36
|
#
|
30
|
-
|
37
|
+
# :call-seq:
|
38
|
+
# visible?( win_handle ), window_visible?( win_handle )
|
39
|
+
#
|
40
|
+
def_api 'IsWindowVisible', 'L', 'L', aliases: :visible?
|
31
41
|
|
42
|
+
##
|
32
43
|
# Tests whether the specified window is maximized.
|
33
44
|
#
|
34
|
-
|
45
|
+
# :call-seq:
|
46
|
+
# zoomed?( win_handle ), maximized?( win_handle )
|
47
|
+
#
|
48
|
+
def_api 'IsZoomed', 'L', 'L', aliases: :maximized?
|
35
49
|
|
50
|
+
##
|
36
51
|
# Tests whether the specified window is maximized.
|
37
52
|
#
|
38
|
-
|
53
|
+
# :call-seq:
|
54
|
+
# iconic?( win_handle ), minimized?( win_handle )
|
55
|
+
#
|
56
|
+
def_api 'IsIconic', 'L', 'L', aliases: :minimized?
|
39
57
|
|
58
|
+
##
|
40
59
|
# Tests whether a window is a child (or descendant) window of a specified parent window.
|
41
60
|
# A child window is the direct descendant of a specified parent window if that parent window
|
42
61
|
# is in the chain of parent windows; the chain of parent windows leads from the original overlapped
|
43
62
|
# or pop-up window to the child window.
|
44
63
|
#
|
64
|
+
# :call-seq:
|
65
|
+
# child?( win_handle )
|
66
|
+
#
|
45
67
|
def_api 'IsChild', 'LL', 'L'
|
46
68
|
|
47
|
-
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
69
|
+
##
|
70
|
+
# Returns a handle to the top-level window whose class and window name match the specified strings.
|
71
|
+
# This function does not search child windows. This function does not perform a case-sensitive search.
|
72
|
+
#
|
73
|
+
# Parameters:
|
74
|
+
# class_name (P) - String that specifies (window) class name OR class atom created by a previous
|
75
|
+
# call to the RegisterClass(Ex) function. The atom must be in the low-order word of class_name;
|
76
|
+
# the high-order word must be zero. The class name can be any name registered with RegisterClass(Ex),
|
77
|
+
# or any of the predefined control-class names. If this parameter is nil, it finds any window whose
|
78
|
+
# title matches the win_title parameter.
|
79
|
+
# win_name (P) - String that specifies the window name (title). If nil, all names match.
|
80
|
+
# Return Value (L): found window handle or NIL if nothing found
|
81
|
+
|
82
|
+
# :call-seq:
|
83
|
+
# win_handle = find_window( class_name, win_name )
|
56
84
|
#
|
57
|
-
def_api 'FindWindow', 'PP', 'L', :
|
85
|
+
def_api 'FindWindow', 'PP', 'L', zeronil: true
|
58
86
|
|
87
|
+
##
|
59
88
|
# Unicode version of find_window (strings must be encoded as utf-16LE AND terminate with "\x00\x00")
|
60
89
|
#
|
61
|
-
|
90
|
+
# :call-seq:
|
91
|
+
# win_handle = find_window_w( class_name, win_name )
|
92
|
+
#
|
93
|
+
def_api 'FindWindowW', 'PP', 'L', zeronil: true
|
62
94
|
|
95
|
+
##
|
63
96
|
# Retrieves a handle to a CHILD window whose class name and window name match the specified strings.
|
64
97
|
# The function searches child windows, beginning with the one following the specified child window.
|
65
98
|
# This function does NOT perform a case-sensitive search.
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
#
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
99
|
+
#
|
100
|
+
# Parameters:
|
101
|
+
# parent (L) - Handle to the parent window whose child windows are to be searched.
|
102
|
+
# If nil, the function uses the desktop window as the parent window.
|
103
|
+
# The function searches among windows that are child windows of the desktop.
|
104
|
+
# after_child (L) - Handle to a child window. Search begins with the NEXT child window in the Z order.
|
105
|
+
# The child window must be a direct child window of parent, not just a descendant window.
|
106
|
+
# If after_child is nil, the search begins with the first child window of parent.
|
107
|
+
# win_class (P), win_title (P) - Strings that specify window class and name(title). If nil, anything matches.
|
108
|
+
# Returns (L): found child window handle or NIL if nothing found
|
109
|
+
#
|
110
|
+
#:call-seq:
|
111
|
+
# win_handle = find_window_ex( win_handle, after_child, class_name, win_name )
|
112
|
+
#
|
113
|
+
def_api 'FindWindowEx', 'LLPP', 'L', zeronil: true
|
114
|
+
|
115
|
+
##
|
116
|
+
# Returns the text of the specified window's title bar (if it has one).
|
117
|
+
# If the specified window is a control, the text of the control is copied. However, GetWindowText
|
118
|
+
# cannot retrieve the text of a control in another application.
|
119
|
+
#
|
120
|
+
# Original Parameters:
|
121
|
+
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
122
|
+
# text (P) - Long Pointer to the buffer that is to receive the text string.
|
123
|
+
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the text parameter.
|
124
|
+
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
125
|
+
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
126
|
+
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
127
|
+
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
128
|
+
#
|
129
|
+
# Enhanced API requires only win_handle and returns rstripped text
|
130
|
+
#
|
131
|
+
# Enhanced Parameters:
|
132
|
+
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
133
|
+
# Returns: Window title bar text or nil
|
87
134
|
# If the window has no title bar or text, if the title bar is empty, or if the window or control handle
|
88
|
-
# is invalid, the return value is
|
89
|
-
# To get extended error information, call GetLastError.
|
135
|
+
# is invalid, the return value is NIL. To get extended error information, call GetLastError.
|
90
136
|
#
|
91
137
|
# Remarks: This function CANNOT retrieve the text of an edit control in ANOTHER app.
|
92
138
|
# If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to
|
@@ -98,105 +144,180 @@ module WinGui
|
|
98
144
|
# To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead
|
99
145
|
# of calling GetWindowText.
|
100
146
|
#
|
147
|
+
#:call-seq:
|
148
|
+
# text = get_window_text( win_handle )
|
149
|
+
#
|
101
150
|
def_api 'GetWindowText', 'LPI', 'L', &return_string
|
102
151
|
|
152
|
+
##
|
103
153
|
# Unicode version of get_window_text (returns rstripped utf-8 string)
|
104
154
|
# API improved to require only win_handle and return rstripped string
|
105
155
|
#
|
156
|
+
#:call-seq:
|
157
|
+
# text = get_window_text_w( win_handle )
|
158
|
+
#
|
106
159
|
def_api 'GetWindowTextW', 'LPI', 'L', &return_string('utf-8')
|
107
160
|
|
161
|
+
##
|
108
162
|
# Retrieves the name of the class to which the specified window belongs.
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
163
|
+
#
|
164
|
+
# Original Parameters:
|
165
|
+
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
166
|
+
# class_name (P) - Long Pointer to the buffer that is to receive the class name string.
|
167
|
+
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the class_name parameter.
|
113
168
|
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
114
|
-
#
|
115
|
-
#
|
169
|
+
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
170
|
+
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
171
|
+
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
172
|
+
#
|
173
|
+
# API improved to require only win_handle and return rstripped string
|
174
|
+
#
|
175
|
+
# Enhanced Parameters:
|
176
|
+
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
177
|
+
# Returns: Name of the class or NIL if function fails. For extended error information, call GetLastError.
|
178
|
+
#
|
179
|
+
#:call-seq:
|
180
|
+
# text = get_class_name( win_handle )
|
116
181
|
#
|
117
182
|
def_api 'GetClassName', 'LPI', 'I', &return_string
|
118
183
|
|
184
|
+
##
|
119
185
|
# Unicode version of get_class_name (returns rstripped utf-8 string)
|
120
186
|
# API improved to require only win_handle and return rstripped string
|
121
187
|
#
|
188
|
+
#:call-seq:
|
189
|
+
# text = get_class_name_w( win_handle )
|
190
|
+
#
|
122
191
|
def_api 'GetClassNameW', 'LPI', 'I', &return_string('utf-8')
|
123
192
|
|
124
|
-
|
125
|
-
#
|
126
|
-
# API improved to accept window handle as a single arg and return a pair of [thread, process] ids
|
127
|
-
# handle (L) - Handle to the window.
|
128
|
-
# process (P) - A POINTER to a (Long) variable that receives the process identifier.
|
129
|
-
# Returns (L) - Identifier of the thread that created the window.
|
193
|
+
##
|
194
|
+
# Shows and hides windows.
|
130
195
|
#
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
196
|
+
# Parameters:
|
197
|
+
# win_handle (L) - Handle to the window.
|
198
|
+
# cmd (I) - Specifies how the window is to be shown. This parameter is ignored the first time an
|
199
|
+
# application calls ShowWindow, if the program that launched the application provides a STARTUPINFO
|
200
|
+
# structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained
|
201
|
+
# by the WinMain function in its nCmdShow parameter. In subsequent calls, cmd may be:
|
202
|
+
# SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE,
|
203
|
+
# SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL, SW_RESTORE, SW_SHOWDEFAULT, SW_FORCEMINIMIZE
|
204
|
+
#
|
205
|
+
# Original Return Value: - Nonzero if the window was PREVIOUSLY visible, otherwise zero
|
206
|
+
# Enhanced Returns: - True if the window was PREVIOUSLY visible, otherwise false
|
207
|
+
#
|
208
|
+
#:call-seq:
|
209
|
+
# was_visible = show_window( win_handle, cmd )
|
210
|
+
#
|
211
|
+
def_api 'ShowWindow', 'LI', 'I', boolean: true
|
136
212
|
|
137
|
-
#
|
138
|
-
|
139
|
-
#
|
140
|
-
|
141
|
-
#
|
142
|
-
#
|
143
|
-
|
144
|
-
#
|
145
|
-
|
146
|
-
#
|
147
|
-
|
148
|
-
#
|
149
|
-
|
150
|
-
#
|
151
|
-
|
152
|
-
#
|
153
|
-
|
154
|
-
#
|
155
|
-
|
156
|
-
#
|
157
|
-
|
158
|
-
#
|
159
|
-
|
160
|
-
#
|
161
|
-
#
|
162
|
-
|
163
|
-
#
|
164
|
-
#
|
165
|
-
|
166
|
-
#
|
167
|
-
|
213
|
+
# Hides the window and activates another window.
|
214
|
+
SW_HIDE = 0
|
215
|
+
# Same as SW_SHOWNORMAL
|
216
|
+
SW_NORMAL = 1
|
217
|
+
# Activates and displays a window. If the window is minimized or maximized, the system restores it to its
|
218
|
+
# original size and position. An application should specify this flag when displaying the window for the first time.
|
219
|
+
SW_SHOWNORMAL = 1
|
220
|
+
# Activates the window and displays it as a minimized window.
|
221
|
+
SW_SHOWMINIMIZED = 2
|
222
|
+
# Activates the window and displays it as a maximized window.
|
223
|
+
SW_SHOWMAXIMIZED = 3
|
224
|
+
# Maximizes the specified window.
|
225
|
+
SW_MAXIMIZE = 3
|
226
|
+
# Displays a window in its most recent size and position. Similar to SW_SHOWNORMAL, but the window is not activated.
|
227
|
+
SW_SHOWNOACTIVATE = 4
|
228
|
+
# Activates the window and displays it in its current size and position.
|
229
|
+
SW_SHOW = 5
|
230
|
+
# Minimizes the specified window, activates the next top-level window in the Z order.
|
231
|
+
SW_MINIMIZE = 6
|
232
|
+
# Displays the window as a minimized window. Similar to SW_SHOWMINIMIZED, except the window is not activated.
|
233
|
+
SW_SHOWMINNOACTIVE= 7
|
234
|
+
# Displays the window in its current size and position. Similar to SW_SHOW, except the window is not activated.
|
235
|
+
SW_SHOWNA = 8
|
236
|
+
# Activates and displays the window. If the window is minimized or maximized, the system restores it to its original
|
237
|
+
# size and position. An application should specify this flag when restoring a minimized window.
|
238
|
+
SW_RESTORE = 9
|
239
|
+
# Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess
|
240
|
+
# function by the program that started the application.
|
241
|
+
SW_SHOWDEFAULT = 10
|
242
|
+
# Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. Only use this
|
243
|
+
# flag when minimizing windows from a different thread.
|
244
|
+
SW_FORCEMINIMIZE = 11
|
168
245
|
|
169
246
|
def hide_window(handle)
|
170
247
|
show_window(handle, SW_HIDE)
|
171
248
|
end
|
172
249
|
|
173
|
-
|
174
|
-
#
|
250
|
+
##
|
251
|
+
# Retrieves the identifier of the thread that created the specified window
|
252
|
+
# and, optionally, the identifier of the process that created the window.
|
253
|
+
#
|
254
|
+
# Original Parameters:
|
255
|
+
# handle (L) - Handle to the window.
|
256
|
+
# process (P) - A POINTER to a (Long) variable that receives the process identifier.
|
257
|
+
# Original Return (L): Identifier of the thread that created the window.
|
258
|
+
#
|
259
|
+
# API improved to accept window handle as a single arg and return a pair of [thread, process] ids
|
260
|
+
#
|
261
|
+
# New Parameters:
|
262
|
+
# handle (L) - Handle to the window.
|
263
|
+
# Returns: Pair of identifiers of the thread and process_id that created the window.
|
264
|
+
#
|
265
|
+
#:call-seq:
|
266
|
+
# thread, process_id = get_window_tread_process_id( win_handle )
|
267
|
+
#
|
268
|
+
def_api 'GetWindowThreadProcessId', 'LP', 'L' do |api, *args|
|
269
|
+
raise 'Invalid args count' unless args.size == api.prototype.size-1
|
270
|
+
thread = api.call(args.first, process = [1].pack('L'))
|
271
|
+
[thread, *process.unpack('L')]
|
272
|
+
end
|
273
|
+
|
274
|
+
##
|
275
|
+
# Retrieves the dimensions of the specified window bounding rectangle.
|
276
|
+
# Dimensions are given relative to the upper-left corner of the screen.
|
277
|
+
#
|
278
|
+
# Original Parameters:
|
279
|
+
# win_handle (L) - Handle to the window.
|
280
|
+
# rect (P) - Long pointer to a RECT structure that receives the screen coordinates of the upper-left and
|
281
|
+
# lower-right corners of the window.
|
282
|
+
# Original Return Value: Nonzero indicates success. Zero indicates failure. For error info, call GetLastError.
|
283
|
+
#
|
175
284
|
# API improved to accept only window handle and return 4-member dimensions array (left, top, right, bottom)
|
176
|
-
#
|
285
|
+
#
|
286
|
+
# New Parameters:
|
287
|
+
# win_handle (L) - Handle to the window
|
288
|
+
# New Return: Array(left, top, right, bottom) - rectangle dimensions
|
177
289
|
#
|
178
290
|
# Remarks: As a convention for the RECT structure, the bottom-right coordinates of the returned rectangle
|
179
291
|
# are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.
|
180
292
|
#
|
293
|
+
#:call-seq:
|
294
|
+
# rect = get_window_rect( win_handle )
|
295
|
+
#
|
181
296
|
def_api 'GetWindowRect', 'LP', 'I' do |api, *args|
|
182
297
|
raise 'Invalid args count' unless args.size == api.prototype.size-1
|
183
298
|
rectangle = [0, 0, 0, 0].pack 'L*'
|
184
299
|
api.call args.first, rectangle
|
185
|
-
rectangle.unpack '
|
300
|
+
rectangle.unpack 'L*'
|
186
301
|
end
|
187
302
|
|
188
|
-
|
189
|
-
def_api 'PostMessage', 'LLLL', 'L'
|
190
|
-
def_api 'SendMessage', 'LLLP', 'L'
|
191
|
-
def_api 'GetDlgItem', 'LL', 'L'
|
192
|
-
|
303
|
+
##
|
193
304
|
# The EnumWindows function enumerates all top-level windows on the screen by passing the handle to
|
194
305
|
# each window, in turn, to an application-defined callback function. EnumWindows continues until
|
195
306
|
# the last top-level window is enumerated or the callback function returns FALSE.
|
307
|
+
#
|
308
|
+
# Original Parameters:
|
309
|
+
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
310
|
+
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
311
|
+
# Original Return: Nonzero if the function succeeds, zero if the function fails. GetLastError for error info.
|
312
|
+
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
313
|
+
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
314
|
+
#
|
196
315
|
# API improved to accept blocks (instead of callback objects) and message as a single arg
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
316
|
+
#
|
317
|
+
# New Parameters:
|
318
|
+
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
319
|
+
# block given to method invocation serves as an application-defined callback function (see EnumWindowsProc).
|
320
|
+
# Returns: True if the function succeeds, false if the function fails. GetLastError for error info.
|
200
321
|
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
201
322
|
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
202
323
|
#
|
@@ -205,23 +326,46 @@ module WinGui
|
|
205
326
|
# the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being
|
206
327
|
# caught in an infinite loop or referencing a handle to a window that has been destroyed.
|
207
328
|
#
|
208
|
-
|
329
|
+
#:call-seq:
|
330
|
+
# status = enum_windows( message ) {|win_handle, message| callback procedure }
|
331
|
+
#
|
332
|
+
def_api'EnumWindows', 'KP', 'L', boolean: true, &return_enum
|
209
333
|
|
334
|
+
##
|
210
335
|
# Enumerates child windows to a given window.
|
211
|
-
#
|
336
|
+
#
|
337
|
+
# Original Parameters:
|
338
|
+
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
339
|
+
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
340
|
+
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
341
|
+
# Original Return: Not used (?!)
|
342
|
+
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
343
|
+
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
212
344
|
# If it is nil, this function is equivalent to EnumWindows. Windows 95/98/Me: parent cannot be NULL.
|
345
|
+
#
|
213
346
|
# API improved to accept blocks (instead of callback objects) and two args: parent handle and message.
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
347
|
+
# New Parameters:
|
348
|
+
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
349
|
+
# message (P) - Specifies an application-defined value(message) to be passed to the callback function.
|
350
|
+
# block given to method invocation serves as an application-defined callback function (see EnumChildProc).
|
351
|
+
#
|
352
|
+
# Remarks:
|
217
353
|
# If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.
|
218
354
|
# A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated.
|
219
355
|
# The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process.
|
356
|
+
#
|
357
|
+
#:call-seq:
|
358
|
+
# enum_windows( parent_handle, message ) {|win_handle, message| callback procedure }
|
220
359
|
def_api 'EnumChildWindows', 'LKP', 'L', &return_enum
|
221
360
|
|
222
361
|
def_api 'GetForegroundWindow', 'V', 'L'
|
223
362
|
def_api 'GetActiveWindow', 'V', 'L'
|
224
363
|
|
364
|
+
def_api 'keybd_event', 'IILL', 'V'
|
365
|
+
def_api 'PostMessage', 'LLLL', 'L'
|
366
|
+
def_api 'SendMessage', 'LLLP', 'L'
|
367
|
+
def_api 'GetDlgItem', 'LL', 'L'
|
368
|
+
|
225
369
|
|
226
370
|
# Convenience wrapper methods:
|
227
371
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
lib_dir = File.join(File.dirname(__FILE__),".."
|
1
|
+
lib_dir = File.join(File.dirname(__FILE__), "..", "lib" )
|
2
2
|
$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir)
|
3
3
|
require 'spec'
|
4
4
|
require 'win_gui'
|
5
5
|
require 'note'
|
6
|
-
|
6
|
+
|
7
7
|
# Customize RSpec with my own extensions
|
8
8
|
module SpecMacros
|
9
9
|
|
@@ -15,9 +15,9 @@ module SpecMacros
|
|
15
15
|
|
16
16
|
# reads description line from source file and drops external brackets (like its{}, use{}
|
17
17
|
def description_from(file, line)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
File.open(file) do |f|
|
19
|
+
f.lines.to_a[line-1].gsub( /(spec.*?{)|(use.*?{)|}/, '' ).strip
|
20
|
+
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -45,8 +45,9 @@ module GuiTest
|
|
45
45
|
def use
|
46
46
|
lambda {yield}.should_not raise_error
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def any_handle
|
50
|
+
WinGui.def_api 'FindWindow', 'PP', 'L' unless respond_to? :find_window
|
50
51
|
find_window(nil, nil)
|
51
52
|
end
|
52
53
|
|
@@ -57,48 +58,54 @@ module GuiTest
|
|
57
58
|
def any_block
|
58
59
|
lambda {|*args| args}
|
59
60
|
end
|
60
|
-
|
61
|
-
def hide_method(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
|
62
|
+
def hide_method(*names) # hide original method(s) if it is defined
|
63
|
+
names.each do |name|
|
64
|
+
WinGui.module_eval do
|
65
|
+
if method_defined? name.to_sym
|
66
|
+
alias_method "orig_#{name.to_s}".to_sym, name.to_sym
|
67
|
+
remove_method name.to_sym
|
68
|
+
end
|
66
69
|
end
|
67
70
|
end
|
68
71
|
end
|
69
|
-
|
70
|
-
def restore_method(
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
|
73
|
+
def restore_method(*names) # restore original method if it was hidden
|
74
|
+
names.each do |name|
|
75
|
+
WinGui.module_eval do
|
76
|
+
temp = "orig_#{name.to_s}".to_sym
|
77
|
+
if method_defined? temp
|
78
|
+
alias_method name.to_sym, temp
|
79
|
+
remove_method temp
|
80
|
+
end
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
79
|
-
|
84
|
+
|
80
85
|
def launch_test_app
|
81
86
|
system TEST_APP_START
|
82
87
|
sleep TEST_SLEEP_DELAY until (handle = find_window(nil, TEST_WIN_TITLE))
|
83
88
|
@launched_test_app = Window.new handle
|
84
89
|
end
|
85
|
-
|
90
|
+
|
86
91
|
def close_test_app(app = @launched_test_app)
|
87
92
|
while app and app.respond_to? :handle and find_window(nil, TEST_WIN_TITLE)
|
88
93
|
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, 0)
|
89
94
|
sleep TEST_SLEEP_DELAY
|
90
|
-
end
|
95
|
+
end
|
91
96
|
@launched_test_app = nil
|
92
97
|
end
|
93
|
-
|
98
|
+
|
94
99
|
# Creates test app object and yields it back to the block
|
95
100
|
def test_app
|
96
101
|
app = launch_test_app
|
102
|
+
|
97
103
|
def app.textarea #define singleton method retrieving app's text area
|
98
104
|
Window.new find_window_ex(self.handle, 0, TEST_TEXTAREA_CLASS, nil)
|
99
105
|
end
|
106
|
+
|
100
107
|
yield app
|
101
|
-
close_test_app
|
108
|
+
close_test_app
|
102
109
|
end
|
103
|
-
|
110
|
+
|
104
111
|
end
|