win 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -19
- data/VERSION +1 -1
- data/lib/win/dde.rb +147 -88
- data/lib/win/gui/dialog.rb +35 -1
- data/lib/win/gui/input.rb +128 -93
- data/lib/win/gui/message.rb +365 -5
- data/lib/win/gui/{convenience.rb → window/window.rb} +12 -67
- data/lib/win/gui/window.rb +338 -219
- data/lib/win/gui.rb +1 -2
- data/lib/win/library.rb +0 -2
- data/spec/spec_helper.rb +4 -4
- data/spec/win/gui/dialog_spec.rb +22 -7
- data/spec/win/gui/input_spec.rb +30 -0
- data/spec/win/gui/message_spec.rb +0 -7
- data/spec/win/gui/{convenience_spec.rb → window/window_spec.rb} +13 -61
- data/spec/win/gui/window_spec.rb +30 -4
- data/spec/win/library_spec.rb +0 -27
- data/win.gemspec +5 -5
- metadata +5 -5
data/lib/win/gui/window.rb
CHANGED
@@ -55,7 +55,7 @@ module Win
|
|
55
55
|
handles = []
|
56
56
|
|
57
57
|
# Insert callback proc into appropriate place of args Array
|
58
|
-
args[api.prototype.find_index(:
|
58
|
+
args[api.prototype.find_index(:EnumWindowsProc), 0] =
|
59
59
|
proc do |handle, message|
|
60
60
|
handles << handle
|
61
61
|
block ? block[handle, message] : true
|
@@ -90,41 +90,74 @@ module Win
|
|
90
90
|
# Windows GUI API definitions:
|
91
91
|
|
92
92
|
##
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
93
|
+
# The IsWindow function determines whether the specified window handle identifies an existing window.
|
94
|
+
# [*Syntax*] BOOL IsWindow( HWND hWnd );
|
95
|
+
#
|
96
|
+
# hWnd:: [in] Handle to the window to test.
|
97
|
+
#
|
98
|
+
# *Returns*:: If the window handle identifies an existing window, the return value is (*true*).
|
99
|
+
# If the window handle does not identify an existing window, the return value is (*false*).
|
100
|
+
# ---
|
101
|
+
# *remarks*:
|
102
|
+
# A thread should not use IsWindow for a window that it did not create because the window
|
103
|
+
# could be destroyed after this function was called. Further, because window handles are
|
104
|
+
# recycled the handle could even point to a different window.
|
97
105
|
#
|
98
106
|
# :call-seq:
|
99
107
|
# window?( win_handle )
|
100
108
|
#
|
101
|
-
function
|
109
|
+
function :IsWindow, [:ulong], :int, boolean: true
|
102
110
|
|
103
111
|
##
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
112
|
+
# The IsWindowVisible function retrieves the visibility state of the specified window.
|
113
|
+
# [*Syntax*] BOOL IsWindowVisible( HWND hWnd );
|
114
|
+
#
|
115
|
+
# hWnd:: [in] Handle to the window to test.
|
116
|
+
#
|
117
|
+
# *Returns*:: If the specified window, its parent window, its parent's parent window, and so forth,
|
118
|
+
# have the WS_VISIBLE style set, return value is *true*. Because the return value specifies
|
119
|
+
# whether the window has the WS_VISIBLE style, it may be true even if the window is totally
|
120
|
+
# obscured by other windows.
|
121
|
+
# ---
|
122
|
+
# *Remarks*:
|
123
|
+
# - The visibility state of a window is indicated by the WS_VISIBLE style bit. When WS_VISIBLE is set,
|
124
|
+
# the window is displayed and subsequent drawing into it is displayed as long as the window has the
|
125
|
+
# WS_VISIBLE style.
|
126
|
+
# - Any drawing to a window with the WS_VISIBLE style will not be displayed if the window is obscured
|
127
|
+
# by other windows or is clipped by its parent window.
|
107
128
|
#
|
108
129
|
# :call-seq:
|
109
130
|
# [window_]visible?( win_handle )
|
110
131
|
#
|
111
|
-
function
|
132
|
+
function :IsWindowVisible, [:ulong], :int, boolean: true, aliases: :visible?
|
112
133
|
|
113
134
|
##
|
114
135
|
# Tests whether the specified window is maximized.
|
136
|
+
# [*Syntax*] BOOL IsZoomed( HWND hWnd );
|
137
|
+
#
|
138
|
+
# hWnd:: [in] Handle to the window to test.
|
139
|
+
#
|
140
|
+
# *Returns*:: If the window is zoomed (maximized), the return value is *true*.
|
141
|
+
# If the window is not zoomed (maximized), the return value is *false*.
|
115
142
|
#
|
116
143
|
# :call-seq:
|
117
144
|
# zoomed?( win_handle ), maximized?( win_handle )
|
118
145
|
#
|
119
|
-
function
|
146
|
+
function :IsZoomed, [:ulong], :int, boolean: true, aliases: :maximized?
|
120
147
|
|
121
148
|
##
|
122
|
-
# Tests whether the specified window is
|
149
|
+
# Tests whether the specified window is minimized.
|
150
|
+
# [*Syntax*] BOOL IsIconic( HWND hWnd );
|
151
|
+
#
|
152
|
+
# hWnd:: [in] Handle to the window to test.
|
153
|
+
#
|
154
|
+
# *Returns*:: If the window is iconic (minimized), the return value is *true*.
|
155
|
+
# If the window is not iconic (minimized), the return value is *false*.
|
123
156
|
#
|
124
157
|
# :call-seq:
|
125
158
|
# iconic?( win_handle ), minimized?( win_handle )
|
126
159
|
#
|
127
|
-
function
|
160
|
+
function :IsIconic, [:ulong], :int, boolean: true, aliases: :minimized?
|
128
161
|
|
129
162
|
##
|
130
163
|
# Tests whether a window is a child (or descendant) window of a specified parent window.
|
@@ -132,174 +165,233 @@ module Win
|
|
132
165
|
# is in the chain of parent windows; the chain of parent windows leads from the original overlapped
|
133
166
|
# or pop-up window to the child window.
|
134
167
|
#
|
168
|
+
# [*Syntax*] BOOL IsChild( HWND hWndParent, HWND hWnd);
|
169
|
+
#
|
170
|
+
# hWndParent:: [in] Handle to the parent window.
|
171
|
+
# hWnd:: [in] Handle to the window to be tested.
|
172
|
+
#
|
173
|
+
# *Returns*:: If the window is a child or descendant window of the specified parent window,
|
174
|
+
# the return value is *true*. If the window is not a child or descendant window of
|
175
|
+
# the specified parent window, the return value is *false*.
|
135
176
|
# :call-seq:
|
136
177
|
# child?( win_handle )
|
137
178
|
#
|
138
|
-
function
|
179
|
+
function :IsChild, [:ulong, :ulong], :int, boolean: true
|
139
180
|
|
140
181
|
##
|
141
|
-
#
|
142
|
-
# This function does not search child windows. This function does not
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
182
|
+
# The FindWindow function retrieves a handle to the top-level window whose class name and window name
|
183
|
+
# match the specified strings. This function does not search child windows. This function does not
|
184
|
+
# perform a case-sensitive search.
|
185
|
+
#
|
186
|
+
# To search child windows, beginning with a specified child window, use the FindWindowEx function.
|
187
|
+
#
|
188
|
+
# [*Syntax*] HWND FindWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName );
|
189
|
+
#
|
190
|
+
# lpClassName:: [in] Pointer to a null-terminated string that specifies the class name or a class
|
191
|
+
# atom created by a previous call to the RegisterClass or RegisterClassEx function.
|
192
|
+
# The atom must be in the low-order word of lpClassName; the high-order word must be zero.
|
193
|
+
# If lpClassName points to a string, it specifies the window class name. The class name
|
194
|
+
# can be any name registered with RegisterClass or RegisterClassEx, or any of the
|
195
|
+
# predefined control-class names.
|
196
|
+
# If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.
|
197
|
+
# lpWindowName:: [in] Pointer to a null-terminated string that specifies the window name (the window's title).
|
198
|
+
# If this parameter is NULL, all window names match.
|
199
|
+
# *Returns*:: If the function succeeds, the return value is a handle to the window that has the specified
|
200
|
+
# class name and window name. If the function fails, the return value is *nil*.
|
201
|
+
# To get extended error information, call GetLastError.
|
202
|
+
# ---
|
203
|
+
# *Remarks*:
|
204
|
+
# - If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve
|
205
|
+
# the window name for comparison. For a description of a potential problem that can arise, see the
|
206
|
+
# Remarks for GetWindowText.
|
207
|
+
# - To check if the Microsoft IntelliType version 1.x software is running, call FindWindow as follows:
|
208
|
+
# find_window("MSITPro::EventQueue", nil)
|
209
|
+
# - To check if the IntelliType version 2.0 software is running, call FindWindow as follows:
|
210
|
+
# find_window("Type32_Main_Window", nil)
|
211
|
+
# If the IntelliType software is running, it sends WM_APPCOMMAND messages to the application.
|
212
|
+
# Otherwise the application must install a hook to receive WM_APPCOMMAND messages.
|
152
213
|
#
|
153
214
|
# :call-seq:
|
154
215
|
# win_handle = find_window( class_name, win_name )
|
155
216
|
#
|
156
|
-
function
|
217
|
+
function :FindWindow, [:pointer, :pointer], :ulong, zeronil: true
|
157
218
|
|
158
219
|
##
|
159
|
-
# Unicode version of
|
220
|
+
# Unicode version of FindWindow (strings must be encoded as utf-16LE AND terminate with "\x00\x00")
|
160
221
|
#
|
161
222
|
# :call-seq:
|
162
223
|
# win_handle = find_window_w( class_name, win_name )
|
163
224
|
#
|
164
|
-
function
|
225
|
+
function :FindWindowW, [:pointer, :pointer], :ulong, zeronil: true
|
165
226
|
|
166
227
|
##
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
228
|
+
# The FindWindowEx function retrieves a handle to a window whose class name and window name match the specified
|
229
|
+
# strings. The function searches child windows, beginning with the one following the specified child window.
|
230
|
+
# This function does not perform a case-sensitive search.
|
231
|
+
#
|
232
|
+
# [*Syntax*] HWND FindWindowEx( HWND hwndParent, HWND hwndChildAfter, LPCTSTR lpszClass, LPCTSTR lpszWindow );
|
233
|
+
#
|
234
|
+
# hwndParent:: [in] Handle to the parent window whose child windows are to be searched.
|
235
|
+
# If hwndParent is NULL, the function uses the desktop window as the parent window.
|
236
|
+
# The function searches among windows that are child windows of the desktop.
|
237
|
+
# Microsoft Windows 2000 and Windows XP: If hwndParent is HWND_MESSAGE, the function
|
238
|
+
# searches all message-only windows.
|
239
|
+
# hwndChildAfter:: [in] Handle to a child window. The search begins with the next child window in the Z order.
|
240
|
+
# The child window must be a direct child window of hwndParent, not just a descendant window.
|
241
|
+
# If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
|
242
|
+
# Note that if both hwndParent and hwndChildAfter are NULL, the function searches all
|
243
|
+
# top-level and message-only windows.
|
244
|
+
# lpszClass:: [in] Pointer to a null-terminated string that specifies the class name or a class atom created
|
245
|
+
# by a previous call to the RegisterClass or RegisterClassEx function. The atom must be placed in
|
246
|
+
# the low-order word of lpszClass; the high-order word must be zero.
|
247
|
+
# If lpszClass is a string, it specifies the window class name. The class name can be any name
|
248
|
+
# registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names,
|
249
|
+
# or it can be MAKEINTATOM(0x800). In this latter case, 0x8000 is the atom for a menu class. For
|
250
|
+
# more information, see the Remarks section of this topic.
|
251
|
+
# lpszWindow:: [in] Pointer to a null-terminated string that specifies the window name (the window's title).
|
252
|
+
# If this parameter is NULL, all window names match.
|
253
|
+
#
|
254
|
+
# *Returns*:: If the function succeeds, the return value is a handle to the window that has the specified
|
255
|
+
# class and window names. If the function fails, the return value is NULL. For extended error info,
|
256
|
+
# call GetLastError.
|
257
|
+
# ---
|
258
|
+
# *Remarks*:
|
259
|
+
# - If the lpszWindow parameter is not NULL, FindWindowEx calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks section of GetWindowText.
|
260
|
+
# - An application can call this function in the following way.
|
261
|
+
# find_window_ex( nil, nil, MAKEINTATOM(0x8000), nil )
|
262
|
+
# 0x8000 is the atom for a menu class. When an application calls this function, the function checks whether
|
263
|
+
# a context menu is being displayed that the application created.
|
180
264
|
#
|
181
265
|
# :call-seq:
|
182
266
|
# win_handle = find_window_ex( win_handle, after_child, class_name, win_name )
|
183
267
|
#
|
184
|
-
function
|
268
|
+
function :FindWindowEx, [:ulong, :ulong, :pointer, :pointer], :ulong, zeronil: true
|
185
269
|
|
186
270
|
##
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
271
|
+
# GetWindowText returns the text of the specified window's title bar (if it has one).
|
272
|
+
# If the specified window is a control, the text of the control is copied. However, GetWindowText
|
273
|
+
# cannot retrieve the text of a control in another application.
|
274
|
+
#
|
275
|
+
# [*Syntax*] int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount );
|
276
|
+
#
|
277
|
+
# *Original* Parameters:
|
278
|
+
# hWnd:: Handle to the window and, indirectly, the class to which the window belongs.
|
279
|
+
# lpString:: Long Pointer to the buffer that is to receive the text string.
|
280
|
+
# nMaxCount:: Specifies the length, in TCHAR, of the buffer pointed to by the text parameter.
|
281
|
+
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
282
|
+
# *Original* Return:: Length, in characters, of the copied string, not including the terminating null
|
283
|
+
# character (if success). Zero indicates that the window has no title bar or text,
|
284
|
+
# if the title bar is empty, or if the window or control handle is invalid.
|
285
|
+
# For extended error information, call GetLastError.
|
286
|
+
# ---
|
200
287
|
# Enhanced API requires only win_handle and returns rstripped text
|
201
288
|
#
|
202
|
-
# Enhanced Parameters:
|
203
|
-
#
|
204
|
-
# Returns
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
# Remarks
|
209
|
-
#
|
289
|
+
# *Enhanced* Parameters:
|
290
|
+
# win_handle:: Handle to the window and, indirectly, the class to which the window belongs.
|
291
|
+
# *Returns*:: Window title bar text or nil. If the window has no title bar or text, if the title bar
|
292
|
+
# is empty, or if the window or control handle is invalid, the return value is *NIL*.
|
293
|
+
# To get extended error information, call GetLastError.
|
294
|
+
# ---
|
295
|
+
# *Remarks*: This function CANNOT retrieve the text of an edit control in ANOTHER app.
|
296
|
+
# - If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to
|
210
297
|
# be sent to the specified window or control. If the target window is owned by another process and has
|
211
298
|
# a caption, GetWindowText retrieves the window caption text. If the window does not have a caption,
|
212
299
|
# the return value is a null string. This allows to call GetWindowText without becoming unresponsive
|
213
300
|
# if the target window owner process is not responding. However, if the unresponsive target window
|
214
301
|
# belongs to the calling app, GetWindowText will cause the calling app to become unresponsive.
|
215
|
-
#
|
302
|
+
# - To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead
|
216
303
|
# of calling GetWindowText.
|
217
304
|
#
|
218
305
|
#:call-seq:
|
219
306
|
# text = [get_]window_text( win_handle )
|
220
307
|
#
|
221
|
-
function
|
308
|
+
function :GetWindowText, [:ulong, :pointer, :int], :int, &return_string
|
222
309
|
|
223
310
|
##
|
224
|
-
# Unicode version of
|
311
|
+
# GetWindowTextW is a Unicode version of GetWindowText (returns rstripped utf-8 string)
|
225
312
|
# API improved to require only win_handle and return rstripped string
|
226
313
|
#
|
227
314
|
#:call-seq:
|
228
315
|
# text = [get_]window_text_w( win_handle )
|
229
316
|
#
|
230
|
-
function
|
317
|
+
function :GetWindowTextW, [:ulong, :pointer, :int], :int, &return_string('utf-8')
|
231
318
|
|
232
319
|
##
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# Original Parameters:
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
# Original Return
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
320
|
+
# GetClassName retrieves the name of the class to which the specified window belongs.
|
321
|
+
# [*Syntax*] int GetClassName( HWND hWnd, LPTSTR lpClassName, int nMaxCount );
|
322
|
+
# *Original* Parameters:
|
323
|
+
# hWnd:: [in] Handle to the window and, indirectly, the class to which the window belongs.
|
324
|
+
# lpClassName:: [out] Pointer to the buffer that is to receive the class name string.
|
325
|
+
# nMaxCount:: [in] Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter.
|
326
|
+
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
327
|
+
# *Original* Return:: Length, in characters, of the copied string, not including the terminating null character,
|
328
|
+
# indicates success. Zero indicates that the window has no title bar or text, if the title
|
329
|
+
# bar is empty, or if the window or control handle is invalid.
|
330
|
+
# ---
|
244
331
|
# API improved to require only win_handle and return rstripped string
|
245
332
|
#
|
246
|
-
# Enhanced Parameters:
|
247
|
-
#
|
248
|
-
# Returns
|
333
|
+
# *Enhanced* Parameters:
|
334
|
+
# win_handle:: Handle to the window and, indirectly, the class to which the window belongs.
|
335
|
+
# *Returns*:: Name of the class or *nil* if function fails. For extended error information, call GetLastError.
|
249
336
|
#
|
250
337
|
#:call-seq:
|
251
338
|
# text = [get_]class_name( win_handle )
|
252
339
|
#
|
253
|
-
function
|
340
|
+
function :GetClassName, [:ulong, :pointer, :int], :int, &return_string
|
254
341
|
|
255
342
|
##
|
256
|
-
# Unicode version of
|
343
|
+
# GetClassNameW is a Unicode version of GetClassName (returns rstripped utf-8 string)
|
257
344
|
# API improved to require only win_handle and return rstripped string
|
258
345
|
#
|
259
346
|
#:call-seq:
|
260
347
|
# text = [get_]class_name_w( win_handle )
|
261
348
|
#
|
262
|
-
function
|
349
|
+
function :GetClassNameW, [:ulong, :pointer, :int], :int, &return_string('utf-8')
|
263
350
|
|
264
351
|
##
|
265
|
-
#
|
352
|
+
# ShowWindow shows and hides windows (sets the specified window's show state).
|
353
|
+
#
|
354
|
+
# [*Syntax*] BOOL ShowWindow( HWND hWnd, int nCmdShow);
|
266
355
|
#
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
356
|
+
# hWnd:: Handle to the window.
|
357
|
+
# nCmdShow:: Specifies how the window is to be shown. This parameter is ignored the first time an
|
358
|
+
# application calls ShowWindow, if the program that launched the application provides a
|
359
|
+
# STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should
|
360
|
+
# be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent
|
361
|
+
# calls, cmd may be:
|
362
|
+
# SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE,
|
363
|
+
# SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL, SW_RESTORE, SW_SHOWDEFAULT, SW_FORCEMINIMIZE
|
275
364
|
#
|
276
|
-
#
|
277
|
-
# Enhanced Returns: - True if the window was PREVIOUSLY visible, otherwise false
|
365
|
+
# *Returns*:: *True* if the window was PREVIOUSLY visible, otherwise *false*
|
278
366
|
#
|
279
367
|
#:call-seq:
|
280
368
|
# was_visible = show_window( win_handle, cmd )
|
281
369
|
#
|
282
|
-
function
|
370
|
+
function :ShowWindow, [:ulong, :int], :int, boolean: true
|
283
371
|
|
284
372
|
##
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
373
|
+
# GetWindowThreadProcessId retrieves the identifier of the thread that created the specified window
|
374
|
+
# and, optionally, the identifier of the process that created the window.
|
375
|
+
#
|
376
|
+
# [*Syntax*] DWORD GetWindowThreadProcessId( HWND hWnd, LPDWORD lpdwProcessId );
|
377
|
+
#
|
378
|
+
# *Original* Parameters:
|
379
|
+
# hWnd:: [in] Handle to the window.
|
380
|
+
# lpdwProcessId:: [out] Pointer to a variable that receives the process identifier. If this parameter
|
381
|
+
# is not NULL, GetWindowThreadProcessId copies the identifier of the process to the
|
382
|
+
# variable; otherwise, it does not.
|
383
|
+
# *Original* Return:: The identifier of the thread that created the window.
|
384
|
+
# ---
|
293
385
|
# API improved to accept window handle as a single arg and return a pair of [thread, process] ids
|
294
386
|
#
|
295
|
-
# New Parameters:
|
296
|
-
#
|
297
|
-
# Returns
|
387
|
+
# *New* Parameters:
|
388
|
+
# handle:: Handle to the window.
|
389
|
+
# *Returns*: Pair of identifiers of the thread and process_id that created the window.
|
298
390
|
#
|
299
391
|
#:call-seq:
|
300
392
|
# thread, process_id = [get_]window_tread_process_id( win_handle )
|
301
393
|
#
|
302
|
-
function
|
394
|
+
function :GetWindowThreadProcessId, [:ulong, :pointer], :long,
|
303
395
|
&->(api, *args) {
|
304
396
|
namespace.enforce_count( args, api.prototype, -1)
|
305
397
|
process = FFI::MemoryPointer.new(:long)
|
@@ -310,178 +402,190 @@ module Win
|
|
310
402
|
# goes crazy if block is attached to meta-definition
|
311
403
|
|
312
404
|
##
|
313
|
-
#
|
314
|
-
#
|
405
|
+
# GetWindowRect retrieves the dimensions of the specified window bounding rectangle.
|
406
|
+
# Dimensions are given relative to the upper-left corner of the screen.
|
315
407
|
#
|
316
|
-
#
|
317
|
-
# win_handle (L) - Handle to the window.
|
318
|
-
# rect (P) - Long pointer to a RECT structure that receives the screen coordinates of the upper-left and
|
319
|
-
# lower-right corners of the window.
|
320
|
-
# Original Return Value: Nonzero indicates success. Zero indicates failure. For error info, call GetLastError.
|
408
|
+
# [*Syntax*] BOOL GetWindowRect( HWND hWnd, LPRECT lpRect );
|
321
409
|
#
|
410
|
+
# *Original* Parameters:
|
411
|
+
# hWnd:: [in] Handle to the window.
|
412
|
+
# lpRect:: [out] Pointer to a structure that receives the screen coordinates of the upper-left and
|
413
|
+
# lower-right corners of the window.
|
414
|
+
# *Original* Return:: Nonzero indicates success. Zero indicates failure. For error info, call GetLastError.
|
415
|
+
# ---
|
322
416
|
# API improved to accept only window handle and return 4-member dimensions array (left, top, right, bottom)
|
323
417
|
#
|
324
|
-
# New Parameters:
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
# Remarks
|
329
|
-
#
|
418
|
+
# *New* Parameters:
|
419
|
+
# win_handle:: Handle to the window
|
420
|
+
# *Returns*:: Array(left, top, right, bottom) - rectangle dimensions
|
421
|
+
# ---
|
422
|
+
# *Remarks*: As a convention for the RECT structure, the bottom-right coordinates of the returned rectangle
|
423
|
+
# are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.
|
330
424
|
#
|
331
425
|
#:call-seq:
|
332
426
|
# rect = [get_]window_rect( win_handle )
|
333
427
|
#
|
334
|
-
function
|
428
|
+
function :GetWindowRect, [:ulong, :pointer], :int,
|
335
429
|
&->(api, *args) {
|
336
430
|
namespace.enforce_count( args, api.prototype, -1)
|
337
431
|
rect = FFI::MemoryPointer.new(:long, 4)
|
338
432
|
rect.write_array_of_long([0, 0, 0, 0])
|
339
433
|
res = api.call args.first, rect
|
340
|
-
res == 0 ? [nil, nil, nil, nil] :
|
434
|
+
res == 0 ? [nil, nil, nil, nil] : rect.read_array_of_long(4) }
|
341
435
|
# weird lambda literal instead of normal block is needed because current version of RDoc
|
342
436
|
# goes crazy if block is attached to meta-definition
|
343
437
|
|
344
|
-
|
345
|
-
#
|
438
|
+
##
|
439
|
+
# EnumWindowsProc is an application-defined callback function that receives top-level window handles
|
440
|
+
# as a result of a call to the EnumWindows, EnumChildWindows or EnumDesktopWindows function.
|
346
441
|
#
|
347
|
-
# Syntax
|
442
|
+
# [*Syntax*] BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam );
|
348
443
|
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
444
|
+
# hWnd:: [in] Handle to a top-level window.
|
445
|
+
# lParam:: [in] Specifies the application-defined value given in EnumWindows or EnumDesktopWindows.
|
446
|
+
# *Return* *Value*:: To continue enumeration, the callback function must return TRUE;
|
447
|
+
# to stop enumeration, it must return FALSE.
|
448
|
+
# ---
|
449
|
+
# Remarks:
|
450
|
+
# - An application must register this callback function by passing its address to EnumWindows,
|
451
|
+
# EnumChildWindows or EnumDesktopWindows.
|
452
|
+
# - You must ensure that the callback function sets SetLastError if it fails.
|
453
|
+
#
|
454
|
+
# :call-seq:
|
455
|
+
# EnumWindowsProc callback block: {|win_handle, value| your callback code }
|
354
456
|
#
|
355
|
-
|
356
|
-
# EnumChildWindows or EnumDesktopWindows.
|
357
|
-
callback :enum_callback, 'LL', :bool
|
457
|
+
callback :EnumWindowsProc, [:ulong, :long], :bool
|
358
458
|
|
359
459
|
##
|
360
460
|
# The EnumWindows function enumerates all top-level windows on the screen by passing the handle to
|
361
461
|
# each window, in turn, to an application-defined callback function. EnumWindows continues until
|
362
462
|
# the last top-level window is enumerated or the callback function returns FALSE.
|
363
463
|
#
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
375
|
-
#
|
376
|
-
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
#
|
383
|
-
#
|
464
|
+
# [*Syntax*] BOOL EnumWindows( WNDENUMPROC lpEnumFunc, LPARAM lParam );
|
465
|
+
#
|
466
|
+
# *Original* Parameters:
|
467
|
+
# lpEnumFunc:: [in] Pointer to an application-defined callback function of EnumWindowsProc type.
|
468
|
+
# lParam:: [in] Specifies an application-defined value(message) to be passed to the callback function.
|
469
|
+
# *Original* Return:: Nonzero if the function succeeds, zero if the function fails. GetLastError for error info.
|
470
|
+
# If callback returns zero, the return value is also zero. In this case, the callback
|
471
|
+
# function should call SetLastError to obtain a meaningful error code to be returned to
|
472
|
+
# the caller of EnumWindows.
|
473
|
+
# ---
|
474
|
+
# API improved to accept blocks (instead of callback objects) with message as an optional argument
|
475
|
+
#
|
476
|
+
# *New* Parameters:
|
477
|
+
# message:: Specifies an application-defined value(message) to be passed to the callback block.
|
478
|
+
# attached block:: Serves as an application-defined callback function (see EnumWindowsProc).
|
479
|
+
# *Returns*:: *True* if the function succeeds, *false* if the function fails. GetLastError for error info.
|
480
|
+
# If callback returned zero/false, the return value is also false. In this case, the callback
|
481
|
+
# function should call SetLastError to obtain a meaningful error code to be returned to the
|
482
|
+
# caller of EnumWindows.
|
483
|
+
# ---
|
484
|
+
# *Remarks*: The EnumWindows function does not enumerate child windows, with the exception of a few top-level
|
485
|
+
# windows owned by the system that have the WS_CHILD style. This function is more reliable than calling
|
486
|
+
# the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being
|
487
|
+
# caught in an infinite loop or referencing a handle to a window that has been destroyed.
|
384
488
|
#
|
385
489
|
# :call-seq:
|
386
490
|
# handles = enum_windows( [value=0] ) {|handle, value| your callback procedure }
|
387
491
|
#
|
388
|
-
function
|
492
|
+
function :EnumWindows, [:EnumWindowsProc, :long], :bool, &return_enum
|
389
493
|
|
390
494
|
##
|
391
|
-
#EnumDesktopWindows Function
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
395
|
-
#
|
396
|
-
#
|
397
|
-
#
|
398
|
-
#
|
399
|
-
#
|
400
|
-
#
|
401
|
-
#
|
402
|
-
#
|
403
|
-
#
|
404
|
-
#
|
405
|
-
#
|
406
|
-
#
|
407
|
-
#
|
408
|
-
#
|
409
|
-
#
|
410
|
-
#A
|
411
|
-
#
|
412
|
-
#
|
413
|
-
#
|
414
|
-
#
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
419
|
-
#
|
420
|
-
#
|
421
|
-
#
|
422
|
-
#Windows Server 2003 and Windows XP/2000: If there are no windows on the desktop, GetLastError returns ERROR_INVALID_HANDLE.
|
423
|
-
#Remarks
|
424
|
-
#The EnumDesktopWindows function repeatedly invokes the lpfn callback function until the last top-level window is enumerated or the callback function returns FALSE.
|
425
|
-
#
|
426
|
-
#Requirements
|
427
|
-
#Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
495
|
+
# EnumDesktopWindows Function enumerates all top-level windows associated with the specified desktop.
|
496
|
+
# It passes the handle to each window, in turn, to an application-defined callback function.
|
497
|
+
#
|
498
|
+
# [*Syntax*] BOOL WINAPI EnumDesktopWindows( __in_opt HDESK hDesktop, __in WNDENUMPROC lpfn, __in LPARAM lParam);
|
499
|
+
#
|
500
|
+
# *Original* Parameters:
|
501
|
+
# hDesktop:: A handle to the desktop whose top-level windows are to be enumerated. This handle is returned by
|
502
|
+
# the CreateDesktop, GetThreadDesktop, OpenDesktop, or OpenInputDesktop function, and must have the
|
503
|
+
# DESKTOP_ENUMERATE access right. For more information, see Desktop Security and Access Rights.
|
504
|
+
# If this parameter is NULL, the current desktop is used.
|
505
|
+
# lpfn:: A pointer to an application-defined EnumWindowsProc callback.
|
506
|
+
# lParam:: An application-defined value to be passed to the callback.
|
507
|
+
# *Return*:: If the function fails or is unable to perform the enumeration, the return value is zero.
|
508
|
+
# To get extended error information, call GetLastError. You must ensure that the callback function
|
509
|
+
# sets SetLastError if it fails.
|
510
|
+
# ---
|
511
|
+
# API enhanced to return *true*/*false* instead of nonzero/zero, and message value is optional (defaults to 0).
|
512
|
+
#
|
513
|
+
# *Enhanced*12 34 Parameters:
|
514
|
+
# desktop:: A handle to the desktop whose top-level windows are to be enumerated.
|
515
|
+
# value:: Specifies an application-defined value(message) to be passed to the callback (default 0).
|
516
|
+
# attached block:: Serves as an application-defined callback function (see EnumWindowsProc).
|
517
|
+
# ---
|
518
|
+
# *Remarks*:
|
519
|
+
# - Windows Server 2003 and Windows XP/2000: If there are no windows on the desktop, GetLastError returns
|
520
|
+
# ERROR_INVALID_HANDLE.
|
521
|
+
# - The EnumDesktopWindows function repeatedly invokes the callback function until the last top-level window
|
522
|
+
# is enumerated or the callback function returns FALSE.
|
523
|
+
# ---
|
524
|
+
# *Requirements*:
|
525
|
+
# Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
428
526
|
#
|
429
527
|
# :call-seq:
|
430
528
|
# handles = enum_desktop_windows( desktop_handle, [value=0] ) {|handle, value| your callback procedure }
|
431
529
|
#
|
432
|
-
function
|
530
|
+
function :EnumDesktopWindows, [:ulong, :EnumWindowsProc, :long], :bool, &return_enum
|
433
531
|
|
434
532
|
##
|
435
|
-
#
|
533
|
+
# The EnumChildWindows function enumerates the child windows that belong to the specified parent window by
|
534
|
+
# passing the handle of each child window, in turn, to an application-defined callback. EnumChildWindows
|
535
|
+
# continues until the last child window is enumerated or the callback function returns FALSE.
|
536
|
+
#
|
537
|
+
# [*Syntax*] BOOL EnumChildWindows( HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM lParam );
|
436
538
|
#
|
437
|
-
# Original Parameters:
|
438
|
-
#
|
439
|
-
#
|
440
|
-
#
|
441
|
-
#
|
442
|
-
#
|
443
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
444
|
-
# If it is nil, this function is equivalent to EnumWindows. Windows 95/98/Me: parent cannot be NULL.
|
539
|
+
# *Original* Parameters:
|
540
|
+
# hWndParent:: [in] Handle to the parent window whose child windows are to be enumerated. If this parameter
|
541
|
+
# is NULL, this function is equivalent to EnumWindows.
|
542
|
+
# Windows 95/98/Me: hWndParent cannot be NULL.
|
543
|
+
# lpEnumFunc:: [in] Pointer to an application-defined callback. For more information, see EnumChildProc.
|
544
|
+
# lParam:: [in] Specifies an application-defined value to be passed to the callback function.
|
445
545
|
#
|
546
|
+
# *Return*:: Not used!
|
547
|
+
# ---
|
446
548
|
# API improved to accept blocks (instead of callback objects) and parent handle (value is optional, default 0)
|
447
|
-
# New Parameters:
|
448
|
-
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
449
|
-
# value (P) - Specifies an application-defined value(message) to be passed to the callback function.
|
450
|
-
# block given to method invocation serves as an application-defined callback function (see EnumChildProc).
|
451
549
|
#
|
452
|
-
#
|
453
|
-
#
|
454
|
-
#
|
455
|
-
#
|
550
|
+
# *New* Parameters:
|
551
|
+
# parent:: Handle to the parent window whose child windows are to be enumerated.
|
552
|
+
# value:: Specifies an application-defined value(message) to be passed to the callback function.
|
553
|
+
# attached block:: Serves as an application-defined callback function (see EnumWindowsProc).
|
554
|
+
# ---
|
555
|
+
# *Remarks*:
|
556
|
+
# - If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.
|
557
|
+
# - A child window that is moved or repositioned in the Z order during the enumeration process will be properly
|
558
|
+
# enumerated. The function does not enumerate a child window that is destroyed before being enumerated or that
|
559
|
+
# is created during the enumeration process.
|
456
560
|
#
|
457
561
|
#:call-seq:
|
458
562
|
# handles = enum_child_windows( parent_handle, [value=0] ) {|handle, value| your callback procedure }
|
459
563
|
#
|
460
|
-
function
|
564
|
+
function :EnumChildWindows, [:ulong, :EnumWindowsProc, :long], :bool, &return_enum
|
461
565
|
|
462
566
|
##
|
463
567
|
# GetForegroundWindow function returns a handle to the foreground window (the window with which the user
|
464
568
|
# is currently working). The system assigns a slightly higher priority to the thread that creates the
|
465
569
|
# foreground window than it does to other threads.
|
466
570
|
#
|
467
|
-
# Syntax
|
571
|
+
# [*Syntax*] HWND GetForegroundWindow(VOID);
|
468
572
|
#
|
469
|
-
#
|
470
|
-
#
|
573
|
+
# *Returns*:: The return value is a handle to the foreground window. The foreground window can be NULL in
|
574
|
+
# certain circumstances, such as when a window is losing activation.
|
471
575
|
#
|
472
576
|
#:call-seq:
|
473
577
|
# win_handle = [get_]foreground_window()
|
474
578
|
#
|
475
|
-
function
|
579
|
+
function :GetForegroundWindow, [], :ulong, zeronil: true
|
476
580
|
|
477
581
|
##
|
478
582
|
# The GetActiveWindow function retrieves the window handle to the active window attached to
|
479
583
|
# the calling thread's message queue.
|
480
584
|
#
|
481
|
-
# Syntax
|
585
|
+
# [*Syntax*] HWND GetActiveWindow(VOID);
|
482
586
|
#
|
483
|
-
#
|
484
|
-
#
|
587
|
+
# *Returns*:: The return value is the handle to the active window attached to the calling
|
588
|
+
# thread's message queue. Otherwise, the return value is NULL.
|
485
589
|
#
|
486
590
|
# Remarks: To get the handle to the foreground window, you can use GetForegroundWindow.
|
487
591
|
# To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.
|
@@ -489,8 +593,23 @@ module Win
|
|
489
593
|
#:call-seq:
|
490
594
|
# win_handle = [get_]active_window()
|
491
595
|
#
|
492
|
-
function
|
596
|
+
function :GetActiveWindow, [], :ulong, zeronil: true
|
493
597
|
|
598
|
+
# Convenience wrapper methods:
|
599
|
+
|
600
|
+
##
|
601
|
+
# Hides the window and activates another window
|
602
|
+
#
|
603
|
+
def hide_window(win_handle)
|
604
|
+
show_window(win_handle, SW_HIDE)
|
605
|
+
end
|
606
|
+
|
607
|
+
##
|
608
|
+
# Tests if given window handle points to foreground (topmost) window
|
609
|
+
#
|
610
|
+
def foreground?(win_handle)
|
611
|
+
win_handle == foreground_window
|
612
|
+
end
|
494
613
|
end
|
495
614
|
end
|
496
615
|
end
|