Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › GetMessageW

GetMessageW

関数
呼び出しスレッドのメッセージキューからメッセージを取得する。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

BOOL GetMessageW(
    MSG* lpMsg,
    HWND hWnd,   // optional
    DWORD wMsgFilterMin,
    DWORD wMsgFilterMax
);

パラメーター

名前方向
lpMsgMSG*out
hWndHWNDinoptional
wMsgFilterMinDWORDin
wMsgFilterMaxDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

BOOL GetMessageW(
    MSG* lpMsg,
    HWND hWnd,   // optional
    DWORD wMsgFilterMin,
    DWORD wMsgFilterMax
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetMessageW(
    IntPtr lpMsg,   // MSG* out
    IntPtr hWnd,   // HWND optional
    uint wMsgFilterMin,   // DWORD
    uint wMsgFilterMax   // DWORD
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetMessageW(
    lpMsg As IntPtr,   ' MSG* out
    hWnd As IntPtr,   ' HWND optional
    wMsgFilterMin As UInteger,   ' DWORD
    wMsgFilterMax As UInteger   ' DWORD
) As Boolean
End Function
' lpMsg : MSG* out
' hWnd : HWND optional
' wMsgFilterMin : DWORD
' wMsgFilterMax : DWORD
Declare PtrSafe Function GetMessageW Lib "user32" ( _
    ByVal lpMsg As LongPtr, _
    ByVal hWnd As LongPtr, _
    ByVal wMsgFilterMin As Long, _
    ByVal wMsgFilterMax 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

GetMessageW = ctypes.windll.user32.GetMessageW
GetMessageW.restype = wintypes.BOOL
GetMessageW.argtypes = [
    ctypes.c_void_p,  # lpMsg : MSG* out
    wintypes.HANDLE,  # hWnd : HWND optional
    wintypes.DWORD,  # wMsgFilterMin : DWORD
    wintypes.DWORD,  # wMsgFilterMax : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetMessageW = Fiddle::Function.new(
  lib['GetMessageW'],
  [
    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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn GetMessageW(
        lpMsg: *mut MSG,  // MSG* out
        hWnd: *mut core::ffi::c_void,  // HWND optional
        wMsgFilterMin: u32,  // DWORD
        wMsgFilterMax: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool GetMessageW(IntPtr lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMessageW' -Namespace Win32 -PassThru
# $api::GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax)
#uselib "USER32.dll"
#func global GetMessageW "GetMessageW" wptr, wptr, wptr, wptr
; GetMessageW varptr(lpMsg), hWnd, wMsgFilterMin, wMsgFilterMax   ; 戻り値は stat
; lpMsg : MSG* out -> "wptr"
; hWnd : HWND optional -> "wptr"
; wMsgFilterMin : DWORD -> "wptr"
; wMsgFilterMax : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetMessageW "GetMessageW" var, sptr, int, int
; res = GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax)
; lpMsg : MSG* out -> "var"
; hWnd : HWND optional -> "sptr"
; wMsgFilterMin : DWORD -> "int"
; wMsgFilterMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetMessageW(MSG* lpMsg, HWND hWnd, DWORD wMsgFilterMin, DWORD wMsgFilterMax)
#uselib "USER32.dll"
#cfunc global GetMessageW "GetMessageW" var, intptr, int, int
; res = GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax)
; lpMsg : MSG* out -> "var"
; hWnd : HWND optional -> "intptr"
; wMsgFilterMin : DWORD -> "int"
; wMsgFilterMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetMessageW = user32.NewProc("GetMessageW")
)

// lpMsg (MSG* out), hWnd (HWND optional), wMsgFilterMin (DWORD), wMsgFilterMax (DWORD)
r1, _, err := procGetMessageW.Call(
	uintptr(lpMsg),
	uintptr(hWnd),
	uintptr(wMsgFilterMin),
	uintptr(wMsgFilterMax),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetMessageW(
  lpMsg: Pointer;   // MSG* out
  hWnd: THandle;   // HWND optional
  wMsgFilterMin: DWORD;   // DWORD
  wMsgFilterMax: DWORD   // DWORD
): BOOL; stdcall;
  external 'USER32.dll' name 'GetMessageW';
result := DllCall("USER32\GetMessageW"
    , "Ptr", lpMsg   ; MSG* out
    , "Ptr", hWnd   ; HWND optional
    , "UInt", wMsgFilterMin   ; DWORD
    , "UInt", wMsgFilterMax   ; DWORD
    , "Int")   ; return: BOOL
●GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax) = DLL("USER32.dll", "bool GetMessageW(void*, void*, dword, dword)")
# 呼び出し: GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax)
# lpMsg : MSG* out -> "void*"
# hWnd : HWND optional -> "void*"
# wMsgFilterMin : DWORD -> "dword"
# wMsgFilterMax : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。