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

NotifyWinEvent

関数
WinEventフックへアクセシビリティイベントを通知する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll
#include <windows.h>

void NotifyWinEvent(
    DWORD event,
    HWND hwnd,
    INT idObject,
    INT idChild
);

パラメーター

名前方向説明
eventDWORDin通知するWinEventのイベント定数(EVENT_*)。
hwndHWNDinイベントを発生させた要素を含むウィンドウのハンドル。
idObjectINTinイベント対象オブジェクトのID(OBJID_*)。
idChildINTinイベント対象の子要素ID。オブジェクト自身はCHILDID_SELF(0)を指定する。

戻り値の型: void

各言語での呼び出し定義

// USER32.dll
#include <windows.h>

void NotifyWinEvent(
    DWORD event,
    HWND hwnd,
    INT idObject,
    INT idChild
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern void NotifyWinEvent(
    uint event,   // DWORD
    IntPtr hwnd,   // HWND
    int idObject,   // INT
    int idChild   // INT
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Sub NotifyWinEvent(
    [event] As UInteger,   ' DWORD
    hwnd As IntPtr,   ' HWND
    idObject As Integer,   ' INT
    idChild As Integer   ' INT
)
End Sub
' event : DWORD
' hwnd : HWND
' idObject : INT
' idChild : INT
Declare PtrSafe Sub NotifyWinEvent Lib "user32" ( _
    ByVal event As Long, _
    ByVal hwnd As LongPtr, _
    ByVal idObject As Long, _
    ByVal idChild As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NotifyWinEvent = ctypes.windll.user32.NotifyWinEvent
NotifyWinEvent.restype = None
NotifyWinEvent.argtypes = [
    wintypes.DWORD,  # event : DWORD
    wintypes.HANDLE,  # hwnd : HWND
    ctypes.c_int,  # idObject : INT
    ctypes.c_int,  # idChild : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
NotifyWinEvent = Fiddle::Function.new(
  lib['NotifyWinEvent'],
  [
    -Fiddle::TYPE_INT,  # event : DWORD
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_INT,  # idObject : INT
    Fiddle::TYPE_INT,  # idChild : INT
  ],
  Fiddle::TYPE_VOID)
#[link(name = "user32")]
extern "system" {
    fn NotifyWinEvent(
        event: u32,  // DWORD
        hwnd: *mut core::ffi::c_void,  // HWND
        idObject: i32,  // INT
        idChild: i32  // INT
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll")]
public static extern void NotifyWinEvent(uint event, IntPtr hwnd, int idObject, int idChild);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_NotifyWinEvent' -Namespace Win32 -PassThru
# $api::NotifyWinEvent(event, hwnd, idObject, idChild)
#uselib "USER32.dll"
#func global NotifyWinEvent "NotifyWinEvent" sptr, sptr, sptr, sptr
; NotifyWinEvent event, hwnd, idObject, idChild
; event : DWORD -> "sptr"
; hwnd : HWND -> "sptr"
; idObject : INT -> "sptr"
; idChild : INT -> "sptr"
#uselib "USER32.dll"
#func global NotifyWinEvent "NotifyWinEvent" int, sptr, int, int
; NotifyWinEvent event, hwnd, idObject, idChild
; event : DWORD -> "int"
; hwnd : HWND -> "sptr"
; idObject : INT -> "int"
; idChild : INT -> "int"
; void NotifyWinEvent(DWORD event, HWND hwnd, INT idObject, INT idChild)
#uselib "USER32.dll"
#func global NotifyWinEvent "NotifyWinEvent" int, intptr, int, int
; NotifyWinEvent event, hwnd, idObject, idChild
; event : DWORD -> "int"
; hwnd : HWND -> "intptr"
; idObject : INT -> "int"
; idChild : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procNotifyWinEvent = user32.NewProc("NotifyWinEvent")
)

// event (DWORD), hwnd (HWND), idObject (INT), idChild (INT)
r1, _, err := procNotifyWinEvent.Call(
	uintptr(event),
	uintptr(hwnd),
	uintptr(idObject),
	uintptr(idChild),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure NotifyWinEvent(
  event: DWORD;   // DWORD
  hwnd: THandle;   // HWND
  idObject: Integer;   // INT
  idChild: Integer   // INT
); stdcall;
  external 'USER32.dll' name 'NotifyWinEvent';
result := DllCall("USER32\NotifyWinEvent"
    , "UInt", event   ; DWORD
    , "Ptr", hwnd   ; HWND
    , "Int", idObject   ; INT
    , "Int", idChild   ; INT
    , "Int")   ; return: void
●NotifyWinEvent(event, hwnd, idObject, idChild) = DLL("USER32.dll", "int NotifyWinEvent(dword, void*, int, int)")
# 呼び出し: NotifyWinEvent(event, hwnd, idObject, idChild)
# event : DWORD -> "dword"
# hwnd : HWND -> "void*"
# idObject : INT -> "int"
# idChild : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "user32" fn NotifyWinEvent(
    event: u32, // DWORD
    hwnd: ?*anyopaque, // HWND
    idObject: i32, // INT
    idChild: i32 // INT
) callconv(std.os.windows.WINAPI) void;
proc NotifyWinEvent(
    event: uint32,  # DWORD
    hwnd: pointer,  # HWND
    idObject: int32,  # INT
    idChild: int32  # INT
) {.importc: "NotifyWinEvent", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
void NotifyWinEvent(
    uint event,   // DWORD
    void* hwnd,   // HWND
    int idObject,   // INT
    int idChild   // INT
);
ccall((:NotifyWinEvent, "USER32.dll"), stdcall, Cvoid,
      (UInt32, Ptr{Cvoid}, Int32, Int32),
      event, hwnd, idObject, idChild)
# event : DWORD -> UInt32
# hwnd : HWND -> Ptr{Cvoid}
# idObject : INT -> Int32
# idChild : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void NotifyWinEvent(
    uint32_t event,
    void* hwnd,
    int32_t idObject,
    int32_t idChild);
]]
local user32 = ffi.load("user32")
-- user32.NotifyWinEvent(event, hwnd, idObject, idChild)
-- event : DWORD
-- hwnd : HWND
-- idObject : INT
-- idChild : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const NotifyWinEvent = lib.func('__stdcall', 'NotifyWinEvent', 'void', ['uint32_t', 'void *', 'int32_t', 'int32_t']);
// NotifyWinEvent(event, hwnd, idObject, idChild)
// event : DWORD -> 'uint32_t'
// hwnd : HWND -> 'void *'
// idObject : INT -> 'int32_t'
// idChild : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  NotifyWinEvent: { parameters: ["u32", "pointer", "i32", "i32"], result: "void" },
});
// lib.symbols.NotifyWinEvent(event, hwnd, idObject, idChild)
// event : DWORD -> "u32"
// hwnd : HWND -> "pointer"
// idObject : INT -> "i32"
// idChild : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void NotifyWinEvent(
    uint32_t event,
    void* hwnd,
    int32_t idObject,
    int32_t idChild);
