ホーム › UI.WindowsAndMessaging › SendMessageA
SendMessageA
関数ウィンドウにメッセージを送り処理完了まで待つ(ANSI)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
LRESULT SendMessageA(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hWnd | HWND | in |
| Msg | DWORD | in |
| wParam | WPARAM | in |
| lParam | LPARAM | in |
戻り値の型: LRESULT
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
LRESULT SendMessageA(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SendMessageA(
IntPtr hWnd, // HWND
uint Msg, // DWORD
UIntPtr wParam, // WPARAM
IntPtr lParam // LPARAM
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SendMessageA(
hWnd As IntPtr, ' HWND
Msg As UInteger, ' DWORD
wParam As UIntPtr, ' WPARAM
lParam As IntPtr ' LPARAM
) As IntPtr
End Function' hWnd : HWND
' Msg : DWORD
' wParam : WPARAM
' lParam : LPARAM
Declare PtrSafe Function SendMessageA Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal Msg As Long, _
ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SendMessageA = ctypes.windll.user32.SendMessageA
SendMessageA.restype = ctypes.c_ssize_t
SendMessageA.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')
SendMessageA = Fiddle::Function.new(
lib['SendMessageA'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
-Fiddle::TYPE_INT, # Msg : DWORD
Fiddle::TYPE_UINTPTR_T, # wParam : WPARAM
Fiddle::TYPE_INTPTR_T, # lParam : LPARAM
],
Fiddle::TYPE_INTPTR_T)#[link(name = "user32")]
extern "system" {
fn SendMessageA(
hWnd: *mut core::ffi::c_void, // HWND
Msg: u32, // DWORD
wParam: usize, // WPARAM
lParam: isize // LPARAM
) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr SendMessageA(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SendMessageA' -Namespace Win32 -PassThru
# $api::SendMessageA(hWnd, Msg, wParam, lParam)#uselib "USER32.dll"
#func global SendMessageA "SendMessageA" sptr, sptr, sptr, sptr
; SendMessageA hWnd, Msg, wParam, lParam ; 戻り値は stat
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "sptr"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SendMessageA "SendMessageA" sptr, int, sptr, sptr
; res = SendMessageA(hWnd, Msg, wParam, lParam)
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"; LRESULT SendMessageA(HWND hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam)
#uselib "USER32.dll"
#cfunc global SendMessageA "SendMessageA" intptr, int, intptr, intptr
; res = SendMessageA(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")
procSendMessageA = user32.NewProc("SendMessageA")
)
// hWnd (HWND), Msg (DWORD), wParam (WPARAM), lParam (LPARAM)
r1, _, err := procSendMessageA.Call(
uintptr(hWnd),
uintptr(Msg),
uintptr(wParam),
uintptr(lParam),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LRESULTfunction SendMessageA(
hWnd: THandle; // HWND
Msg: DWORD; // DWORD
wParam: NativeUInt; // WPARAM
lParam: NativeInt // LPARAM
): NativeInt; stdcall;
external 'USER32.dll' name 'SendMessageA';result := DllCall("USER32\SendMessageA"
, "Ptr", hWnd ; HWND
, "UInt", Msg ; DWORD
, "UPtr", wParam ; WPARAM
, "Ptr", lParam ; LPARAM
, "Ptr") ; return: LRESULT●SendMessageA(hWnd, Msg, wParam, lParam) = DLL("USER32.dll", "int SendMessageA(void*, dword, int, int)")
# 呼び出し: SendMessageA(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)。