win 0.1.0 → 0.1.2
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 +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/message.rb
CHANGED
@@ -7,15 +7,375 @@ module Win
|
|
7
7
|
module Message
|
8
8
|
include Win::Library
|
9
9
|
|
10
|
+
# Window messages:
|
11
|
+
|
12
|
+
WM_NULL = 0x0000
|
13
|
+
WA_INACTIVE = 0x0000
|
14
|
+
WM_CREATE = 0x0001
|
15
|
+
WA_ACTIVE = 0x0001
|
16
|
+
WM_DESTROY = 0x0002
|
17
|
+
WA_CLICKACTIVE = 0x0002
|
18
|
+
WM_MOVE = 0x0003
|
19
|
+
WM_SIZE = 0x0005
|
20
|
+
WM_ACTIVATE = 0x0006
|
21
|
+
WM_SETFOCUS = 0x0007
|
22
|
+
WM_KILLFOCUS = 0x0008
|
23
|
+
WM_ENABLE = 0x000A
|
24
|
+
WM_SETREDRAW = 0x000B
|
25
|
+
WM_SETTEXT = 0x000C
|
10
26
|
# Windows Message Get Text
|
11
|
-
WM_GETTEXT
|
27
|
+
WM_GETTEXT = 0x000D
|
28
|
+
WM_GETTEXTLENGTH = 0x000E
|
29
|
+
WM_PAINT = 0x000F
|
30
|
+
WM_CLOSE = 0x0010
|
31
|
+
WM_QUERYENDSESSION= 0x0011
|
32
|
+
WM_QUIT = 0x0012
|
33
|
+
WM_QUERYOPEN = 0x0013
|
34
|
+
WM_ERASEBKGND = 0x0014
|
35
|
+
WM_SYSCOLORCHANGE = 0x0015
|
36
|
+
WM_ENDSESSION = 0x0016
|
37
|
+
WM_SHOWWINDOW = 0x0018
|
38
|
+
WM_WININICHANGE = 0x001A
|
39
|
+
WM_SETTINGCHANGE = WM_WININICHANGE
|
40
|
+
WM_DEVMODECHANGE = 0x001B
|
41
|
+
WM_ACTIVATEAPP = 0x001C
|
42
|
+
WM_FONTCHANGE = 0x001D
|
43
|
+
WM_TIMECHANGE = 0x001E
|
44
|
+
WM_CANCELMODE = 0x001F
|
45
|
+
WM_SETCURSOR = 0x0020
|
46
|
+
WM_MOUSEACTIVATE = 0x0021
|
47
|
+
WM_CHILDACTIVATE = 0x0022
|
48
|
+
WM_QUEUESYNC = 0x0023
|
49
|
+
WM_GETMINMAXINFO = 0x0024
|
50
|
+
WM_PAINTICON = 0x0026
|
51
|
+
WM_ICONERASEBKGND = 0x0027
|
52
|
+
WM_NEXTDLGCTL = 0x0028
|
53
|
+
WM_SPOOLERSTATUS = 0x002A
|
54
|
+
WM_DRAWITEM = 0x002B
|
55
|
+
WM_MEASUREITEM = 0x002C
|
56
|
+
WM_DELETEITEM = 0x002D
|
57
|
+
WM_VKEYTOITEM = 0x002E
|
58
|
+
WM_CHARTOITEM = 0x002F
|
59
|
+
WM_SETFONT = 0x0030
|
60
|
+
WM_GETFONT = 0x0031
|
61
|
+
WM_SETHOTKEY = 0x0032
|
62
|
+
WM_GETHOTKEY = 0x0033
|
63
|
+
WM_QUERYDRAGICON = 0x0037
|
64
|
+
WM_COMPAREITEM = 0x0039
|
65
|
+
WM_COMPACTING = 0x0041
|
66
|
+
WM_COMMNOTIFY = 0x0044 # no longer supported
|
67
|
+
WM_WINDOWPOSCHANGING = 0x0046
|
68
|
+
WM_WINDOWPOSCHANGED = 0x0047
|
69
|
+
WM_POWER = 0x0048
|
70
|
+
WM_COPYDATA = 0x004A
|
71
|
+
WM_CANCELJOURNAL = 0x004B
|
72
|
+
WM_NOTIFY = 0x004E
|
73
|
+
WM_INPUTLANGCHANGEREQUEST = 0x0050
|
74
|
+
WM_INPUTLANGCHANGE = 0x0051
|
75
|
+
WM_TCARD = 0x0052
|
76
|
+
WM_HELP = 0x0053
|
77
|
+
WM_USERCHANGED = 0x0054
|
78
|
+
WM_NOTIFYFORMAT = 0x0055
|
79
|
+
WM_CONTEXTMENU = 0x007B
|
80
|
+
WM_STYLECHANGING = 0x007C
|
81
|
+
WM_STYLECHANGED = 0x007D
|
82
|
+
WM_DISPLAYCHANGE = 0x007E
|
83
|
+
WM_GETICON = 0x007F
|
84
|
+
WM_SETICON = 0x0080
|
85
|
+
WM_NCCREATE = 0x0081
|
86
|
+
WM_NCDESTROY = 0x0082
|
87
|
+
WM_NCCALCSIZE = 0x0083
|
88
|
+
WM_NCHITTEST = 0x0084
|
89
|
+
WM_NCPAINT = 0x0085
|
90
|
+
WM_NCACTIVATE = 0x0086
|
91
|
+
WM_GETDLGCODE = 0x0087
|
92
|
+
WM_SYNCPAINT = 0x0088
|
93
|
+
WM_NCMOUSEMOVE = 0x00A0
|
94
|
+
WM_NCLBUTTONDOWN = 0x00A1
|
95
|
+
WM_NCLBUTTONUP = 0x00A2
|
96
|
+
WM_NCLBUTTONDBLCLK = 0x00A3
|
97
|
+
WM_NCRBUTTONDOWN = 0x00A4
|
98
|
+
WM_NCRBUTTONUP = 0x00A5
|
99
|
+
WM_NCRBUTTONDBLCLK = 0x00A6
|
100
|
+
WM_NCMBUTTONDOWN = 0x00A7
|
101
|
+
WM_NCMBUTTONUP = 0x00A8
|
102
|
+
WM_NCMBUTTONDBLCLK = 0x00A9
|
103
|
+
WM_NCXBUTTONDOWN = 0x00AB
|
104
|
+
WM_NCXBUTTONUP = 0x00AC
|
105
|
+
WM_NCXBUTTONDBLCLK = 0x00AD
|
106
|
+
WM_INPUT = 0x00FF
|
107
|
+
WM_KEYFIRST = 0x0100
|
108
|
+
WM_KEYDOWN = 0x0100
|
109
|
+
WM_KEYUP = 0x0101
|
110
|
+
WM_CHAR = 0x0102
|
111
|
+
WM_DEADCHAR = 0x0103
|
112
|
+
WM_SYSKEYDOWN = 0x0104
|
113
|
+
WM_SYSKEYUP = 0x0105
|
114
|
+
WM_SYSCHAR = 0x0106
|
115
|
+
WM_SYSDEADCHAR = 0x0107
|
116
|
+
WM_UNICHAR = 0x0109
|
117
|
+
WM_IME_STARTCOMPOSITION = 0x010D
|
118
|
+
WM_IME_ENDCOMPOSITION = 0x010E
|
119
|
+
WM_IME_COMPOSITION = 0x010F
|
120
|
+
WM_IME_KEYLAST = 0x010F
|
121
|
+
WM_INITDIALOG = 0x0110
|
122
|
+
WM_COMMAND = 0x0111
|
12
123
|
# Windows Message Sys Command
|
13
|
-
WM_SYSCOMMAND
|
124
|
+
WM_SYSCOMMAND = 0x0112
|
125
|
+
WM_TIMER = 0x0113
|
126
|
+
WM_HSCROLL = 0x0114
|
127
|
+
WM_VSCROLL = 0x0115
|
128
|
+
WM_INITMENU = 0x0116
|
129
|
+
WM_INITMENUPOPUP = 0x0117
|
130
|
+
WM_MENUSELECT = 0x011F
|
131
|
+
WM_MENUCHAR = 0x0120
|
132
|
+
WM_ENTERIDLE = 0x0121
|
133
|
+
WM_MENURBUTTONUP = 0x0122
|
134
|
+
WM_MENUDRAG = 0x0123
|
135
|
+
WM_MENUGETOBJECT = 0x0124
|
136
|
+
WM_UNINITMENUPOPUP = 0x0125
|
137
|
+
WM_MENUCOMMAND = 0x0126
|
138
|
+
WM_CHANGEUISTATE = 0x0127
|
139
|
+
WM_UPDATEUISTATE = 0x0128
|
140
|
+
WM_QUERYUISTATE = 0x0129
|
141
|
+
WM_CTLCOLORMSGBOX = 0x0132
|
142
|
+
WM_CTLCOLOREDIT = 0x0133
|
143
|
+
WM_CTLCOLORLISTBOX = 0x0134
|
144
|
+
WM_CTLCOLORBTN = 0x0135
|
145
|
+
WM_CTLCOLORDLG = 0x0136
|
146
|
+
WM_CTLCOLORSCROLLBAR = 0x0137
|
147
|
+
WM_CTLCOLORSTATIC = 0x0138
|
148
|
+
WM_MOUSEFIRST = 0x0200
|
149
|
+
WM_MOUSEMOVE = 0x0200
|
150
|
+
WM_LBUTTONDOWN = 0x0201
|
151
|
+
WM_LBUTTONUP = 0x0202
|
152
|
+
WM_LBUTTONDBLCLK = 0x0203
|
153
|
+
WM_RBUTTONDOWN = 0x0204
|
154
|
+
WM_RBUTTONUP = 0x0205
|
155
|
+
WM_RBUTTONDBLCLK = 0x0206
|
156
|
+
WM_MBUTTONDOWN = 0x0207
|
157
|
+
WM_MBUTTONUP = 0x0208
|
158
|
+
WM_MBUTTONDBLCLK = 0x0209
|
159
|
+
WM_MOUSEWHEEL = 0x020A
|
160
|
+
WM_XBUTTONDOWN = 0x020B
|
161
|
+
WM_XBUTTONUP = 0x020C
|
162
|
+
WM_XBUTTONDBLCLK = 0x020D
|
163
|
+
WM_MOUSELAST = 0x020D # Win2k or later
|
164
|
+
WM_PARENTNOTIFY = 0x0210
|
165
|
+
WM_ENTERMENULOOP = 0x0211
|
166
|
+
WM_EXITMENULOOP = 0x0212
|
167
|
+
WM_NEXTMENU = 0x0213
|
168
|
+
WM_SIZING = 0x0214
|
169
|
+
WM_CAPTURECHANGED = 0x0215
|
170
|
+
WM_MOVING = 0x0216
|
171
|
+
WM_POWERBROADCAST = 0x0218
|
172
|
+
WM_DEVICECHANGE = 0x0219
|
173
|
+
WM_MDICREATE = 0x0220
|
174
|
+
WM_MDIDESTROY = 0x0221
|
175
|
+
WM_MDIACTIVATE = 0x0222
|
176
|
+
WM_MDIRESTORE = 0x0223
|
177
|
+
WM_MDINEXT = 0x0224
|
178
|
+
WM_MDIMAXIMIZE = 0x0225
|
179
|
+
WM_MDITILE = 0x0226
|
180
|
+
WM_MDICASCADE = 0x0227
|
181
|
+
WM_MDIICONARRANGE = 0x0228
|
182
|
+
WM_MDIGETACTIVE = 0x0229
|
183
|
+
WM_MDISETMENU = 0x0230
|
184
|
+
WM_ENTERSIZEMOVE = 0x0231
|
185
|
+
WM_EXITSIZEMOVE = 0x0232
|
186
|
+
WM_DROPFILES = 0x0233
|
187
|
+
WM_MDIREFRESHMENU = 0x0234
|
188
|
+
WM_IME_SETCONTEXT = 0x0281
|
189
|
+
WM_IME_NOTIFY = 0x0282
|
190
|
+
WM_IME_CONTROL = 0x0283
|
191
|
+
WM_IME_COMPOSITIONFULL = 0x0284
|
192
|
+
WM_IME_SELECT = 0x0285
|
193
|
+
WM_IME_CHAR = 0x0286
|
194
|
+
WM_IME_REQUEST = 0x0288
|
195
|
+
WM_IME_KEYDOWN = 0x0290
|
196
|
+
WM_IME_KEYUP = 0x0291
|
197
|
+
WM_MOUSEHOVER = 0x02A1
|
198
|
+
WM_MOUSELEAVE = 0x02A3
|
199
|
+
WM_NCMOUSEHOVER = 0x02A0
|
200
|
+
WM_NCMOUSELEAVE = 0x02A2
|
201
|
+
WM_WTSSESSION_CHANGE = 0x02B1
|
202
|
+
WM_TABLET_FIRST = 0x02c0
|
203
|
+
WM_TABLET_LAST = 0x02df
|
204
|
+
WM_CUT = 0x0300
|
205
|
+
WM_COPY = 0x0301
|
206
|
+
WM_PASTE = 0x0302
|
207
|
+
WM_CLEAR = 0x0303
|
208
|
+
WM_UNDO = 0x0304
|
209
|
+
WM_RENDERFORMAT = 0x0305
|
210
|
+
WM_RENDERALLFORMATS = 0x0306
|
211
|
+
WM_DESTROYCLIPBOARD = 0x0307
|
212
|
+
WM_DRAWCLIPBOARD = 0x0308
|
213
|
+
WM_PAINTCLIPBOARD = 0x0309
|
214
|
+
WM_VSCROLLCLIPBOARD = 0x030A
|
215
|
+
WM_SIZECLIPBOARD = 0x030B
|
216
|
+
WM_ASKCBFORMATNAME = 0x030C
|
217
|
+
WM_CHANGECBCHAIN = 0x030D
|
218
|
+
WM_HSCROLLCLIPBOARD = 0x030E
|
219
|
+
WM_QUERYNEWPALETTE = 0x030F
|
220
|
+
WM_PALETTEISCHANGING = 0x0310
|
221
|
+
WM_PALETTECHANGED = 0x0311
|
222
|
+
WM_HOTKEY = 0x0312
|
223
|
+
WM_PRINT = 0x0317
|
224
|
+
WM_PRINTCLIENT = 0x0318
|
225
|
+
WM_APPCOMMAND = 0x0319
|
226
|
+
WM_THEMECHANGED = 0x031A
|
227
|
+
WM_HANDHELDFIRST = 0x0358
|
228
|
+
WM_HANDHELDLAST = 0x035F
|
229
|
+
WM_AFXFIRST = 0x0360
|
230
|
+
WM_AFXLAST = 0x037F
|
231
|
+
WM_PENWINFIRST = 0x0380
|
232
|
+
WM_PENWINLAST = 0x038F
|
233
|
+
# User-specific (non-reserved) messages above this one (WM_USER+1, etc...)
|
234
|
+
WM_USER = 0x0400
|
235
|
+
# App-specific (non-reserved) messages above this one (WM_App+1, etc...)
|
236
|
+
WM_APP = 0x8000
|
237
|
+
|
238
|
+
# Sys Commands:
|
239
|
+
|
240
|
+
#
|
241
|
+
SC_SIZE = 0xF000
|
242
|
+
SC_MOVE = 0xF010
|
243
|
+
SC_MINIMIZE = 0xF020
|
244
|
+
SC_MAXIMIZE = 0xF030
|
245
|
+
SC_NEXTWINDOW = 0xF040
|
246
|
+
SC_PREVWINDOW = 0xF050
|
14
247
|
# Sys Command Close
|
15
|
-
SC_CLOSE
|
248
|
+
SC_CLOSE = 0xF060
|
249
|
+
SC_VSCROLL = 0xF070
|
250
|
+
SC_HSCROLL = 0xF080
|
251
|
+
SC_MOUSEMENU = 0xF090
|
252
|
+
SC_KEYMENU = 0xF100
|
253
|
+
SC_ARRANGE = 0xF110
|
254
|
+
SC_RESTORE = 0xF120
|
255
|
+
SC_TASKLIST = 0xF130
|
256
|
+
SC_SCREENSAVE = 0xF140
|
257
|
+
SC_HOTKEY = 0xF150
|
258
|
+
SC_DEFAULT = 0xF160
|
259
|
+
SC_MONITORPOWER = 0xF170
|
260
|
+
SC_CONTEXTHELP = 0xF180
|
261
|
+
|
262
|
+
function :BroadcastSystemMessage, 'LPIIL', 'L'
|
263
|
+
function :DefWindowProc, 'LLLL', 'L'
|
264
|
+
function :DispatchMessage, 'P', 'L'
|
265
|
+
function :GetInputState, 'V', 'B'
|
266
|
+
function :GetMessage, 'PLII', 'B'
|
267
|
+
function :GetMessageExtraInfo, 'V', 'L'
|
268
|
+
function :GetMessagePos, 'V', 'L'
|
269
|
+
function :GetMessageTime, 'V', 'L'
|
270
|
+
function :GetQueueStatus, 'I', 'L'
|
271
|
+
function :InSendMessage, 'V', 'B'
|
272
|
+
function :InSendMessageEx, 'L', 'L'
|
273
|
+
function :PeekMessage, 'PLIII', 'B'
|
274
|
+
function :PostQuitMessage, 'I', 'V'
|
275
|
+
function :PostThreadMessage, 'LILL', 'B'
|
276
|
+
function :RegisterWindowMessage, 'P', 'I'
|
277
|
+
function :ReplyMessage, 'L', 'B'
|
278
|
+
function :SendMessageTimeout, 'LILLIIP', 'L'
|
279
|
+
function :SendNotifyMessage, 'LILLIIP', 'L'
|
280
|
+
function :SetMessageExtraInfo, 'L', 'L'
|
281
|
+
function :TranslateMessage, 'P', 'B'
|
282
|
+
function :WaitMessage, 'V', 'B'
|
283
|
+
|
284
|
+
##
|
285
|
+
# The SendAsyncProc function is an application-defined callback function used with the SendMessageCallback
|
286
|
+
# function. The system passes the message to the callback function after passing the message to the
|
287
|
+
# destination window procedure. SendAsyncProc is a placeholder for the application-defined function name.
|
288
|
+
#
|
289
|
+
# [*Syntax*] VOID SendAsyncProc( HWND hwnd, UINT uMsg, ULONG_PTR dwData, LRESULT lResult );
|
290
|
+
#
|
291
|
+
# hwnd:: [in] Handle to the window whose window procedure received the message. If SendMessageCallback
|
292
|
+
# function was called with its hwnd parameter set to HWND_BROADCAST, the system calls the
|
293
|
+
# SendAsyncProc function once for each top-level window.
|
294
|
+
# uMsg:: [in] Specifies the message.
|
295
|
+
# dwData:: [in] Specifies an application-defined value sent from the SendMessageCallback function.
|
296
|
+
# lResult:: [in] Specifies the result of the message processing. This value depends on the message.
|
297
|
+
#
|
298
|
+
# :call-seq:
|
299
|
+
# SendAsyncProc callback block: {|handle, msg, w_param, l_param| your code }
|
300
|
+
#
|
301
|
+
callback :SendAsyncProc, [:long, :uint, :ulong, :ulong, :long], :void
|
302
|
+
|
303
|
+
##
|
304
|
+
# The SendMessageCallback function sends the specified message to a window or windows. It calls the window
|
305
|
+
# procedure for the specified window and returns immediately. After the window procedure processes the message,
|
306
|
+
# the system calls the specified callback function, passing the result of the message processing and an
|
307
|
+
# application-defined value to the callback function.
|
308
|
+
#
|
309
|
+
# [*Syntax*] BOOL SendMessageCallback( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
|
310
|
+
# SENDASYNCPROC lpCallBack, ULONG_PTR dwData);
|
311
|
+
#
|
312
|
+
# hWnd:: [in] Handle to the window whose window procedure will receive the message. If this parameter is
|
313
|
+
# HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible
|
314
|
+
# unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
|
315
|
+
# Msg:: [in] Specifies the message to be sent.
|
316
|
+
# wParam:: [in] Specifies additional message-specific information.
|
317
|
+
# lParam:: [in] Specifies additional message-specific information.
|
318
|
+
# lpCallBack:: [in] Pointer to a callback function that the system calls after the window procedure processes
|
319
|
+
# the message. For more information, see SendAsyncProc. If hWnd is HWND_BROADCAST, the system calls the
|
320
|
+
# SendAsyncProc callback function once for each top-level window.
|
321
|
+
# dwData:: [in] Specifies an application-defined value to be sent to the callback function pointed to by
|
322
|
+
# the lpCallBack parameter.
|
323
|
+
# *Returns*:: Nonzero if the function succeeds, zero if it fails. For extended error info, call GetLastError.
|
324
|
+
# ---
|
325
|
+
# *Remarks*:
|
326
|
+
# - If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage,
|
327
|
+
# SendNotifyMessage, and SendMessageCallback), its message parameters cannot include pointers. Otherwise,
|
328
|
+
# the operation will fail. The functions will return before the receiving thread has had a chance
|
329
|
+
# to process the message and the sender will free the memory before it is used.
|
330
|
+
# - Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function
|
331
|
+
# to obtain a unique message for inter-application communication.
|
332
|
+
# - The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send
|
333
|
+
# messages (>= WM_USER) to another process, you must do custom marshalling.
|
334
|
+
# - The callback function is called only when the thread that called SendMessageCallback also calls GetMessage,
|
335
|
+
# PeekMessage, or WaitMessage.
|
336
|
+
#
|
337
|
+
function :SendMessageCallback, [:long, :uint, :uint, :long, :SendAsyncProc, :ulong], :bool
|
338
|
+
|
339
|
+
##
|
340
|
+
# The PostMessage function places (posts) a message in the message queue associated with the thread that
|
341
|
+
# created the specified window and returns without waiting for the thread to process the message.
|
342
|
+
# To post a message in the message queue associate with a thread, use the PostThreadMessage function.
|
343
|
+
#
|
344
|
+
# [*Syntax*] BOOL PostMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
345
|
+
#
|
346
|
+
# handle:: [in] Handle to the window whose window procedure will receive the message. If this parameter is
|
347
|
+
# HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or
|
348
|
+
# invisible unowned windows, overlapped windows, and pop-up windows; but the message is not posted to
|
349
|
+
# child windows. If it is NULL, the function behaves like a call to PostThreadMessage()
|
350
|
+
# with the dwThreadId parameter set to the identifier of the current thread.
|
351
|
+
# msg:: [in] Specifies the message to be posted.
|
352
|
+
# w_param:: [in] Specifies additional message-specific information.
|
353
|
+
# l_param:: [in] Specifies additional message-specific information.
|
354
|
+
#
|
355
|
+
# *Returns*:: Nonzero if the function succeeds, zero if it fails. For extended error info, call GetLastError.
|
356
|
+
# ---
|
357
|
+
# *Remarks*:
|
358
|
+
# - Microsoft Windows Vista and later. When a message is blocked by UIPI the last error, retrieved with
|
359
|
+
# GetLastError, is set to 5 (access denied). Messages in a message queue are retrieved by calls to the
|
360
|
+
# GetMessage or PeekMessage function.
|
361
|
+
# - Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function
|
362
|
+
# to obtain a unique message for inter-application communication.
|
363
|
+
# - The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other
|
364
|
+
# messages (those >= WM_USER) to another process, you must do custom marshalling.
|
365
|
+
# - If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage,
|
366
|
+
# SendNotifyMessage, and SendMessageCallback), its message parameters cannot include pointers. Otherwise,
|
367
|
+
# the operation will fail. The functions will return before the receiving thread has had a chance to
|
368
|
+
# process the message and the sender will free the memory before it is used. Use the PostQuitMessage
|
369
|
+
# instead of PostMessage to post WM_QUIT message.
|
370
|
+
#
|
371
|
+
#:call-seq:
|
372
|
+
# success = post_message(handle, msg, w_param, l_param)
|
373
|
+
#
|
374
|
+
function :PostMessage, [:ulong, :uint, :long, :uint], :bool
|
375
|
+
|
376
|
+
function :SendMessage, 'LLLP', 'L'
|
377
|
+
|
16
378
|
|
17
|
-
function 'PostMessage', 'LLLL', 'L'
|
18
|
-
function 'SendMessage', 'LLLP', 'L'
|
19
379
|
end
|
20
380
|
end
|
21
381
|
end
|
@@ -5,72 +5,18 @@ require 'win/gui/input'
|
|
5
5
|
|
6
6
|
module Win
|
7
7
|
module Gui
|
8
|
-
|
9
|
-
#
|
10
|
-
module Convenience
|
11
|
-
include Win::Gui::Window
|
12
|
-
include Win::Gui::Message
|
13
|
-
include Win::Gui::Input
|
14
|
-
|
15
|
-
# Internal constants:
|
16
|
-
|
17
|
-
# Key event delay
|
18
|
-
KEY_DELAY = 0.00001
|
19
|
-
# Wait delay
|
20
|
-
SLEEP_DELAY = 0.001
|
21
|
-
# Timeout waiting for Window to be closed
|
22
|
-
CLOSE_TIMEOUT = 1
|
23
|
-
|
24
|
-
# Convenience wrapper methods:
|
25
|
-
|
26
|
-
# Hides the window and activates another window
|
27
|
-
def hide_window(win_handle)
|
28
|
-
show_window(win_handle, SW_HIDE)
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# Tests if given window handle points to foreground (topmost) window
|
33
|
-
#
|
34
|
-
def foreground?(win_handle)
|
35
|
-
win_handle == foreground_window
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# Emulates combinations of (any amount of) keys pressed one after another (Ctrl+Alt+P) and then released
|
40
|
-
# *keys should be a sequence of a virtual-key codes. The codes must be a value in the range 1 to 254.
|
41
|
-
# For a complete list, see msdn:Virtual Key Codes.
|
42
|
-
def keystroke(*keys)
|
43
|
-
return if keys.empty?
|
44
|
-
keybd_event keys.first, 0, KEYEVENTF_KEYDOWN, 0
|
45
|
-
sleep KEY_DELAY
|
46
|
-
keystroke *keys[1..-1]
|
47
|
-
sleep KEY_DELAY
|
48
|
-
keybd_event keys.first, 0, KEYEVENTF_KEYUP, 0
|
49
|
-
end
|
50
|
-
|
51
|
-
# types text message into window holding the focus
|
52
|
-
def type_in(message)
|
53
|
-
message.scan(/./m) do |char|
|
54
|
-
keystroke(*char.to_vkeys)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# finds top-level dialog window by title and yields found dialog window to block if given
|
59
|
-
def dialog(title, seconds=3)
|
60
|
-
d = begin
|
61
|
-
win = WrapWindow.top_level(title, seconds)
|
62
|
-
yield(win) ? win : nil
|
63
|
-
rescue TimeoutError
|
64
|
-
end
|
65
|
-
d.wait_for_close if d
|
66
|
-
return d
|
67
|
-
end
|
68
|
-
|
8
|
+
module Window
|
69
9
|
# This class is a thin wrapper around window handle
|
70
|
-
class
|
10
|
+
class Window
|
11
|
+
# Wait delay
|
12
|
+
SLEEP_DELAY = 0.001
|
13
|
+
# Timeout waiting for Window to be closed
|
14
|
+
CLOSE_TIMEOUT = 1
|
15
|
+
|
71
16
|
include Win::Gui::Window
|
72
17
|
extend Win::Gui::Window
|
73
18
|
include Win::Gui::Message
|
19
|
+
include Win::Gui::Input
|
74
20
|
|
75
21
|
attr_reader :handle
|
76
22
|
|
@@ -79,7 +25,7 @@ module Win
|
|
79
25
|
@handle = timeout(seconds) do
|
80
26
|
sleep SLEEP_DELAY while (h = find_window nil, title) == nil; h
|
81
27
|
end
|
82
|
-
|
28
|
+
Window.new @handle
|
83
29
|
end
|
84
30
|
|
85
31
|
def initialize(handle)
|
@@ -101,11 +47,11 @@ module Win
|
|
101
47
|
nil
|
102
48
|
end
|
103
49
|
raise "Control '#{id}' not found" unless result
|
104
|
-
|
50
|
+
Window.new result
|
105
51
|
end
|
106
52
|
|
107
53
|
def children
|
108
|
-
enum_child_windows(@handle).map{|child_handle|
|
54
|
+
enum_child_windows(@handle).map{|child_handle| Window.new child_handle}
|
109
55
|
end
|
110
56
|
|
111
57
|
# emulate click of the control identified by id
|
@@ -138,5 +84,4 @@ module Win
|
|
138
84
|
end
|
139
85
|
end
|
140
86
|
end
|
141
|
-
end
|
142
|
-
|
87
|
+
end
|