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

SendMessageTimeoutA

関数
タイムアウト付きでメッセージを送る(ANSI)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

LRESULT SendMessageTimeoutA(
    HWND hWnd,
    DWORD Msg,
    WPARAM wParam,
    LPARAM lParam,
    SEND_MESSAGE_TIMEOUT_FLAGS fuFlags,
    DWORD uTimeout,
    UINT_PTR* lpdwResult   // optional
);

パラメーター

名前方向
hWndHWNDin
MsgDWORDin
wParamWPARAMin
lParamLPARAMin
fuFlagsSEND_MESSAGE_TIMEOUT_FLAGSin
uTimeoutDWORDin
lpdwResultUINT_PTR*outoptional

戻り値の型: LRESULT

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

LRESULT SendMessageTimeoutA(
    HWND hWnd,
    DWORD Msg,
    WPARAM wParam,
    LPARAM lParam,
    SEND_MESSAGE_TIMEOUT_FLAGS fuFlags,
    DWORD uTimeout,
    UINT_PTR* lpdwResult   // optional
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SendMessageTimeoutA(
    IntPtr hWnd,   // HWND
    uint Msg,   // DWORD
    UIntPtr wParam,   // WPARAM
    IntPtr lParam,   // LPARAM
    uint fuFlags,   // SEND_MESSAGE_TIMEOUT_FLAGS
    uint uTimeout,   // DWORD
    IntPtr lpdwResult   // UINT_PTR* optional, out
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SendMessageTimeoutA(
    hWnd As IntPtr,   ' HWND
    Msg As UInteger,   ' DWORD
    wParam As UIntPtr,   ' WPARAM
    lParam As IntPtr,   ' LPARAM
    fuFlags As UInteger,   ' SEND_MESSAGE_TIMEOUT_FLAGS
    uTimeout As UInteger,   ' DWORD
    lpdwResult As IntPtr   ' UINT_PTR* optional, out
) As IntPtr
End Function
' hWnd : HWND
' Msg : DWORD
' wParam : WPARAM
' lParam : LPARAM
' fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS
' uTimeout : DWORD
' lpdwResult : UINT_PTR* optional, out
Declare PtrSafe Function SendMessageTimeoutA Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal Msg As Long, _
    ByVal wParam As LongPtr, _
    ByVal lParam As LongPtr, _
    ByVal fuFlags As Long, _
    ByVal uTimeout As Long, _
    ByVal lpdwResult As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SendMessageTimeoutA = ctypes.windll.user32.SendMessageTimeoutA
SendMessageTimeoutA.restype = ctypes.c_ssize_t
SendMessageTimeoutA.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.DWORD,  # Msg : DWORD
    ctypes.c_size_t,  # wParam : WPARAM
    ctypes.c_ssize_t,  # lParam : LPARAM
    wintypes.DWORD,  # fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS
    wintypes.DWORD,  # uTimeout : DWORD
    ctypes.POINTER(ctypes.c_size_t),  # lpdwResult : UINT_PTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SendMessageTimeoutA = Fiddle::Function.new(
  lib['SendMessageTimeoutA'],
  [
    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,  # fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS
    -Fiddle::TYPE_INT,  # uTimeout : DWORD
    Fiddle::TYPE_VOIDP,  # lpdwResult : UINT_PTR* optional, out
  ],
  Fiddle::TYPE_INTPTR_T)
#[link(name = "user32")]
extern "system" {
    fn SendMessageTimeoutA(
        hWnd: *mut core::ffi::c_void,  // HWND
        Msg: u32,  // DWORD
        wParam: usize,  // WPARAM
        lParam: isize,  // LPARAM
        fuFlags: u32,  // SEND_MESSAGE_TIMEOUT_FLAGS
        uTimeout: u32,  // DWORD
        lpdwResult: *mut usize  // UINT_PTR* optional, out
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr SendMessageTimeoutA(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SendMessageTimeoutA' -Namespace Win32 -PassThru
# $api::SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult)
#uselib "USER32.dll"
#func global SendMessageTimeoutA "SendMessageTimeoutA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SendMessageTimeoutA hWnd, Msg, wParam, lParam, fuFlags, uTimeout, varptr(lpdwResult)   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "sptr"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"
; fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS -> "sptr"
; uTimeout : DWORD -> "sptr"
; lpdwResult : UINT_PTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global SendMessageTimeoutA "SendMessageTimeoutA" sptr, int, sptr, sptr, int, int, var
; res = SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult)
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"
; fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS -> "int"
; uTimeout : DWORD -> "int"
; lpdwResult : UINT_PTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; LRESULT SendMessageTimeoutA(HWND hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam, SEND_MESSAGE_TIMEOUT_FLAGS fuFlags, DWORD uTimeout, UINT_PTR* lpdwResult)
#uselib "USER32.dll"
#cfunc global SendMessageTimeoutA "SendMessageTimeoutA" intptr, int, intptr, intptr, int, int, var
; res = SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult)
; hWnd : HWND -> "intptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "intptr"
; lParam : LPARAM -> "intptr"
; fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS -> "int"
; uTimeout : DWORD -> "int"
; lpdwResult : UINT_PTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSendMessageTimeoutA = user32.NewProc("SendMessageTimeoutA")
)

// hWnd (HWND), Msg (DWORD), wParam (WPARAM), lParam (LPARAM), fuFlags (SEND_MESSAGE_TIMEOUT_FLAGS), uTimeout (DWORD), lpdwResult (UINT_PTR* optional, out)
r1, _, err := procSendMessageTimeoutA.Call(
	uintptr(hWnd),
	uintptr(Msg),
	uintptr(wParam),
	uintptr(lParam),
	uintptr(fuFlags),
	uintptr(uTimeout),
	uintptr(lpdwResult),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LRESULT
function SendMessageTimeoutA(
  hWnd: THandle;   // HWND
  Msg: DWORD;   // DWORD
  wParam: NativeUInt;   // WPARAM
  lParam: NativeInt;   // LPARAM
  fuFlags: DWORD;   // SEND_MESSAGE_TIMEOUT_FLAGS
  uTimeout: DWORD;   // DWORD
  lpdwResult: Pointer   // UINT_PTR* optional, out
): NativeInt; stdcall;
  external 'USER32.dll' name 'SendMessageTimeoutA';
result := DllCall("USER32\SendMessageTimeoutA"
    , "Ptr", hWnd   ; HWND
    , "UInt", Msg   ; DWORD
    , "UPtr", wParam   ; WPARAM
    , "Ptr", lParam   ; LPARAM
    , "UInt", fuFlags   ; SEND_MESSAGE_TIMEOUT_FLAGS
    , "UInt", uTimeout   ; DWORD
    , "Ptr", lpdwResult   ; UINT_PTR* optional, out
    , "Ptr")   ; return: LRESULT
●SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult) = DLL("USER32.dll", "int SendMessageTimeoutA(void*, dword, int, int, dword, dword, void*)")
# 呼び出し: SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, lpdwResult)
# hWnd : HWND -> "void*"
# Msg : DWORD -> "dword"
# wParam : WPARAM -> "int"
# lParam : LPARAM -> "int"
# fuFlags : SEND_MESSAGE_TIMEOUT_FLAGS -> "dword"
# uTimeout : DWORD -> "dword"
# lpdwResult : UINT_PTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。