ホーム › UI.WindowsAndMessaging › DefWindowProcA
DefWindowProcA
関数既定のウィンドウメッセージ処理を行う(ANSI)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
LRESULT DefWindowProcA(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | メッセージを受け取ったウィンドウプロシージャへのハンドル。 |
| Msg | DWORD | in | メッセージ。 |
| wParam | WPARAM | in | メッセージに関する追加情報。このパラメーターの内容は Msg パラメーターの値に依存します。 |
| lParam | LPARAM | in | メッセージに関する追加情報。このパラメーターの内容は Msg パラメーターの値に依存します。 |
戻り値の型: LRESULT
公式ドキュメント
アプリケーションが処理しないウィンドウメッセージに対して、既定の処理を提供するためにデフォルトのウィンドウプロシージャを呼び出します。(ANSI)
戻り値
型: LRESULT
戻り値はメッセージ処理の結果であり、メッセージによって異なります。
解説(Remarks)
メモ
winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして DefWindowProc を定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
LRESULT DefWindowProcA(
HWND hWnd,
DWORD Msg,
WPARAM wParam,
LPARAM lParam
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr DefWindowProcA(
IntPtr hWnd, // HWND
uint Msg, // DWORD
UIntPtr wParam, // WPARAM
IntPtr lParam // LPARAM
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DefWindowProcA(
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 DefWindowProcA 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
DefWindowProcA = ctypes.windll.user32.DefWindowProcA
DefWindowProcA.restype = ctypes.c_ssize_t
DefWindowProcA.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.DWORD, # Msg : DWORD
ctypes.c_size_t, # wParam : WPARAM
ctypes.c_ssize_t, # lParam : LPARAM
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DefWindowProcA = Fiddle::Function.new(
lib['DefWindowProcA'],
[
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 DefWindowProcA(
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)]
public static extern IntPtr DefWindowProcA(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DefWindowProcA' -Namespace Win32 -PassThru
# $api::DefWindowProcA(hWnd, Msg, wParam, lParam)#uselib "USER32.dll"
#func global DefWindowProcA "DefWindowProcA" sptr, sptr, sptr, sptr
; DefWindowProcA 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 DefWindowProcA "DefWindowProcA" sptr, int, sptr, sptr
; res = DefWindowProcA(hWnd, Msg, wParam, lParam)
; hWnd : HWND -> "sptr"
; Msg : DWORD -> "int"
; wParam : WPARAM -> "sptr"
; lParam : LPARAM -> "sptr"; LRESULT DefWindowProcA(HWND hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam)
#uselib "USER32.dll"
#cfunc global DefWindowProcA "DefWindowProcA" intptr, int, intptr, intptr
; res = DefWindowProcA(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")
procDefWindowProcA = user32.NewProc("DefWindowProcA")
)
// hWnd (HWND), Msg (DWORD), wParam (WPARAM), lParam (LPARAM)
r1, _, err := procDefWindowProcA.Call(
uintptr(hWnd),
uintptr(Msg),
uintptr(wParam),
uintptr(lParam),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LRESULTfunction DefWindowProcA(
hWnd: THandle; // HWND
Msg: DWORD; // DWORD
wParam: NativeUInt; // WPARAM
lParam: NativeInt // LPARAM
): NativeInt; stdcall;
external 'USER32.dll' name 'DefWindowProcA';result := DllCall("USER32\DefWindowProcA"
, "Ptr", hWnd ; HWND
, "UInt", Msg ; DWORD
, "UPtr", wParam ; WPARAM
, "Ptr", lParam ; LPARAM
, "Ptr") ; return: LRESULT●DefWindowProcA(hWnd, Msg, wParam, lParam) = DLL("USER32.dll", "int DefWindowProcA(void*, dword, int, int)")
# 呼び出し: DefWindowProcA(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)。const std = @import("std");
extern "user32" fn DefWindowProcA(
hWnd: ?*anyopaque, // HWND
Msg: u32, // DWORD
wParam: usize, // WPARAM
lParam: isize // LPARAM
) callconv(std.os.windows.WINAPI) isize;proc DefWindowProcA(
hWnd: pointer, # HWND
Msg: uint32, # DWORD
wParam: uint, # WPARAM
lParam: int # LPARAM
): int {.importc: "DefWindowProcA", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
ptrdiff_t DefWindowProcA(
void* hWnd, // HWND
uint Msg, // DWORD
size_t wParam, // WPARAM
ptrdiff_t lParam // LPARAM
);ccall((:DefWindowProcA, "USER32.dll"), stdcall, Int,
(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 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t DefWindowProcA(
void* hWnd,
uint32_t Msg,
uintptr_t wParam,
intptr_t lParam);
]]
local user32 = ffi.load("user32")
-- user32.DefWindowProcA(hWnd, Msg, wParam, lParam)
-- hWnd : HWND
-- Msg : DWORD
-- wParam : WPARAM
-- lParam : LPARAM
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DefWindowProcA = lib.func('__stdcall', 'DefWindowProcA', 'intptr_t', ['void *', 'uint32_t', 'uintptr_t', 'intptr_t']);
// DefWindowProcA(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", {
DefWindowProcA: { parameters: ["pointer", "u32", "usize", "isize"], result: "isize" },
});
// lib.symbols.DefWindowProcA(hWnd, Msg, wParam, lParam)
// hWnd : HWND -> "pointer"
// Msg : DWORD -> "u32"
// wParam : WPARAM -> "usize"
// lParam : LPARAM -> "isize"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t DefWindowProcA(
void* hWnd,
uint32_t Msg,
size_t wParam,
intptr_t lParam);
C, "USER32.dll");
// $ffi->DefWindowProcA(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.ASCII_OPTIONS);
long DefWindowProcA(
Pointer hWnd, // HWND
int Msg, // DWORD
long wParam, // WPARAM
long lParam // LPARAM
);
}@[Link("user32")]
lib LibUSER32
fun DefWindowProcA = DefWindowProcA(
hWnd : Void*, # HWND
Msg : UInt32, # DWORD
wParam : LibC::SizeT, # WPARAM
lParam : LibC::SSizeT # LPARAM
) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DefWindowProcANative = IntPtr Function(Pointer<Void>, Uint32, UintPtr, IntPtr);
typedef DefWindowProcADart = int Function(Pointer<Void>, int, int, int);
final DefWindowProcA = DynamicLibrary.open('USER32.dll')
.lookupFunction<DefWindowProcANative, DefWindowProcADart>('DefWindowProcA');
// hWnd : HWND -> Pointer<Void>
// Msg : DWORD -> Uint32
// wParam : WPARAM -> UintPtr
// lParam : LPARAM -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DefWindowProcA(
hWnd: THandle; // HWND
Msg: DWORD; // DWORD
wParam: NativeUInt; // WPARAM
lParam: NativeInt // LPARAM
): NativeInt; stdcall;
external 'USER32.dll' name 'DefWindowProcA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DefWindowProcA"
c_DefWindowProcA :: Ptr () -> Word32 -> CUIntPtr -> CIntPtr -> IO CIntPtr
-- hWnd : HWND -> Ptr ()
-- Msg : DWORD -> Word32
-- wParam : WPARAM -> CUIntPtr
-- lParam : LPARAM -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let defwindowproca =
foreign "DefWindowProcA"
((ptr void) @-> uint32_t @-> size_t @-> intptr_t @-> returning intptr_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 ("DefWindowProcA" def-window-proc-a :convention :stdcall) :int64
(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 $DefWindowProcA = Win32::API::More->new('USER32',
'LPARAM DefWindowProcA(HANDLE hWnd, DWORD Msg, WPARAM wParam, LPARAM lParam)');
# my $ret = $DefWindowProcA->Call($hWnd, $Msg, $wParam, $lParam);
# hWnd : HWND -> HANDLE
# Msg : DWORD -> DWORD
# wParam : WPARAM -> WPARAM
# lParam : LPARAM -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f DefWindowProcW (Unicode版) — 既定のウィンドウメッセージ処理を行う(Unicode)。
公式の関連項目
- f CallWindowProcA — 指定のウィンドウプロシージャを呼び出す(ANSI)。
- f DefDlgProcA — 既定のダイアログメッセージ処理を行う(ANSI)。
- c WNDPROC