C, "USER32.dll");
// $ffi->NotifyWinEvent(event, hwnd, idObject, idChild);
// event : DWORD
// hwnd : HWND
// idObject : INT
// idChild : INT
// 構造体/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);
    void NotifyWinEvent(
        int event,   // DWORD
        Pointer hwnd,   // HWND
        int idObject,   // INT
        int idChild   // INT
    );
}
@[Link("user32")]
lib LibUSER32
  fun NotifyWinEvent = NotifyWinEvent(
    event : UInt32,   # DWORD
    hwnd : Void*,   # HWND
    idObject : Int32,   # INT
    idChild : Int32   # INT
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NotifyWinEventNative = Void Function(Uint32, Pointer<Void>, Int32, Int32);
typedef NotifyWinEventDart = void Function(int, Pointer<Void>, int, int);
final NotifyWinEvent = DynamicLibrary.open('USER32.dll')
    .lookupFunction<NotifyWinEventNative, NotifyWinEventDart>('NotifyWinEvent');
// event : DWORD -> Uint32
// hwnd : HWND -> Pointer<Void>
// idObject : INT -> Int32
// idChild : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure NotifyWinEvent(
  event: DWORD;   // DWORD
  hwnd: THandle;   // HWND
  idObject: Integer;   // INT
  idChild: Integer   // INT
); stdcall;
  external 'USER32.dll' name 'NotifyWinEvent';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NotifyWinEvent"
  c_NotifyWinEvent :: Word32 -> Ptr () -> Int32 -> Int32 -> IO ()
-- event : DWORD -> Word32
-- hwnd : HWND -> Ptr ()
-- idObject : INT -> Int32
-- idChild : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let notifywinevent =
  foreign "NotifyWinEvent"
    (uint32_t @-> (ptr void) @-> int32_t @-> int32_t @-> returning void)
(* event : DWORD -> uint32_t *)
(* hwnd : HWND -> (ptr void) *)
(* idObject : INT -> int32_t *)
(* idChild : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("NotifyWinEvent" notify-win-event :convention :stdcall) :void
  (event :uint32)   ; DWORD
  (hwnd :pointer)   ; HWND
  (id-object :int32)   ; INT
  (id-child :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NotifyWinEvent = Win32::API::More->new('USER32',
    'void NotifyWinEvent(DWORD event, HANDLE hwnd, int idObject, int idChild)');
# my $ret = $NotifyWinEvent->Call($event, $hwnd, $idObject, $idChild);
# event : DWORD -> DWORD
# hwnd : HWND -> HANDLE
# idObject : INT -> int
# idChild : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。