SendNotifyMessageW
関数シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL SendNotifyMessageW(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | メッセージを受け取るウィンドウプロシージャを持つウィンドウへのハンドルです。このパラメーターが HWND_BROADCAST ((HWND)0xffff) の場合、メッセージは、無効化または非表示の所有者なしウィンドウ、オーバーラップウィンドウ、ポップアップウィンドウを含む、システム内のすべてのトップレベルウィンドウに送信されます。ただし、子ウィンドウには送信されません。 |
| Msg | DWORD | in | 送信するメッセージです。 システムが提供するメッセージの一覧については、System-Defined Messages を参照してください。 |
| wParam | WPARAM | in | メッセージ固有の追加情報です。 |
| lParam | LPARAM | in | メッセージ固有の追加情報です。 |
戻り値の型: BOOL
公式ドキュメント
指定したメッセージを 1 つまたは複数のウィンドウに送信します。(SendNotifyMessageW)
戻り値
解説(Remarks)
WM_USER より小さい範囲のメッセージを非同期メッセージ関数(PostMessage、SendNotifyMessage、SendMessageCallback)に送信する場合、そのメッセージパラメーターにポインターを含めることはできません。含めると操作は失敗します。これらの関数は、受信側スレッドがメッセージを処理する前に戻り、送信側はメモリが使用される前に解放してしまうためです。
HWND_BROADCAST を使用して通信する必要があるアプリケーションは、RegisterWindowMessage 関数を使用して、アプリケーション間通信用の一意のメッセージを取得してください。
システムは、システムメッセージ(0 から (WM_USER-1) までの範囲)に対してのみマーシャリングを行います。その他のメッセージ(WM_USER 以上)を別のプロセスに送信するには、独自にマーシャリングを行う必要があります。
winuser.h ヘッダーは、SendNotifyMessage を、UNICODE プリプロセッサー定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL SendNotifyMessageW(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SendNotifyMessageW(
IntPtr hWnd, // HWND
uint Msg, // DWORD
UIntPtr wParam, // WPARAM
IntPtr lParam // LPARAM
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SendNotifyMessageW(
hWnd As IntPtr, ' HWND
Msg As UInteger, ' DWORD
wParam As UIntPtr, ' WPARAM
lParam As IntPtr ' LPARAM
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hWnd : HWND
' Msg : DWORD
' wParam : WPARAM
' lParam : LPARAM
Declare PtrSafe Function SendNotifyMessageW Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal Msg As Long, _
ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) 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
SendNotifyMessageW = ctypes.windll.user32.SendNotifyMessageW
SendNotifyMessageW.restype = wintypes.BOOL
SendNotifyMessageW.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.DWORD, # Msg : DWORD
ctypes.c_size_t, # wParam : WPARAM
ctypes.c_ssize_t, # lParam : LPARAM
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SendNotifyMessageW = Fiddle::Function.new(
lib['SendNotifyMessageW'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
-Fiddle::TYPE_INT, # Msg : DWORD
Fiddle::TYPE_UINTPTR_T, # wParam : WPARAM
Fiddle::TYPE_INTPTR_T, # lParam : LPARAM
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn SendNotifyMessageW(
hWnd: *mut core::ffi::c_void, // HWND
Msg: u32, // DWORD
wParam: usize, // WPARAM
lParam: isize // LPARAM
) -> 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 SendNotifyMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SendNotifyMessageW' -Namespace Win32 -PassThru
# $api::SendNotifyMessageW(hWnd, Msg, wParam, lParam)#uselib "USER32.dll"
#func global SendNotifyMessageW "SendNotifyMessageW" wptr, wptr, wptr, wptr
; SendNotifyMessageW hWnd, Msg, wParam, lParam ; 戻り値は stat
; hWnd : HWND -> "wptr"
; Msg : DWORD -> "wptr"
; wParam : WPARAM -> "wptr"
; lParam : LPARAM -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SendNotifyMessageW "SendNotifyMessageW" sptr, int, sptr, sptr
; res = SendNotifyMessageW(hWnd, Msg, wParam, lParam)
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"; BOOL SendNotifyMessageW(HWND hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam)
#uselib "USER32.dll"
#cfunc global SendNotifyMessageW "SendNotifyMessageW" intptr, int, intptr, intptr
; res = SendNotifyMessageW(hWnd, Msg, wParam, lParam)
; hWnd : HWND -> "intptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "intptr"
; lParam : LPARAM -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procSendNotifyMessageW = user32.NewProc("SendNotifyMessageW")
)
// hWnd (HWND), Msg (DWORD), wParam (WPARAM), lParam (LPARAM)
r1, _, err := procSendNotifyMessageW.Call(
uintptr(hWnd),
uintptr(Msg),
uintptr(wParam),
uintptr(lParam),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SendNotifyMessageW(
hWnd: THandle; // HWND
Msg: DWORD; // DWORD
wParam: NativeUInt; // WPARAM
lParam: NativeInt // LPARAM
): BOOL; stdcall;
external 'USER32.dll' name 'SendNotifyMessageW';result := DllCall("USER32\SendNotifyMessageW"
, "Ptr", hWnd ; HWND
, "UInt", Msg ; DWORD
, "UPtr", wParam ; WPARAM
, "Ptr", lParam ; LPARAM
, "Int") ; return: BOOL●SendNotifyMessageW(hWnd, Msg, wParam, lParam) = DLL("USER32.dll", "bool SendNotifyMessageW(void*, dword, int, int)")
# 呼び出し: SendNotifyMessageW(hWnd, Msg, wParam, lParam)
# hWnd : HWND -> "void*"
# Msg : DWORD -> "dword"
# wParam : WPARAM -> "int"
# lParam : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "user32" fn SendNotifyMessageW(
hWnd: ?*anyopaque, // HWND
Msg: u32, // DWORD
wParam: usize, // WPARAM
lParam: isize // LPARAM
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SendNotifyMessageW(
hWnd: pointer, # HWND
Msg: uint32, # DWORD
wParam: uint, # WPARAM
lParam: int # LPARAM
): int32 {.importc: "SendNotifyMessageW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "user32");
extern(Windows)
int SendNotifyMessageW(
void* hWnd, // HWND
uint Msg, // DWORD
size_t wParam, // WPARAM
ptrdiff_t lParam // LPARAM
);ccall((:SendNotifyMessageW, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Csize_t, Int),
hWnd, Msg, wParam, lParam)
# hWnd : HWND -> Ptr{Cvoid}
# Msg : DWORD -> UInt32
# wParam : WPARAM -> Csize_t
# lParam : LPARAM -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SendNotifyMessageW(
void* hWnd,
uint32_t Msg,
uintptr_t wParam,
intptr_t lParam);
]]
local user32 = ffi.load("user32")
-- user32.SendNotifyMessageW(hWnd, Msg, wParam, lParam)
-- hWnd : HWND
-- Msg : DWORD
-- wParam : WPARAM
-- lParam : LPARAM
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const SendNotifyMessageW = lib.func('__stdcall', 'SendNotifyMessageW', 'int32_t', ['void *', 'uint32_t', 'uintptr_t', 'intptr_t']);
// SendNotifyMessageW(hWnd, Msg, wParam, lParam)
// hWnd : HWND -> 'void *'
// Msg : DWORD -> 'uint32_t'
// wParam : WPARAM -> 'uintptr_t'
// lParam : LPARAM -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SendNotifyMessageW: { parameters: ["pointer", "u32", "usize", "isize"], result: "i32" },
});
// lib.symbols.SendNotifyMessageW(hWnd, Msg, wParam, lParam)
// hWnd : HWND -> "pointer"
// Msg : DWORD -> "u32"
// wParam : WPARAM -> "usize"
// lParam : LPARAM -> "isize"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SendNotifyMessageW(
void* hWnd,
uint32_t Msg,
size_t wParam,
intptr_t lParam);
C, "USER32.dll");
// $ffi->SendNotifyMessageW(hWnd, Msg, wParam, lParam);
// hWnd : HWND
// Msg : DWORD
// wParam : WPARAM
// lParam : LPARAM
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
boolean SendNotifyMessageW(
Pointer hWnd, // HWND
int Msg, // DWORD
long wParam, // WPARAM
long lParam // LPARAM
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("user32")]
lib LibUSER32
fun SendNotifyMessageW = SendNotifyMessageW(
hWnd : Void*, # HWND
Msg : UInt32, # DWORD
wParam : LibC::SizeT, # WPARAM
lParam : LibC::SSizeT # LPARAM
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SendNotifyMessageWNative = Int32 Function(Pointer<Void>, Uint32, UintPtr, IntPtr);
typedef SendNotifyMessageWDart = int Function(Pointer<Void>, int, int, int);
final SendNotifyMessageW = DynamicLibrary.open('USER32.dll')
.lookupFunction<SendNotifyMessageWNative, SendNotifyMessageWDart>('SendNotifyMessageW');
// hWnd : HWND -> Pointer<Void>
// Msg : DWORD -> Uint32
// wParam : WPARAM -> UintPtr
// lParam : LPARAM -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SendNotifyMessageW(
hWnd: THandle; // HWND
Msg: DWORD; // DWORD
wParam: NativeUInt; // WPARAM
lParam: NativeInt // LPARAM
): BOOL; stdcall;
external 'USER32.dll' name 'SendNotifyMessageW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SendNotifyMessageW"
c_SendNotifyMessageW :: Ptr () -> Word32 -> CUIntPtr -> CIntPtr -> IO CInt
-- hWnd : HWND -> Ptr ()
-- Msg : DWORD -> Word32
-- wParam : WPARAM -> CUIntPtr
-- lParam : LPARAM -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sendnotifymessagew =
foreign "SendNotifyMessageW"
((ptr void) @-> uint32_t @-> size_t @-> intptr_t @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* Msg : DWORD -> uint32_t *)
(* wParam : WPARAM -> size_t *)
(* lParam : LPARAM -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("SendNotifyMessageW" send-notify-message-w :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(msg :uint32) ; DWORD
(w-param :uint64) ; WPARAM
(l-param :int64)) ; LPARAM
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SendNotifyMessageW = Win32::API::More->new('USER32',
'BOOL SendNotifyMessageW(HANDLE hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam)');
# my $ret = $SendNotifyMessageW->Call($hWnd, $Msg, $wParam, $lParam);
# hWnd : HWND -> HANDLE
# Msg : DWORD -> DWORD
# wParam : WPARAM -> WPARAM
# lParam : LPARAM -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SendNotifyMessageA (ANSI版) — メッセージを送り戻りを待たず通知する(ANSI)。
- f PostMessageW — メッセージをキューに投函し即時に戻る(Unicode)。
- f PostThreadMessageW — 指定スレッドのキューにメッセージを投函する(Unicode)。
- f RegisterWindowMessageW — アプリ間で一意なウィンドウメッセージを登録する(Unicode)。
- f SendMessageCallbackW — 非同期でメッセージを送りコールバックで結果を受ける(Unicode)。