win 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +45 -20
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/win/dde.rb +13 -15
- data/lib/win/extensions.rb +1 -1
- data/lib/win/gui/convenience.rb +142 -0
- data/lib/win/gui/dialog.rb +15 -0
- data/lib/win/gui/input.rb +255 -0
- data/lib/win/gui/message.rb +22 -0
- data/lib/win/gui/window.rb +497 -0
- data/lib/win/gui.rb +17 -0
- data/lib/win/library.rb +10 -9
- data/spec/spec_helper.rb +53 -15
- data/spec/win/dde_spec.rb +1 -0
- data/spec/win/extensions_spec.rb +1 -1
- data/spec/win/{window/extra_spec.rb → gui/convenience_spec.rb} +19 -23
- data/spec/win/gui/dialog_spec.rb +42 -0
- data/spec/win/gui/input_spec.rb +39 -0
- data/spec/win/gui/message_spec.rb +43 -0
- data/spec/win/{window_spec.rb → gui/window_spec.rb} +7 -97
- data/spec/win/library_spec.rb +3 -6
- data/win.gemspec +21 -11
- metadata +20 -10
- data/lib/win/window/extra.rb +0 -113
- data/lib/win/window.rb +0 -608
data/lib/win/window.rb
DELETED
@@ -1,608 +0,0 @@
|
|
1
|
-
require 'win/library'
|
2
|
-
|
3
|
-
module Win
|
4
|
-
|
5
|
-
# Contains constants, functions and wrappers related to Windows manipulation
|
6
|
-
#
|
7
|
-
module Window
|
8
|
-
# Internal constants:
|
9
|
-
|
10
|
-
# Windows keyboard-related Constants:
|
11
|
-
# ? move to keyboard.rb?
|
12
|
-
KEY_DELAY = 0.00001
|
13
|
-
|
14
|
-
include Win::Library
|
15
|
-
|
16
|
-
#General constants:
|
17
|
-
|
18
|
-
# Windows Message Get Text
|
19
|
-
WM_GETTEXT = 0x000D
|
20
|
-
# Windows Message Sys Command
|
21
|
-
WM_SYSCOMMAND = 0x0112
|
22
|
-
# Sys Command Close
|
23
|
-
SC_CLOSE = 0xF060
|
24
|
-
|
25
|
-
# Key down keyboard event (the key is being depressed)
|
26
|
-
KEYEVENTF_KEYDOWN = 0
|
27
|
-
# Key up keyboard event (the key is being released)
|
28
|
-
KEYEVENTF_KEYUP = 2
|
29
|
-
# Extended kb event. If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
|
30
|
-
KEYEVENTF_EXTENDEDKEY = 1
|
31
|
-
|
32
|
-
# Virtual key codes:
|
33
|
-
|
34
|
-
# Control-break processing
|
35
|
-
VK_CANCEL = 0x03
|
36
|
-
# Backspace? key
|
37
|
-
VK_BACK = 0x08
|
38
|
-
# Tab key
|
39
|
-
VK_TAB = 0x09
|
40
|
-
# Shift key
|
41
|
-
VK_SHIFT = 0x10
|
42
|
-
# Ctrl key
|
43
|
-
VK_CONTROL = 0x11
|
44
|
-
# ENTER key
|
45
|
-
VK_RETURN = 0x0D
|
46
|
-
# ALT key
|
47
|
-
VK_ALT = 0x12
|
48
|
-
# ALT key alias
|
49
|
-
VK_MENU = 0x12
|
50
|
-
# PAUSE key
|
51
|
-
VK_PAUSE = 0x13
|
52
|
-
# CAPS LOCK key
|
53
|
-
VK_CAPITAL = 0x14
|
54
|
-
# ESC key
|
55
|
-
VK_ESCAPE = 0x1B
|
56
|
-
# SPACEBAR
|
57
|
-
VK_SPACE = 0x20
|
58
|
-
# PAGE UP key
|
59
|
-
VK_PRIOR = 0x21
|
60
|
-
# PAGE DOWN key
|
61
|
-
VK_NEXT = 0x22
|
62
|
-
# END key
|
63
|
-
VK_END = 0x23
|
64
|
-
# HOME key
|
65
|
-
VK_HOME = 0x24
|
66
|
-
# LEFT ARROW key
|
67
|
-
VK_LEFT = 0x25
|
68
|
-
# UP ARROW key
|
69
|
-
VK_UP = 0x26
|
70
|
-
# RIGHT ARROW key
|
71
|
-
VK_RIGHT = 0x27
|
72
|
-
# DOWN ARROW key
|
73
|
-
VK_DOWN = 0x28
|
74
|
-
# SELECT key
|
75
|
-
VK_SELECT = 0x29
|
76
|
-
# PRINT key
|
77
|
-
VK_PRINT = 0x2A
|
78
|
-
# EXECUTE key
|
79
|
-
VK_EXECUTE = 0x2B
|
80
|
-
# PRINT SCREEN key
|
81
|
-
VK_SNAPSHOT = 0x2C
|
82
|
-
# INS key
|
83
|
-
VK_INSERT = 0x2D
|
84
|
-
# DEL key
|
85
|
-
VK_DELETE = 0x2E
|
86
|
-
# HELP key
|
87
|
-
VK_HELP = 0x2F
|
88
|
-
|
89
|
-
# ShowWindow constants:
|
90
|
-
|
91
|
-
# Hides the window and activates another window.
|
92
|
-
SW_HIDE = 0
|
93
|
-
# Same as SW_SHOWNORMAL
|
94
|
-
SW_NORMAL = 1
|
95
|
-
# Activates and displays a window. If the window is minimized or maximized, the system restores it to its
|
96
|
-
# original size and position. An application should specify this flag when displaying the window for the first time.
|
97
|
-
SW_SHOWNORMAL = 1
|
98
|
-
# Activates the window and displays it as a minimized window.
|
99
|
-
SW_SHOWMINIMIZED = 2
|
100
|
-
# Activates the window and displays it as a maximized window.
|
101
|
-
SW_SHOWMAXIMIZED = 3
|
102
|
-
# Activates the window and displays it as a maximized window.
|
103
|
-
SW_MAXIMIZE = 3
|
104
|
-
# Displays a window in its most recent size and position. Similar to SW_SHOWNORMAL, but the window is not activated.
|
105
|
-
SW_SHOWNOACTIVATE = 4
|
106
|
-
# Activates the window and displays it in its current size and position.
|
107
|
-
SW_SHOW = 5
|
108
|
-
# Minimizes the specified window, activates the next top-level window in the Z order.
|
109
|
-
SW_MINIMIZE = 6
|
110
|
-
# Displays the window as a minimized window. Similar to SW_SHOWMINIMIZED, except the window is not activated.
|
111
|
-
SW_SHOWMINNOACTIVE= 7
|
112
|
-
# Displays the window in its current size and position. Similar to SW_SHOW, except the window is not activated.
|
113
|
-
SW_SHOWNA = 8
|
114
|
-
# Activates and displays the window. If the window is minimized or maximized, the system restores it to its original
|
115
|
-
# size and position. An application should specify this flag when restoring a minimized window.
|
116
|
-
SW_RESTORE = 9
|
117
|
-
# Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess
|
118
|
-
# function by the program that started the application.
|
119
|
-
SW_SHOWDEFAULT = 10
|
120
|
-
# Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. Only use this
|
121
|
-
# flag when minimizing windows from a different thread.
|
122
|
-
SW_FORCEMINIMIZE = 11
|
123
|
-
|
124
|
-
class << self
|
125
|
-
# Def_block that calls API function expecting EnumWindowsProc callback (EnumWindows, EnumChildWindows, ...).
|
126
|
-
# Default callback just pushes all passed handles into Array that is returned if Enum function call was successful.
|
127
|
-
# If runtime block is given it is added to the end of default callback (handles Array is still collected/returned).
|
128
|
-
# If Enum function call failed, method returns nil, otherwise an Array of window handles.
|
129
|
-
#
|
130
|
-
def return_enum #:nodoc:
|
131
|
-
lambda do |api, *args, &block|
|
132
|
-
args.push 0 if args.size == api.prototype.size - 2 # If value is missing, it defaults to 0
|
133
|
-
handles = []
|
134
|
-
|
135
|
-
# Insert callback proc into appropriate place of args Array
|
136
|
-
args[api.prototype.find_index(:enum_callback), 0] =
|
137
|
-
proc do |handle, message|
|
138
|
-
handles << handle
|
139
|
-
block ? block[handle, message] : true
|
140
|
-
end
|
141
|
-
handles if api.call *args
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# Helper method that creates def_block returning (possibly encoded) string as a result of
|
146
|
-
# api function call or nil if zero characters was returned by api call
|
147
|
-
#
|
148
|
-
def return_string( encode = nil ) #:nodoc:
|
149
|
-
lambda do |api, *args|
|
150
|
-
namespace.enforce_count( args, api.prototype, -2)
|
151
|
-
buffer = FFI::MemoryPointer.new :char, 1024
|
152
|
-
buffer.put_string(0, "\x00" * 1023)
|
153
|
-
args += [buffer, 1024]
|
154
|
-
num_chars = api.call(*args)
|
155
|
-
return nil if num_chars == 0
|
156
|
-
if encode
|
157
|
-
string = buffer.get_bytes(0, num_chars*2)
|
158
|
-
string = string.force_encoding('utf-16LE').encode(encode)
|
159
|
-
else
|
160
|
-
string = buffer.get_bytes(0, num_chars)
|
161
|
-
end
|
162
|
-
string.rstrip
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
private :return_enum, :return_string
|
167
|
-
end
|
168
|
-
|
169
|
-
# Windows GUI API definitions:
|
170
|
-
|
171
|
-
##
|
172
|
-
# Tests whether the specified window handle identifies an existing window.
|
173
|
-
# A thread should not use IsWindow for a window that it did not create because the window
|
174
|
-
# could be destroyed after this function was called. Further, because window handles are
|
175
|
-
# recycled the handle could even point to a different window.
|
176
|
-
#
|
177
|
-
# :call-seq:
|
178
|
-
# window?( win_handle )
|
179
|
-
#
|
180
|
-
function 'IsWindow', 'L', 'L'
|
181
|
-
|
182
|
-
##
|
183
|
-
# Tests if the specified window, its parent window, its parent's parent window, and so forth,
|
184
|
-
# have the WS_VISIBLE style. Because the return value specifies whether the window has the
|
185
|
-
# WS_VISIBLE style, it may be true even if the window is totally obscured by other windows.
|
186
|
-
#
|
187
|
-
# :call-seq:
|
188
|
-
# [window_]visible?( win_handle )
|
189
|
-
#
|
190
|
-
function 'IsWindowVisible', 'L', 'L', aliases: :visible?
|
191
|
-
|
192
|
-
##
|
193
|
-
# Tests whether the specified window is maximized.
|
194
|
-
#
|
195
|
-
# :call-seq:
|
196
|
-
# zoomed?( win_handle ), maximized?( win_handle )
|
197
|
-
#
|
198
|
-
function 'IsZoomed', 'L', 'L', aliases: :maximized?
|
199
|
-
|
200
|
-
##
|
201
|
-
# Tests whether the specified window is maximized.
|
202
|
-
#
|
203
|
-
# :call-seq:
|
204
|
-
# iconic?( win_handle ), minimized?( win_handle )
|
205
|
-
#
|
206
|
-
function 'IsIconic', 'L', 'L', aliases: :minimized?
|
207
|
-
|
208
|
-
##
|
209
|
-
# Tests whether a window is a child (or descendant) window of a specified parent window.
|
210
|
-
# A child window is the direct descendant of a specified parent window if that parent window
|
211
|
-
# is in the chain of parent windows; the chain of parent windows leads from the original overlapped
|
212
|
-
# or pop-up window to the child window.
|
213
|
-
#
|
214
|
-
# :call-seq:
|
215
|
-
# child?( win_handle )
|
216
|
-
#
|
217
|
-
function 'IsChild', 'LL', 'L'
|
218
|
-
|
219
|
-
##
|
220
|
-
# Returns a handle to the top-level window whose class and window name match the specified strings.
|
221
|
-
# This function does not search child windows. This function does not perform a case-sensitive search.
|
222
|
-
#
|
223
|
-
# Parameters:
|
224
|
-
# class_name (P) - String that specifies (window) class name OR class atom created by a previous
|
225
|
-
# call to the RegisterClass(Ex) function. The atom must be in the low-order word of class_name;
|
226
|
-
# the high-order word must be zero. The class name can be any name registered with RegisterClass(Ex),
|
227
|
-
# or any of the predefined control-class names. If this parameter is nil, it finds any window whose
|
228
|
-
# title matches the win_title parameter.
|
229
|
-
# win_name (P) - String that specifies the window name (title). If nil, all names match.
|
230
|
-
# Return Value (L): found window handle or NIL if nothing found
|
231
|
-
#
|
232
|
-
# :call-seq:
|
233
|
-
# win_handle = find_window( class_name, win_name )
|
234
|
-
#
|
235
|
-
function 'FindWindow', 'PP', 'L', zeronil: true
|
236
|
-
|
237
|
-
##
|
238
|
-
# Unicode version of find_window (strings must be encoded as utf-16LE AND terminate with "\x00\x00")
|
239
|
-
#
|
240
|
-
# :call-seq:
|
241
|
-
# win_handle = find_window_w( class_name, win_name )
|
242
|
-
#
|
243
|
-
function 'FindWindowW', 'PP', 'L', zeronil: true
|
244
|
-
|
245
|
-
##
|
246
|
-
# Retrieves a handle to a CHILD window whose class name and window name match the specified strings.
|
247
|
-
# The function searches child windows, beginning with the one following the specified child window.
|
248
|
-
# This function does NOT perform a case-sensitive search.
|
249
|
-
#
|
250
|
-
# Parameters:
|
251
|
-
# parent (L) - Handle to the parent window whose child windows are to be searched.
|
252
|
-
# If nil, the function uses the desktop window as the parent window.
|
253
|
-
# The function searches among windows that are child windows of the desktop.
|
254
|
-
# after_child (L) - Handle to a child window. Search begins with the NEXT child window in the Z order.
|
255
|
-
# The child window must be a direct child window of parent, not just a descendant window.
|
256
|
-
# If after_child is nil, the search begins with the first child window of parent.
|
257
|
-
# win_class (P), win_title (P) - Strings that specify window class and name(title). If nil, anything matches.
|
258
|
-
# Returns (L): found child window handle or NIL if nothing found
|
259
|
-
#
|
260
|
-
# :call-seq:
|
261
|
-
# win_handle = find_window_ex( win_handle, after_child, class_name, win_name )
|
262
|
-
#
|
263
|
-
function 'FindWindowEx', 'LLPP', 'L', zeronil: true
|
264
|
-
|
265
|
-
##
|
266
|
-
# Returns the text of the specified window's title bar (if it has one).
|
267
|
-
# If the specified window is a control, the text of the control is copied. However, GetWindowText
|
268
|
-
# cannot retrieve the text of a control in another application.
|
269
|
-
#
|
270
|
-
# Original Parameters:
|
271
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
272
|
-
# text (P) - Long Pointer to the buffer that is to receive the text string.
|
273
|
-
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the text parameter.
|
274
|
-
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
275
|
-
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
276
|
-
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
277
|
-
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
278
|
-
#
|
279
|
-
# Enhanced API requires only win_handle and returns rstripped text
|
280
|
-
#
|
281
|
-
# Enhanced Parameters:
|
282
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
283
|
-
# Returns: Window title bar text or nil
|
284
|
-
# If the window has no title bar or text, if the title bar is empty, or if the window or control handle
|
285
|
-
# is invalid, the return value is NIL. To get extended error information, call GetLastError.
|
286
|
-
#
|
287
|
-
# Remarks: This function CANNOT retrieve the text of an edit control in ANOTHER app.
|
288
|
-
# If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to
|
289
|
-
# be sent to the specified window or control. If the target window is owned by another process and has
|
290
|
-
# a caption, GetWindowText retrieves the window caption text. If the window does not have a caption,
|
291
|
-
# the return value is a null string. This allows to call GetWindowText without becoming unresponsive
|
292
|
-
# if the target window owner process is not responding. However, if the unresponsive target window
|
293
|
-
# belongs to the calling app, GetWindowText will cause the calling app to become unresponsive.
|
294
|
-
# To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead
|
295
|
-
# of calling GetWindowText.
|
296
|
-
#
|
297
|
-
#:call-seq:
|
298
|
-
# text = [get_]window_text( win_handle )
|
299
|
-
#
|
300
|
-
function 'GetWindowText', 'LPI', 'L', &return_string
|
301
|
-
|
302
|
-
##
|
303
|
-
# Unicode version of get_window_text (returns rstripped utf-8 string)
|
304
|
-
# API improved to require only win_handle and return rstripped string
|
305
|
-
#
|
306
|
-
#:call-seq:
|
307
|
-
# text = [get_]window_text_w( win_handle )
|
308
|
-
#
|
309
|
-
function 'GetWindowTextW', 'LPI', 'L', &return_string('utf-8')
|
310
|
-
|
311
|
-
##
|
312
|
-
# Retrieves the name of the class to which the specified window belongs.
|
313
|
-
#
|
314
|
-
# Original Parameters:
|
315
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
316
|
-
# class_name (P) - Long Pointer to the buffer that is to receive the class name string.
|
317
|
-
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the class_name parameter.
|
318
|
-
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
319
|
-
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
320
|
-
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
321
|
-
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
322
|
-
#
|
323
|
-
# API improved to require only win_handle and return rstripped string
|
324
|
-
#
|
325
|
-
# Enhanced Parameters:
|
326
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
327
|
-
# Returns: Name of the class or NIL if function fails. For extended error information, call GetLastError.
|
328
|
-
#
|
329
|
-
#:call-seq:
|
330
|
-
# text = [get_]class_name( win_handle )
|
331
|
-
#
|
332
|
-
function 'GetClassName', 'LPI', 'I', &return_string
|
333
|
-
|
334
|
-
##
|
335
|
-
# Unicode version of get_class_name (returns rstripped utf-8 string)
|
336
|
-
# API improved to require only win_handle and return rstripped string
|
337
|
-
#
|
338
|
-
#:call-seq:
|
339
|
-
# text = [get_]class_name_w( win_handle )
|
340
|
-
#
|
341
|
-
function 'GetClassNameW', 'LPI', 'I', &return_string('utf-8')
|
342
|
-
|
343
|
-
##
|
344
|
-
# Shows and hides windows.
|
345
|
-
#
|
346
|
-
# Parameters:
|
347
|
-
# win_handle (L) - Handle to the window.
|
348
|
-
# cmd (I) - Specifies how the window is to be shown. This parameter is ignored the first time an
|
349
|
-
# application calls ShowWindow, if the program that launched the application provides a STARTUPINFO
|
350
|
-
# structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained
|
351
|
-
# by the WinMain function in its nCmdShow parameter. In subsequent calls, cmd may be:
|
352
|
-
# SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE,
|
353
|
-
# SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL, SW_RESTORE, SW_SHOWDEFAULT, SW_FORCEMINIMIZE
|
354
|
-
#
|
355
|
-
# Original Return Value: - Nonzero if the window was PREVIOUSLY visible, otherwise zero
|
356
|
-
# Enhanced Returns: - True if the window was PREVIOUSLY visible, otherwise false
|
357
|
-
#
|
358
|
-
#:call-seq:
|
359
|
-
# was_visible = show_window( win_handle, cmd )
|
360
|
-
#
|
361
|
-
function 'ShowWindow', 'LI', 'I', boolean: true
|
362
|
-
|
363
|
-
# Hides the window and activates another window
|
364
|
-
def hide_window(win_handle)
|
365
|
-
show_window(win_handle, SW_HIDE)
|
366
|
-
end
|
367
|
-
|
368
|
-
##
|
369
|
-
# Retrieves the identifier of the thread that created the specified window
|
370
|
-
# and, optionally, the identifier of the process that created the window.
|
371
|
-
#
|
372
|
-
# Original Parameters:
|
373
|
-
# handle (L) - Handle to the window.
|
374
|
-
# process (P) - A POINTER to a (Long) variable that receives the process identifier.
|
375
|
-
# Original Return (L): Identifier of the thread that created the window.
|
376
|
-
#
|
377
|
-
# API improved to accept window handle as a single arg and return a pair of [thread, process] ids
|
378
|
-
#
|
379
|
-
# New Parameters:
|
380
|
-
# handle (L) - Handle to the window.
|
381
|
-
# Returns: Pair of identifiers of the thread and process_id that created the window.
|
382
|
-
#
|
383
|
-
#:call-seq:
|
384
|
-
# thread, process_id = [get_]window_tread_process_id( win_handle )
|
385
|
-
#
|
386
|
-
function 'GetWindowThreadProcessId', [:long, :pointer], :long, &->(api, *args) {
|
387
|
-
namespace.enforce_count( args, api.prototype, -1)
|
388
|
-
process = FFI::MemoryPointer.new(:long)
|
389
|
-
process.write_long(1)
|
390
|
-
thread = api.call(args.first, process)
|
391
|
-
thread == 0 ? [nil, nil] : [thread, process.read_long()] }
|
392
|
-
# weird lambda literal instead of block is needed because RDoc goes crazy if block is attached to meta-definition
|
393
|
-
|
394
|
-
##
|
395
|
-
# Retrieves the dimensions of the specified window bounding rectangle.
|
396
|
-
# Dimensions are given relative to the upper-left corner of the screen.
|
397
|
-
#
|
398
|
-
# Original Parameters:
|
399
|
-
# win_handle (L) - Handle to the window.
|
400
|
-
# rect (P) - Long pointer to a RECT structure that receives the screen coordinates of the upper-left and
|
401
|
-
# lower-right corners of the window.
|
402
|
-
# Original Return Value: Nonzero indicates success. Zero indicates failure. For error info, call GetLastError.
|
403
|
-
#
|
404
|
-
# API improved to accept only window handle and return 4-member dimensions array (left, top, right, bottom)
|
405
|
-
#
|
406
|
-
# New Parameters:
|
407
|
-
# win_handle (L) - Handle to the window
|
408
|
-
# New Return: Array(left, top, right, bottom) - rectangle dimensions
|
409
|
-
#
|
410
|
-
# Remarks: As a convention for the RECT structure, the bottom-right coordinates of the returned rectangle
|
411
|
-
# are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.
|
412
|
-
#
|
413
|
-
#:call-seq:
|
414
|
-
# rect = [get_]window_rect( win_handle )
|
415
|
-
#
|
416
|
-
function 'GetWindowRect', 'LP', 'I', &->(api, *args) {
|
417
|
-
namespace.enforce_count( args, api.prototype, -1)
|
418
|
-
rect = FFI::MemoryPointer.new(:long, 4)
|
419
|
-
rect.write_array_of_long([0, 0, 0, 0])
|
420
|
-
res = api.call args.first, rect
|
421
|
-
res == 0 ? [nil, nil, nil, nil] : rect.read_array_of_long(4) }
|
422
|
-
# weird lambda literal instead of block is needed because RDoc goes crazy if block is attached to meta-definition
|
423
|
-
|
424
|
-
# This is an application-defined callback function that receives top-level window handles as a result of a call
|
425
|
-
# to the EnumWindows, EnumChildWindows or EnumDesktopWindows function.
|
426
|
-
#
|
427
|
-
# Syntax: BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam );
|
428
|
-
#
|
429
|
-
# Parameters:
|
430
|
-
# hwnd (L) - [out] Handle to a top-level window.
|
431
|
-
# lParam (L) - [in] Specifies the application-defined value given in EnumWindows or EnumDesktopWindows.
|
432
|
-
# Return Values:
|
433
|
-
# TRUE continues enumeration. FALSE stops enumeration.
|
434
|
-
#
|
435
|
-
# Remarks: An application must register this callback function by passing its address to EnumWindows or EnumDesktopWindows.
|
436
|
-
callback :enum_callback, 'LL', :bool
|
437
|
-
|
438
|
-
##
|
439
|
-
# The EnumWindows function enumerates all top-level windows on the screen by passing the handle to
|
440
|
-
# each window, in turn, to an application-defined callback function. EnumWindows continues until
|
441
|
-
# the last top-level window is enumerated or the callback function returns FALSE.
|
442
|
-
#
|
443
|
-
# Original Parameters:
|
444
|
-
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
445
|
-
# value [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
446
|
-
# Original Return: Nonzero if the function succeeds, zero if the function fails. GetLastError for error info.
|
447
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
448
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
449
|
-
#
|
450
|
-
# API improved to accept blocks (instead of callback objects) and message as a single arg
|
451
|
-
#
|
452
|
-
# New Parameters:
|
453
|
-
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
454
|
-
# block given to method invocation serves as an application-defined callback function (see EnumWindowsProc).
|
455
|
-
# Returns: True if the function succeeds, false if the function fails. GetLastError for error info.
|
456
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
457
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
458
|
-
#
|
459
|
-
# Remarks: The EnumWindows function does not enumerate child windows, with the exception of a few top-level
|
460
|
-
# windows owned by the system that have the WS_CHILD style. This function is more reliable than calling
|
461
|
-
# the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being
|
462
|
-
# caught in an infinite loop or referencing a handle to a window that has been destroyed.
|
463
|
-
#
|
464
|
-
#:call-seq:
|
465
|
-
# handles = enum_windows( [value] ) {|handle, message| your callback procedure }
|
466
|
-
#
|
467
|
-
function'EnumWindows', [:enum_callback, :long], :bool, &return_enum
|
468
|
-
|
469
|
-
##
|
470
|
-
#EnumDesktopWindows Function
|
471
|
-
#
|
472
|
-
#Enumerates all top-level windows associated with the specified desktop. It passes the handle to each window, in turn, to an application-defined callback function.
|
473
|
-
#
|
474
|
-
#
|
475
|
-
#Syntax
|
476
|
-
#BOOL WINAPI EnumDesktopWindows(
|
477
|
-
# __in_opt HDESK hDesktop,
|
478
|
-
# __in WNDENUMPROC lpfn,
|
479
|
-
# __in LPARAM lParam
|
480
|
-
#);
|
481
|
-
#
|
482
|
-
#Parameters
|
483
|
-
#hDesktop
|
484
|
-
#A handle to the desktop whose top-level windows are to be enumerated. This handle is returned by the CreateDesktop, GetThreadDesktop, OpenDesktop, or OpenInputDesktop function, and must have the DESKTOP_ENUMERATE access right. For more information, see Desktop Security and Access Rights.
|
485
|
-
#
|
486
|
-
#If this parameter is NULL, the current desktop is used.
|
487
|
-
#
|
488
|
-
#lpfn
|
489
|
-
#A pointer to an application-defined EnumWindowsProc callback function.
|
490
|
-
#
|
491
|
-
#lParam
|
492
|
-
#An application-defined value to be passed to the callback function.
|
493
|
-
#
|
494
|
-
#Return Value
|
495
|
-
#If the function fails or is unable to perform the enumeration, the return value is zero.
|
496
|
-
#
|
497
|
-
#To get extended error information, call GetLastError.
|
498
|
-
#
|
499
|
-
#You must ensure that the callback function sets SetLastError if it fails.
|
500
|
-
#
|
501
|
-
#Windows Server 2003 and Windows XP/2000: If there are no windows on the desktop, GetLastError returns ERROR_INVALID_HANDLE.
|
502
|
-
#Remarks
|
503
|
-
#The EnumDesktopWindows function repeatedly invokes the lpfn callback function until the last top-level window is enumerated or the callback function returns FALSE.
|
504
|
-
#
|
505
|
-
#Requirements
|
506
|
-
#Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
507
|
-
function'EnumDesktopWindows', [:ulong, :enum_callback, :long], :bool, &return_enum
|
508
|
-
|
509
|
-
##
|
510
|
-
# Enumerates child windows to a given window.
|
511
|
-
#
|
512
|
-
# Original Parameters:
|
513
|
-
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
514
|
-
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
515
|
-
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
516
|
-
# Original Return: Not used (?!)
|
517
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
518
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
519
|
-
# If it is nil, this function is equivalent to EnumWindows. Windows 95/98/Me: parent cannot be NULL.
|
520
|
-
#
|
521
|
-
# API improved to accept blocks (instead of callback objects) and parent handle (value is optional, default 0)
|
522
|
-
# New Parameters:
|
523
|
-
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
524
|
-
# value (P) - Specifies an application-defined value(message) to be passed to the callback function.
|
525
|
-
# block given to method invocation serves as an application-defined callback function (see EnumChildProc).
|
526
|
-
#
|
527
|
-
# Remarks:
|
528
|
-
# If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.
|
529
|
-
# A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated.
|
530
|
-
# The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process.
|
531
|
-
#
|
532
|
-
#:call-seq:
|
533
|
-
# handles = enum_child_windows( parent_handle, [value = 0] ) {|handle, message| your callback procedure }
|
534
|
-
#
|
535
|
-
function 'EnumChildWindows', [:ulong, :enum_callback, :long], :bool, &return_enum
|
536
|
-
|
537
|
-
##
|
538
|
-
# GetForegroundWindow function returns a handle to the foreground window (the window with which the user
|
539
|
-
# is currently working). The system assigns a slightly higher priority to the thread that creates the
|
540
|
-
# foreground window than it does to other threads.
|
541
|
-
#
|
542
|
-
# Syntax: HWND GetForegroundWindow(VOID);
|
543
|
-
#
|
544
|
-
# Return Value: The return value is a handle to the foreground window. The foreground window can be NULL in
|
545
|
-
# certain circumstances, such as when a window is losing activation.
|
546
|
-
#
|
547
|
-
#:call-seq:
|
548
|
-
# win_handle = [get_]foreground_window()
|
549
|
-
#
|
550
|
-
function 'GetForegroundWindow', [], 'L'
|
551
|
-
|
552
|
-
##
|
553
|
-
# Tests if given window handle points to foreground (topmost) window
|
554
|
-
#
|
555
|
-
def foreground?(win_handle)
|
556
|
-
win_handle == foreground_window
|
557
|
-
end
|
558
|
-
|
559
|
-
##
|
560
|
-
# The GetActiveWindow function retrieves the window handle to the active window attached to
|
561
|
-
# the calling thread's message queue.
|
562
|
-
#
|
563
|
-
# Syntax: HWND GetActiveWindow(VOID);
|
564
|
-
#
|
565
|
-
# Return Value: The return value is the handle to the active window attached to the calling
|
566
|
-
# thread's message queue. Otherwise, the return value is NULL.
|
567
|
-
#
|
568
|
-
# Remarks: To get the handle to the foreground window, you can use GetForegroundWindow.
|
569
|
-
# To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.
|
570
|
-
#
|
571
|
-
#:call-seq:
|
572
|
-
# win_handle = [get_]active_window()
|
573
|
-
#
|
574
|
-
function 'GetActiveWindow', [], 'L'
|
575
|
-
|
576
|
-
##
|
577
|
-
# The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate
|
578
|
-
# a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
|
579
|
-
#
|
580
|
-
# !!!! Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead.
|
581
|
-
#
|
582
|
-
# Syntax: VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, PTR dwExtraInfo);
|
583
|
-
#
|
584
|
-
# Parameters:
|
585
|
-
# bVk [C] - [in] Specifies a virtual-key code. The code must be a value in the range 1 to 254.
|
586
|
-
# For a complete list, see Virtual-Key Codes.
|
587
|
-
# bScan [C] - [in] Specifies a hardware scan code for the key.
|
588
|
-
# dwFlags [L] - [in] Specifies various aspects of function operation. This parameter can be
|
589
|
-
# one or more of the following values:
|
590
|
-
# KEYEVENTF_EXTENDEDKEY, KEYEVENTF_KEYUP, KEYEVENTF_KEYDOWN
|
591
|
-
# dwExtraInfo [L] -[in] Specifies an additional value associated with the key stroke.
|
592
|
-
#
|
593
|
-
# Return Value: none
|
594
|
-
#
|
595
|
-
# Remarks: An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot and save
|
596
|
-
# it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT.
|
597
|
-
#
|
598
|
-
# Windows NT/2000/XP: The keybd_event function can toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.
|
599
|
-
# Windows 95/98/Me: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys.
|
600
|
-
#
|
601
|
-
function 'keybd_event', 'IILL', 'V'
|
602
|
-
|
603
|
-
function 'PostMessage', 'LLLL', 'L'
|
604
|
-
function 'SendMessage', 'LLLP', 'L'
|
605
|
-
function 'GetDlgItem', 'LL', 'L'
|
606
|
-
|
607
|
-
end
|
608
|
-
end
|