win 0.1.18 → 0.1.22
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/VERSION +1 -1
- data/lib/win/dde.rb +139 -3
- data/lib/win/error.rb +14 -14
- data/lib/win/gui/dialog.rb +1 -0
- data/lib/win/gui/input.rb +1 -27
- data/lib/win/gui/message.rb +412 -72
- data/lib/win/gui/window.rb +5 -5
- data/spec/win/dde_spec.rb +187 -57
- data/spec/win/gui/message_spec.rb +195 -8
- data/win.gemspec +2 -2
- metadata +2 -2
data/lib/win/gui/message.rb
CHANGED
@@ -2,13 +2,49 @@ require 'win/library'
|
|
2
2
|
|
3
3
|
module Win
|
4
4
|
module GUI
|
5
|
-
#
|
5
|
+
# Contains constants and Win32API functions related to Windows messaging
|
6
6
|
#
|
7
|
+
# Below is a table of system-defined message prefixes:
|
8
|
+
#
|
9
|
+
# *Prefix*:: *Message* *category*
|
10
|
+
# ABM:: Application desktop toolbar
|
11
|
+
# BM:: Button control
|
12
|
+
# CB:: Combo box control
|
13
|
+
# CBEM:: Extended combo box control
|
14
|
+
# CDM:: Common dialog box
|
15
|
+
# DBT:: Device
|
16
|
+
# DL:: Drag list box
|
17
|
+
# DM:: Default push button control
|
18
|
+
# DTM:: Date and time picker control
|
19
|
+
# EM:: Edit control
|
20
|
+
# HDM:: Header control
|
21
|
+
# HKM:: Hot key control
|
22
|
+
# IPM:: IP address control
|
23
|
+
# LB:: List box control
|
24
|
+
# LVM:: List view control
|
25
|
+
# MCM:: Month calendar control
|
26
|
+
# PBM:: Progress bar
|
27
|
+
# PGM:: Pager control
|
28
|
+
# PSM:: Property sheet
|
29
|
+
# RB:: Rebar control
|
30
|
+
# SB:: Status bar window
|
31
|
+
# SBM:: Scroll bar control
|
32
|
+
# STM:: Static control
|
33
|
+
# TB:: Toolbar
|
34
|
+
# TBM:: Trackbar
|
35
|
+
# TCM:: Tab control
|
36
|
+
# TTM:: Tooltip control
|
37
|
+
# TVM:: Tree-view control
|
38
|
+
# UDM:: Up-down control
|
39
|
+
# WM:: General window
|
7
40
|
module Message
|
8
41
|
include Win::Library
|
9
42
|
|
10
|
-
#
|
43
|
+
# General window messages cover a wide range of information and requests, including messages for mouse and
|
44
|
+
# keyboard input, menu and dialog box input, window creation and management, and Dynamic Data Exchange (DDE).
|
45
|
+
# General window messages WM/WA:
|
11
46
|
|
47
|
+
#
|
12
48
|
WM_NULL = 0x0000
|
13
49
|
WA_INACTIVE = 0x0000
|
14
50
|
WM_CREATE = 0x0001
|
@@ -235,7 +271,7 @@ module Win
|
|
235
271
|
# App-specific (non-reserved) messages above this one (WM_App+1, etc...)
|
236
272
|
WM_APP = 0x8000
|
237
273
|
|
238
|
-
# Sys Commands:
|
274
|
+
# Sys Commands (wParam to use with WM_SYSCOMMAND message):
|
239
275
|
|
240
276
|
#
|
241
277
|
SC_SIZE = 0xF000
|
@@ -259,68 +295,45 @@ module Win
|
|
259
295
|
SC_MONITORPOWER = 0xF170
|
260
296
|
SC_CONTEXTHELP = 0xF180
|
261
297
|
|
262
|
-
|
263
|
-
function :BroadcastSystemMessage, 'LPIIL', 'L'
|
264
|
-
|
265
|
-
##
|
266
|
-
function :DefWindowProc, 'LLLL', 'L'
|
267
|
-
|
268
|
-
##
|
269
|
-
function :DispatchMessage, 'P', 'L'
|
270
|
-
|
271
|
-
##
|
272
|
-
function :GetInputState, 'V', 'B'
|
273
|
-
|
274
|
-
##
|
275
|
-
function :GetMessage, 'PLII', 'B'
|
276
|
-
|
277
|
-
##
|
278
|
-
function :GetMessageExtraInfo, 'V', 'L'
|
279
|
-
|
280
|
-
##
|
281
|
-
function :GetMessagePos, 'V', 'L'
|
282
|
-
|
283
|
-
##
|
284
|
-
function :GetMessageTime, 'V', 'L'
|
285
|
-
|
286
|
-
##
|
287
|
-
function :GetQueueStatus, 'I', 'L'
|
288
|
-
|
289
|
-
##
|
290
|
-
function :InSendMessage, 'V', 'B'
|
291
|
-
|
292
|
-
##
|
293
|
-
function :InSendMessageEx, 'L', 'L'
|
294
|
-
|
295
|
-
##
|
296
|
-
function :PeekMessage, 'PLIII', 'B'
|
297
|
-
|
298
|
-
##
|
299
|
-
function :PostQuitMessage, 'I', 'V'
|
300
|
-
|
301
|
-
##
|
302
|
-
function :PostThreadMessage, 'LILL', 'B'
|
303
|
-
|
304
|
-
##
|
305
|
-
function :RegisterWindowMessage, 'P', 'I'
|
306
|
-
|
307
|
-
##
|
308
|
-
function :ReplyMessage, 'L', 'B'
|
309
|
-
|
310
|
-
##
|
311
|
-
function :SendMessageTimeout, 'LILLIIP', 'L'
|
312
|
-
|
313
|
-
##
|
314
|
-
function :SendNotifyMessage, 'LILLIIP', 'L'
|
315
|
-
|
316
|
-
##
|
317
|
-
function :SetMessageExtraInfo, 'L', 'L'
|
298
|
+
# Queue status flags:
|
318
299
|
|
319
|
-
|
320
|
-
|
300
|
+
#
|
301
|
+
QS_KEY = 0x0001
|
302
|
+
QS_MOUSEMOVE = 0x0002
|
303
|
+
QS_MOUSEBUTTON = 0x0004
|
304
|
+
QS_MOUSE = (QS_MOUSEMOVE | QS_MOUSEBUTTON)
|
305
|
+
QS_POSTMESSAGE = 0x0008
|
306
|
+
QS_TIMER = 0x0010
|
307
|
+
QS_PAINT = 0x0020
|
308
|
+
QS_SENDMESSAGE = 0x0040
|
309
|
+
QS_HOTKEY = 0x0080
|
310
|
+
QS_ALLPOSTMESSAGE= 0x0100
|
311
|
+
QS_RAWINPUT = 0x0400
|
312
|
+
QS_INPUT = (QS_MOUSE | QS_KEY | QS_RAWINPUT)
|
313
|
+
QS_ALLEVENTS = (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY)
|
314
|
+
QS_ALLINPUT = (QS_ALLEVENTS | QS_SENDMESSAGE)
|
315
|
+
QS_SMRESULT = 0x8000
|
316
|
+
|
317
|
+
# PeekMessage flags:
|
318
|
+
|
319
|
+
# Messages are not removed from the queue after processing by PeekMessage (default)
|
320
|
+
PM_NOREMOVE = 0x0000
|
321
|
+
# Messages are removed from the queue after processing by PeekMessage.
|
322
|
+
PM_REMOVE = 0x0001
|
323
|
+
# You can optionally combine the value PM_NOYIELD with either PM_NOREMOVE or PM_REMOVE. This flag
|
324
|
+
# prevents the system from releasing any thread that is waiting for the caller to go idle (see WaitForInputIdle).
|
325
|
+
PM_NOYIELD = 0x0002
|
326
|
+
# By default, all message types are processed. To specify that only certain
|
327
|
+
# message should be processed, specify one or more of the following values.
|
328
|
+
# PM_QS_INPUT - Windows 98/Me, Windows 2000/XP: Process mouse and keyboard messages.
|
329
|
+
PM_QS_INPUT = (QS_INPUT << 16)
|
330
|
+
# PM_QS_POSTMESSAGE - Win 98/Me/2000/XP: Process all posted messages, including timers and hotkeys.
|
331
|
+
PM_QS_POSTMESSAGE= ((QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER) << 16)
|
332
|
+
# PM_QS_PAINT - Windows 98/Me, Windows 2000/XP: Process paint messages.
|
333
|
+
PM_QS_PAINT = (QS_PAINT << 16)
|
334
|
+
# PM_QS_SENDMESSAGE - Windows 98/Me, Windows 2000/XP: Process all sent messages.
|
335
|
+
PM_QS_SENDMESSAGE= (QS_SENDMESSAGE << 16)
|
321
336
|
|
322
|
-
##
|
323
|
-
function :WaitMessage, 'V', 'B'
|
324
337
|
|
325
338
|
##
|
326
339
|
# The SendAsyncProc function is an application-defined callback function used with the SendMessageCallback
|
@@ -337,9 +350,9 @@ module Win
|
|
337
350
|
# lResult:: [in] Specifies the result of the message processing. This value depends on the message.
|
338
351
|
#
|
339
352
|
# :call-seq:
|
340
|
-
# SendAsyncProc callback block: {|handle, msg, data, l_result| your
|
353
|
+
# SendAsyncProc callback block: {|handle, msg, data, l_result| your callback code }
|
341
354
|
#
|
342
|
-
callback :SendAsyncProc, [:
|
355
|
+
callback :SendAsyncProc, [:HWND, :uint, :ulong, :long], :void
|
343
356
|
|
344
357
|
##
|
345
358
|
# The SendMessageCallback function sends the specified message to a window or windows. It calls the window
|
@@ -351,13 +364,13 @@ module Win
|
|
351
364
|
# SENDASYNCPROC lpCallBack, ULONG_PTR dwData);
|
352
365
|
#
|
353
366
|
# hWnd:: [in] Handle to the window whose window procedure will receive the message. If this parameter is
|
354
|
-
# HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or
|
355
|
-
# unowned
|
367
|
+
# HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or
|
368
|
+
# invisible, unowned, overlapped and pop-up windows; but the message is not sent to child windows.
|
356
369
|
# Msg:: [in] Specifies the message to be sent.
|
357
370
|
# wParam:: [in] Specifies additional message-specific information.
|
358
371
|
# lParam:: [in] Specifies additional message-specific information.
|
359
372
|
# lpCallBack:: [in] Pointer to a callback function that the system calls after the window procedure processes
|
360
|
-
# the message. For more information, see SendAsyncProc. If hWnd is HWND_BROADCAST, the system calls
|
373
|
+
# the message. For more information, see SendAsyncProc. If hWnd is HWND_BROADCAST, the system calls
|
361
374
|
# SendAsyncProc callback function once for each top-level window.
|
362
375
|
# dwData:: [in] Specifies an application-defined value to be sent to the callback function pointed to by
|
363
376
|
# the lpCallBack parameter.
|
@@ -376,10 +389,13 @@ module Win
|
|
376
389
|
# PeekMessage, or WaitMessage.
|
377
390
|
#
|
378
391
|
# :call-seq:
|
379
|
-
# success = send_message_callback(handle, msg, w_param, l_param, data)
|
392
|
+
# success = send_message_callback(handle, msg, w_param, l_param, [data=0])
|
380
393
|
# {|handle, msg, data, l_result| callback code }
|
381
394
|
#
|
382
|
-
function :SendMessageCallback, [:
|
395
|
+
function :SendMessageCallback, [:HWND, :uint, :uint, :pointer, :SendAsyncProc, :ulong], :int8, boolean: true,
|
396
|
+
&->(api, handle, msg, w_param, l_param, data=0, &block){
|
397
|
+
api.call(handle, msg, w_param, l_param, block, data)}
|
398
|
+
|
383
399
|
|
384
400
|
##
|
385
401
|
# The PostMessage function places (posts) a message in the message queue associated with the thread that
|
@@ -416,7 +432,7 @@ module Win
|
|
416
432
|
#:call-seq:
|
417
433
|
# success = post_message(handle, msg, w_param, l_param)
|
418
434
|
#
|
419
|
-
function :PostMessage, [:ulong, :uint, :
|
435
|
+
function :PostMessage, [:ulong, :uint, :uint, :pointer], :int, boolean: true
|
420
436
|
|
421
437
|
##
|
422
438
|
# The SendMessage function sends the specified message to a window or windows. It calls the window procedure for
|
@@ -459,8 +475,332 @@ module Win
|
|
459
475
|
#:call-seq:
|
460
476
|
# send_message(handle, msg, w_param, l_param)
|
461
477
|
#
|
462
|
-
function :SendMessage, [:ulong, :uint, :
|
478
|
+
function :SendMessage, [:ulong, :uint, :uint, :pointer], :int # LPARAM different from PostMessage!
|
479
|
+
|
480
|
+
# The MSG structure contains message information from a thread's message queue.
|
481
|
+
#
|
482
|
+
# typedef struct {
|
483
|
+
# HWND hwnd;
|
484
|
+
# UINT message;
|
485
|
+
# WPARAM wParam;
|
486
|
+
# LPARAM lParam;
|
487
|
+
# DWORD time;
|
488
|
+
# POINT pt;
|
489
|
+
# } MSG, *PMSG;
|
490
|
+
#
|
491
|
+
# hwnd:: Handle to the window whose window procedure receives the message. NULL when the message is a thread message.
|
492
|
+
# message:: Message identifier. Applications can only use the low word; the high word is reserved by the system.
|
493
|
+
# wParam:: Additional info about the message. Exact meaning depends on the value of the message member.
|
494
|
+
# lParam:: Additional info about the message. Exact meaning depends on the value of the message member.
|
495
|
+
# time:: Specifies the time at which the message was posted.
|
496
|
+
# pt:: POINT structure - the cursor position, in screen coordinates, when the message was posted.
|
497
|
+
# (in my definition, it is changed to two longs: x, y - has the same effect, just avoid nested structs)
|
498
|
+
class Msg < FFI::Struct
|
499
|
+
layout :hwnd, :ulong,
|
500
|
+
:message, :uint,
|
501
|
+
:w_param, :long,
|
502
|
+
:l_param, :pointer,
|
503
|
+
:time, :uint32,
|
504
|
+
:x, :long,
|
505
|
+
:y, :long
|
506
|
+
end
|
507
|
+
|
508
|
+
##
|
509
|
+
# The GetMessage function retrieves a message from the calling thread's message queue. The function
|
510
|
+
# dispatches incoming sent messages until a posted message is available for retrieval.
|
511
|
+
# Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning.
|
512
|
+
#
|
513
|
+
# [*Syntax*] BOOL GetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax );
|
514
|
+
#
|
515
|
+
# lpMsg:: [out] Pointer to an MSG structure that receives message information from the thread's message
|
516
|
+
# queue.
|
517
|
+
# hWnd:: [in] Handle to the window whose messages are to be retrieved. The window must belong to the current
|
518
|
+
# thread. If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the current
|
519
|
+
# thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG
|
520
|
+
# structure). Therefore if hWnd is NULL, both window messages and thread messages are processed.
|
521
|
+
# If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd
|
522
|
+
# value is NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or
|
523
|
+
# PostThreadMessage.
|
524
|
+
# wMsgFilterMin:: [in] Specifies the integer value of the lowest message value to be retrieved. Use WM_KEYFIRST
|
525
|
+
# to specify the first keyboard message or WM_MOUSEFIRST to specify the first mouse message.
|
526
|
+
# Windows XP: Use WM_INPUT here and in wMsgFilterMax to specify only the WM_INPUT messages.
|
527
|
+
# If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages
|
528
|
+
# (that is, no range filtering is performed).
|
529
|
+
# wMsgFilterMax:: [in] Specifies the integer value of the highest message value to be retrieved. Use
|
530
|
+
# WM_KEYLAST to specify the last keyboard message or WM_MOUSELAST to specify the last
|
531
|
+
# mouse message.
|
532
|
+
#
|
533
|
+
# *Returns*:: If the function retrieves a message other than WM_QUIT, the return value is nonzero.
|
534
|
+
# If the function retrieves the WM_QUIT message, the return value is zero.
|
535
|
+
# If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid
|
536
|
+
# window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError.
|
537
|
+
# *Warning*
|
538
|
+
# Because the return value can be nonzero, zero, or -1, avoid code like this:
|
539
|
+
# while (GetMessage( lpMsg, hWnd, 0, 0)) ...
|
540
|
+
# The possibility of a -1 return value means that such code can lead to fatal application errors.
|
541
|
+
# Instead, use code like this:
|
542
|
+
# while( (bRet = GetMessage( msg, hWnd, 0, 0 )) != 0)
|
543
|
+
# if (bRet == -1)
|
544
|
+
# // handle the error and possibly exit
|
545
|
+
# else
|
546
|
+
# TranslateMessage(msg);
|
547
|
+
# DispatchMessage(msg);
|
548
|
+
# end
|
549
|
+
# end
|
550
|
+
# ---
|
551
|
+
# *Remarks*:
|
552
|
+
# An application typically uses the return value to determine whether to end the main message loop and
|
553
|
+
# exit the program.
|
554
|
+
#
|
555
|
+
# The GetMessage function retrieves messages associated with the window identified by the hWnd parameter
|
556
|
+
# or any of its children, as specified by the IsChild function, and within the range of message values
|
557
|
+
# given by the wMsgFilterMin and wMsgFilterMax parameters. Note that an application can only use the low
|
558
|
+
# word in the wMsgFilterMin and wMsgFilterMax parameters; the high word is reserved for the system.
|
559
|
+
# Note that GetMessage always retrieves WM_QUIT messages, no matter which values you specify for
|
560
|
+
# wMsgFilterMin and wMsgFilterMax.
|
561
|
+
#
|
562
|
+
# During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows
|
563
|
+
# owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, or
|
564
|
+
# SendNotifyMessage function. Then the first queued message that matches the specified filter is
|
565
|
+
# retrieved. The system may also process internal events. If no filter is specified, messages are
|
566
|
+
# processed in the following order:
|
567
|
+
# 1. Sent messages
|
568
|
+
# 2. Posted messages
|
569
|
+
# 3. Input (hardware) messages and system internal events
|
570
|
+
# 4. Sent messages (again)
|
571
|
+
# 5. WM_PAINT messages
|
572
|
+
# 6. WM_TIMER messages
|
573
|
+
#
|
574
|
+
# To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters.
|
575
|
+
# GetMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until
|
576
|
+
# processed.
|
577
|
+
#
|
578
|
+
# Windows XP: If a top-level window stops responding to messages for more than several seconds, the
|
579
|
+
# system considers the window to be not responding and replaces it with a ghost window that has the same
|
580
|
+
# z-order, location, size, and visual attributes. This allows the user to move it, resize it, or even
|
581
|
+
# close the application. However, these are the only actions available because the application is
|
582
|
+
# actually not responding. When in the debugger mode, the system does not generate a ghost window.
|
583
|
+
# ---
|
584
|
+
# <b>Enhanced (snake_case) API: makes all args optional, returns: *false* if WM_QUIT was posted,
|
585
|
+
# *nil* if error was encountered, and retrieved Msg (FFI structure) in all other cases </b>
|
586
|
+
#
|
587
|
+
# :call-seq:
|
588
|
+
# msg = get_message([msg], [handle=0], [msg_filter_min=0], [msg_filter_max=0])
|
589
|
+
#
|
590
|
+
function :GetMessage, [:pointer, :HWND, :uint, :uint], :int8,
|
591
|
+
&->(api, msg=Msg.new, handle=0, msg_filter_min=0, msg_filter_max=0){
|
592
|
+
case api.call(msg, handle, msg_filter_min, msg_filter_max)
|
593
|
+
when 0
|
594
|
+
false
|
595
|
+
when -1
|
596
|
+
nil
|
597
|
+
else
|
598
|
+
msg
|
599
|
+
end }
|
600
|
+
# weird lambda literal instead of block is needed because RDoc goes crazy if block is attached to meta-definition
|
601
|
+
|
602
|
+
##
|
603
|
+
# The PeekMessage function dispatches incoming sent messages, checks the thread message queue for a
|
604
|
+
# posted message, and retrieves the message (if any exist).
|
605
|
+
#
|
606
|
+
# [*Syntax*] BOOL PeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax,
|
607
|
+
# UINT wRemoveMsg );
|
608
|
+
#
|
609
|
+
# lpMsg:: [out] Pointer to an MSG structure that receives message information.
|
610
|
+
# hWnd:: [in] Handle to the window whose messages are to be retrieved. The window must belong to the current
|
611
|
+
# thread. If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current
|
612
|
+
# thread, and any messages on the current thread's message queue whose hwnd value is NULL (see MSG).
|
613
|
+
# Therefore if hWnd is NULL, both window messages and thread messages are processed.
|
614
|
+
# If hWnd is -1, PeekMessage retrieves only messages on the current thread's message queue whose hwnd
|
615
|
+
# value is NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or
|
616
|
+
# PostThreadMessage.
|
617
|
+
# wMsgFilterMin:: [in] Specifies the value of the first message in the range of messages to be examined.
|
618
|
+
# Use WM_KEYFIRST to specify the first keyboard message or WM_MOUSEFIRST to specify the
|
619
|
+
# first mouse message. If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all
|
620
|
+
# available messages (that is, no range filtering is performed).
|
621
|
+
# wMsgFilterMax:: [in] Specifies the value of the last message in the range of messages to be examined.
|
622
|
+
# Use WM_KEYLAST to specify the last keyboard message or WM_MOUSELAST to specify the
|
623
|
+
# last mouse message.
|
624
|
+
# wRemoveMsg:: [in] Specifies how messages are handled. This parameter can be one of the following values.
|
625
|
+
# - PM_NOREMOVE - Messages are not removed from the queue after processing by PeekMessage.
|
626
|
+
# - PM_REMOVE - Messages are removed from the queue after processing by PeekMessage.
|
627
|
+
# You can optionally combine the value PM_NOYIELD with either PM_NOREMOVE or PM_REMOVE. This flag
|
628
|
+
# prevents the system from releasing any thread that is waiting for the caller to go idle (see
|
629
|
+
# WaitForInputIdle). By default, all message types are processed. To specify that only certain
|
630
|
+
# message should be processed, specify one or more of the following values.
|
631
|
+
# - PM_QS_INPUT - Windows 98/Me, Windows 2000/XP: Process mouse and keyboard messages.
|
632
|
+
# - PM_QS_PAINT - Windows 98/Me, Windows 2000/XP: Process paint messages.
|
633
|
+
# - PM_QS_POSTMESSAGE - Win 98/Me/2000/XP: Process all posted messages, including timers and hotkeys.
|
634
|
+
# - PM_QS_SENDMESSAGE - Windows 98/Me, Windows 2000/XP: Process all sent messages.
|
635
|
+
#
|
636
|
+
# *Returns*:: If a message is available, returns nonzero. If no messages are available, the return value is zero.
|
637
|
+
# ---
|
638
|
+
# *Remarks*:
|
639
|
+
# PeekMessage retrieves messages associated with the window identified by the hWnd parameter or any of
|
640
|
+
# its children as specified by the IsChild function, and within the range of message values given by the
|
641
|
+
# wMsgFilterMin and wMsgFilterMax parameters. Note that an application can only use the low word in the
|
642
|
+
# wMsgFilterMin and wMsgFilterMax parameters; the high word is reserved for the system.
|
643
|
+
#
|
644
|
+
# Note that PeekMessage always retrieves WM_QUIT messages, no matter which values you specify for
|
645
|
+
# wMsgFilterMin and wMsgFilterMax.
|
646
|
+
#
|
647
|
+
# During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows
|
648
|
+
# owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, or
|
649
|
+
# SendNotifyMessage function. Then the first queued message that matches the specified filter is
|
650
|
+
# retrieved. The system may also process internal events. If no filter is specified, messages are
|
651
|
+
# processed in the following order:
|
652
|
+
# 1. Sent messages
|
653
|
+
# 2. Posted messages
|
654
|
+
# 3. Input (hardware) messages and system internal events
|
655
|
+
# 4. Sent messages (again)
|
656
|
+
# 5. WM_PAINT messages
|
657
|
+
# 6. WM_TIMER messages
|
658
|
+
#
|
659
|
+
# To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters.
|
660
|
+
#
|
661
|
+
# The PeekMessage function normally does not remove WM_PAINT messages from the queue. WM_PAINT messages
|
662
|
+
# remain in the queue until they are processed. However, if a WM_PAINT message has a NULL update region,
|
663
|
+
# PeekMessage does remove it from the queue.
|
664
|
+
#
|
665
|
+
# Windows XP: If a top-level window stops responding to messages for more than several seconds, the
|
666
|
+
# system considers the window to be not responding and replaces it with a ghost window that has the same
|
667
|
+
# z-order, location, size, and visual attributes. This allows the user to move it, resize it, or even
|
668
|
+
# close the application. However, these are the only actions available because the application is
|
669
|
+
# actually not responding. When an application is being debugged, the system does not generate a ghost
|
670
|
+
# window.
|
671
|
+
# ---
|
672
|
+
# <b>Enhanced (snake_case) API: makes all args optional, returns *nil* if no message in queue,
|
673
|
+
# returns retrieved Msg (FFI structure) if there is message in queue</b>
|
674
|
+
#
|
675
|
+
# :call-seq:
|
676
|
+
# msg = peek_message([msg], [handle], [msg_filter_min], [msg_filter_max], [remove_msg])
|
677
|
+
#
|
678
|
+
function :PeekMessage, [:pointer, :HWND, :uint, :uint, :uint], :int8,
|
679
|
+
&->(api, msg=Msg.new, handle=0, msg_filter_min=0, msg_filter_max=0, remove_msg=PM_NOREMOVE){
|
680
|
+
res = api.call(msg, handle, msg_filter_min, msg_filter_max, remove_msg)
|
681
|
+
res == 0 ? nil : msg }
|
682
|
+
|
683
|
+
##
|
684
|
+
# The TranslateMessage function translates virtual-key messages into character messages. The character
|
685
|
+
# messages are posted to the calling thread's message queue, to be read the next time the thread calls
|
686
|
+
# the GetMessage or PeekMessage function.
|
687
|
+
#
|
688
|
+
# [*Syntax*] BOOL TranslateMessage( const MSG *lpMsg );
|
689
|
+
#
|
690
|
+
# lpMsg:: [in] Pointer to an MSG structure that contains message information retrieved from the calling
|
691
|
+
# thread's message queue by using the GetMessage or PeekMessage function.
|
692
|
+
#
|
693
|
+
# *Returns*:: If the message is translated (that is, a character message is posted to the thread's
|
694
|
+
# message queue), the return value is nonzero.
|
695
|
+
# If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is
|
696
|
+
# nonzero, regardless of the translation.
|
697
|
+
# If the message is not translated (that is, a character message is not posted to the thread's
|
698
|
+
# message queue), the return value is zero.
|
699
|
+
# ---
|
700
|
+
# *Remarks*:
|
701
|
+
# The TranslateMessage function does not modify the message pointed to by the lpMsg parameter.
|
702
|
+
#
|
703
|
+
# WM_KEYDOWN and WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. WM_SYSKEYDOWN and
|
704
|
+
# WM_SYSKEYUP combinations produce a WM_SYSCHAR or WM_SYSDEADCHAR message.
|
705
|
+
#
|
706
|
+
# TranslateMessage produces WM_CHAR messages only for keys that are mapped to ASCII characters by the
|
707
|
+
# keyboard driver.
|
708
|
+
#
|
709
|
+
# If applications process virtual-key messages for some other purpose, they should not call
|
710
|
+
# TranslateMessage. For instance, an application should not call TranslateMessage if the
|
711
|
+
# TranslateAccelerator function returns a nonzero value. Note that the application is responsible for
|
712
|
+
# retrieving and dispatching input messages to the dialog box. Most applications use the main message
|
713
|
+
# loop for this. However, to permit the user to move to and to select controls by using the keyboard,
|
714
|
+
# the application must call IsDialogMessage. For more information, see Dialog Box Keyboard Interface.
|
715
|
+
# ---
|
716
|
+
# <b>Enhanced (snake_case) API: returns true/false instead of nonzero/zero</b>
|
717
|
+
#
|
718
|
+
# :call-seq:
|
719
|
+
# success = translate_message(msg)
|
720
|
+
#
|
721
|
+
function :TranslateMessage, [:pointer], :int8, boolean: true
|
722
|
+
|
723
|
+
##
|
724
|
+
# The DispatchMessage function dispatches a message to a window procedure. It is typically used to
|
725
|
+
# dispatch a message retrieved by the GetMessage function.
|
726
|
+
#
|
727
|
+
# [*Syntax*] LRESULT DispatchMessage( const MSG *lpmsg );
|
728
|
+
#
|
729
|
+
# lpmsg:: [in] Pointer to an MSG structure that contains the message.
|
730
|
+
#
|
731
|
+
# *Returns*:: The return value specifies the value returned by the window procedure. Although its
|
732
|
+
# meaning depends on the message being dispatched, the return value generally is ignored.
|
733
|
+
# ---
|
734
|
+
# *Remarks*:
|
735
|
+
# The MSG structure must contain valid message values. If the lpmsg parameter points to a WM_TIMER
|
736
|
+
# message and the lParam parameter of the WM_TIMER message is not NULL, lParam points to a function that
|
737
|
+
# is called instead of the window procedure.
|
738
|
+
#
|
739
|
+
# Note that the application is responsible for retrieving and dispatching input messages to the dialog
|
740
|
+
# box. Most applications use the main message loop for this. However, to permit the user to move to and
|
741
|
+
# to select controls by using the keyboard, the application must call IsDialogMessage. For more
|
742
|
+
# information, see Dialog Box Keyboard Interface.
|
743
|
+
# ---
|
744
|
+
# <b>Enhanced (snake_case) API: </b>
|
745
|
+
#
|
746
|
+
# :call-seq:
|
747
|
+
# dispatch_message(msg)
|
748
|
+
#
|
749
|
+
function :DispatchMessage, [:pointer], :long
|
750
|
+
|
751
|
+
##
|
752
|
+
function :BroadcastSystemMessage, 'LPIIL', 'L'
|
753
|
+
|
754
|
+
##
|
755
|
+
try_function :BroadcastSystemMessageEx, 'LPILLP', 'L' # Windows XP or later
|
756
|
+
|
757
|
+
##
|
758
|
+
function :DefWindowProc, 'LLLL', 'L'
|
759
|
+
|
760
|
+
##
|
761
|
+
function :GetInputState, 'V', 'B'
|
762
|
+
|
763
|
+
##
|
764
|
+
function :GetMessageExtraInfo, 'V', 'L'
|
765
|
+
|
766
|
+
##
|
767
|
+
function :GetMessagePos, 'V', 'L'
|
768
|
+
|
769
|
+
##
|
770
|
+
function :GetMessageTime, 'V', 'L'
|
463
771
|
|
772
|
+
##
|
773
|
+
function :GetQueueStatus, 'I', 'L'
|
774
|
+
|
775
|
+
##
|
776
|
+
function :InSendMessage, 'V', 'B'
|
777
|
+
|
778
|
+
##
|
779
|
+
function :InSendMessageEx, 'L', 'L'
|
780
|
+
|
781
|
+
##
|
782
|
+
function :PostQuitMessage, 'I', 'V'
|
783
|
+
|
784
|
+
##
|
785
|
+
function :PostThreadMessage, 'LILL', 'B'
|
786
|
+
|
787
|
+
##
|
788
|
+
function :RegisterWindowMessage, 'P', 'I'
|
789
|
+
|
790
|
+
##
|
791
|
+
function :ReplyMessage, 'L', 'B'
|
792
|
+
|
793
|
+
##
|
794
|
+
function :SendMessageTimeout, 'LILLIIP', 'L'
|
795
|
+
|
796
|
+
##
|
797
|
+
function :SendNotifyMessage, 'LILLIIP', 'L'
|
798
|
+
|
799
|
+
##
|
800
|
+
function :SetMessageExtraInfo, 'L', 'L'
|
801
|
+
|
802
|
+
##
|
803
|
+
function :WaitMessage, 'V', 'B'
|
464
804
|
end
|
465
805
|
end
|
466
806
|
end
|
data/lib/win/gui/window.rb
CHANGED
@@ -642,14 +642,14 @@ module Win
|
|
642
642
|
##
|
643
643
|
# Hides the window and activates another window
|
644
644
|
#
|
645
|
-
def hide_window(win_handle)
|
645
|
+
def hide_window( win_handle )
|
646
646
|
show_window(win_handle, SW_HIDE)
|
647
647
|
end
|
648
648
|
|
649
649
|
##
|
650
650
|
# Tests if given window handle points to foreground (topmost) window
|
651
651
|
#
|
652
|
-
def foreground?(win_handle)
|
652
|
+
def foreground?( win_handle )
|
653
653
|
win_handle == foreground_window
|
654
654
|
end
|
655
655
|
|
@@ -657,9 +657,9 @@ module Win
|
|
657
657
|
# Shuts down the window <b>created by different thread</b> by posting WM_SYSCOMMAND, SC_CLOSE message to it.
|
658
658
|
# This closely emulates user clicking on X button of the target window. As it would be expected, this
|
659
659
|
# actually gives the target window chance to close gracefully (it may ask user to save data and stuff).
|
660
|
-
# I have not
|
660
|
+
# I have not found so far how to REALLY destroy window in different thread without it asking user anything.
|
661
661
|
#
|
662
|
-
def shut_window( win_handle)
|
662
|
+
def shut_window( win_handle )
|
663
663
|
post_message(win_handle, Win::GUI::Message::WM_SYSCOMMAND, Win::GUI::Message::SC_CLOSE, nil)
|
664
664
|
end
|
665
665
|
|
@@ -668,7 +668,7 @@ module Win
|
|
668
668
|
# ---
|
669
669
|
# *Remarks*: It is *different* from GetWindowText that returns only window title
|
670
670
|
#
|
671
|
-
def text( win_handle)
|
671
|
+
def text( win_handle )
|
672
672
|
buffer = FFI::MemoryPointer.new :char, 1024
|
673
673
|
num_chars = send_message win_handle, Win::GUI::Message::WM_GETTEXT, buffer.size, buffer
|
674
674
|
num_chars == 0 ? nil : buffer.get_bytes(0, num_chars)
|