ホーム › UI.WindowsAndMessaging › PeekMessageW
PeekMessageW
関数キューを調べメッセージを取得する(Unicode、非ブロッキング)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL PeekMessageW(
MSG* lpMsg,
HWND hWnd, // optional
DWORD wMsgFilterMin,
DWORD wMsgFilterMax,
PEEK_MESSAGE_REMOVE_TYPE wRemoveMsg
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpMsg | MSG* | out |
| hWnd | HWND | inoptional |
| wMsgFilterMin | DWORD | in |
| wMsgFilterMax | DWORD | in |
| wRemoveMsg | PEEK_MESSAGE_REMOVE_TYPE | in |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL PeekMessageW(
MSG* lpMsg,
HWND hWnd, // optional
DWORD wMsgFilterMin,
DWORD wMsgFilterMax,
PEEK_MESSAGE_REMOVE_TYPE wRemoveMsg
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool PeekMessageW(
IntPtr lpMsg, // MSG* out
IntPtr hWnd, // HWND optional
uint wMsgFilterMin, // DWORD
uint wMsgFilterMax, // DWORD
uint wRemoveMsg // PEEK_MESSAGE_REMOVE_TYPE
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PeekMessageW(
lpMsg As IntPtr, ' MSG* out
hWnd As IntPtr, ' HWND optional
wMsgFilterMin As UInteger, ' DWORD
wMsgFilterMax As UInteger, ' DWORD
wRemoveMsg As UInteger ' PEEK_MESSAGE_REMOVE_TYPE
) As Boolean
End Function' lpMsg : MSG* out
' hWnd : HWND optional
' wMsgFilterMin : DWORD
' wMsgFilterMax : DWORD
' wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE
Declare PtrSafe Function PeekMessageW Lib "user32" ( _
ByVal lpMsg As LongPtr, _
ByVal hWnd As LongPtr, _
ByVal wMsgFilterMin As Long, _
ByVal wMsgFilterMax As Long, _
ByVal wRemoveMsg As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PeekMessageW = ctypes.windll.user32.PeekMessageW
PeekMessageW.restype = wintypes.BOOL
PeekMessageW.argtypes = [
ctypes.c_void_p, # lpMsg : MSG* out
wintypes.HANDLE, # hWnd : HWND optional
wintypes.DWORD, # wMsgFilterMin : DWORD
wintypes.DWORD, # wMsgFilterMax : DWORD
wintypes.DWORD, # wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
PeekMessageW = Fiddle::Function.new(
lib['PeekMessageW'],
[
Fiddle::TYPE_VOIDP, # lpMsg : MSG* out
Fiddle::TYPE_VOIDP, # hWnd : HWND optional
-Fiddle::TYPE_INT, # wMsgFilterMin : DWORD
-Fiddle::TYPE_INT, # wMsgFilterMax : DWORD
-Fiddle::TYPE_INT, # wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn PeekMessageW(
lpMsg: *mut MSG, // MSG* out
hWnd: *mut core::ffi::c_void, // HWND optional
wMsgFilterMin: u32, // DWORD
wMsgFilterMax: u32, // DWORD
wRemoveMsg: u32 // PEEK_MESSAGE_REMOVE_TYPE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern bool PeekMessageW(IntPtr lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_PeekMessageW' -Namespace Win32 -PassThru
# $api::PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg)#uselib "USER32.dll"
#func global PeekMessageW "PeekMessageW" wptr, wptr, wptr, wptr, wptr
; PeekMessageW varptr(lpMsg), hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg ; 戻り値は stat
; lpMsg : MSG* out -> "wptr"
; hWnd : HWND optional -> "wptr"
; wMsgFilterMin : DWORD -> "wptr"
; wMsgFilterMax : DWORD -> "wptr"
; wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global PeekMessageW "PeekMessageW" var, sptr, int, int, int ; res = PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg) ; lpMsg : MSG* out -> "var" ; hWnd : HWND optional -> "sptr" ; wMsgFilterMin : DWORD -> "int" ; wMsgFilterMax : DWORD -> "int" ; wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global PeekMessageW "PeekMessageW" sptr, sptr, int, int, int ; res = PeekMessageW(varptr(lpMsg), hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg) ; lpMsg : MSG* out -> "sptr" ; hWnd : HWND optional -> "sptr" ; wMsgFilterMin : DWORD -> "int" ; wMsgFilterMax : DWORD -> "int" ; wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL PeekMessageW(MSG* lpMsg, HWND hWnd, DWORD wMsgFilterMin, DWORD wMsgFilterMax, PEEK_MESSAGE_REMOVE_TYPE wRemoveMsg) #uselib "USER32.dll" #cfunc global PeekMessageW "PeekMessageW" var, intptr, int, int, int ; res = PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg) ; lpMsg : MSG* out -> "var" ; hWnd : HWND optional -> "intptr" ; wMsgFilterMin : DWORD -> "int" ; wMsgFilterMax : DWORD -> "int" ; wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL PeekMessageW(MSG* lpMsg, HWND hWnd, DWORD wMsgFilterMin, DWORD wMsgFilterMax, PEEK_MESSAGE_REMOVE_TYPE wRemoveMsg) #uselib "USER32.dll" #cfunc global PeekMessageW "PeekMessageW" intptr, intptr, int, int, int ; res = PeekMessageW(varptr(lpMsg), hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg) ; lpMsg : MSG* out -> "intptr" ; hWnd : HWND optional -> "intptr" ; wMsgFilterMin : DWORD -> "int" ; wMsgFilterMax : DWORD -> "int" ; wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procPeekMessageW = user32.NewProc("PeekMessageW")
)
// lpMsg (MSG* out), hWnd (HWND optional), wMsgFilterMin (DWORD), wMsgFilterMax (DWORD), wRemoveMsg (PEEK_MESSAGE_REMOVE_TYPE)
r1, _, err := procPeekMessageW.Call(
uintptr(lpMsg),
uintptr(hWnd),
uintptr(wMsgFilterMin),
uintptr(wMsgFilterMax),
uintptr(wRemoveMsg),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PeekMessageW(
lpMsg: Pointer; // MSG* out
hWnd: THandle; // HWND optional
wMsgFilterMin: DWORD; // DWORD
wMsgFilterMax: DWORD; // DWORD
wRemoveMsg: DWORD // PEEK_MESSAGE_REMOVE_TYPE
): BOOL; stdcall;
external 'USER32.dll' name 'PeekMessageW';result := DllCall("USER32\PeekMessageW"
, "Ptr", lpMsg ; MSG* out
, "Ptr", hWnd ; HWND optional
, "UInt", wMsgFilterMin ; DWORD
, "UInt", wMsgFilterMax ; DWORD
, "UInt", wRemoveMsg ; PEEK_MESSAGE_REMOVE_TYPE
, "Int") ; return: BOOL●PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg) = DLL("USER32.dll", "bool PeekMessageW(void*, void*, dword, dword, dword)")
# 呼び出し: PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg)
# lpMsg : MSG* out -> "void*"
# hWnd : HWND optional -> "void*"
# wMsgFilterMin : DWORD -> "dword"
# wMsgFilterMax : DWORD -> "dword"
# wRemoveMsg : PEEK_MESSAGE_REMOVE_TYPE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。