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

EnumChildWindows

関数
親ウィンドウの全子ウィンドウをコールバックで列挙する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL EnumChildWindows(
    HWND hWndParent,   // optional
    WNDENUMPROC lpEnumFunc,
    LPARAM lParam
);

パラメーター

名前方向説明
hWndParentHWNDinoptional子ウィンドウを列挙する対象となる親ウィンドウへのハンドル。このパラメーターが NULL の場合、この関数は EnumWindows と同等になります。
lpEnumFuncWNDENUMPROCinアプリケーション定義のコールバック関数へのポインター。詳細については、EnumChildProc を参照してください。
lParamLPARAMinコールバック関数に渡される、アプリケーション定義の値。

戻り値の型: BOOL

公式ドキュメント

指定された親ウィンドウに属する子ウィンドウを列挙します。各子ウィンドウのハンドルを順番にアプリケーション定義のコールバック関数へ渡します。

戻り値

型: BOOL

戻り値は使用されません。

解説(Remarks)

子ウィンドウがさらに独自の子ウィンドウを作成している場合、EnumChildWindows はそれらのウィンドウも列挙します。

列挙処理中に移動されたり Z オーダー内で位置を変更されたりした子ウィンドウは、正しく列挙されます。列挙される前に破棄された子ウィンドウ、または列挙処理中に作成された子ウィンドウは、この関数では列挙されません。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL EnumChildWindows(
    HWND hWndParent,   // optional
    WNDENUMPROC lpEnumFunc,
    LPARAM lParam
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", ExactSpelling = true)]
static extern bool EnumChildWindows(
    IntPtr hWndParent,   // HWND optional
    IntPtr lpEnumFunc,   // WNDENUMPROC
    IntPtr lParam   // LPARAM
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function EnumChildWindows(
    hWndParent As IntPtr,   ' HWND optional
    lpEnumFunc As IntPtr,   ' WNDENUMPROC
    lParam As IntPtr   ' LPARAM
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hWndParent : HWND optional
' lpEnumFunc : WNDENUMPROC
' lParam : LPARAM
Declare PtrSafe Function EnumChildWindows Lib "user32" ( _
    ByVal hWndParent As LongPtr, _
    ByVal lpEnumFunc As LongPtr, _
    ByVal lParam As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EnumChildWindows = ctypes.windll.user32.EnumChildWindows
EnumChildWindows.restype = wintypes.BOOL
EnumChildWindows.argtypes = [
    wintypes.HANDLE,  # hWndParent : HWND optional
    ctypes.c_void_p,  # lpEnumFunc : WNDENUMPROC
    ctypes.c_ssize_t,  # lParam : LPARAM
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
EnumChildWindows = Fiddle::Function.new(
  lib['EnumChildWindows'],
  [
    Fiddle::TYPE_VOIDP,  # hWndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # lpEnumFunc : WNDENUMPROC
    Fiddle::TYPE_INTPTR_T,  # lParam : LPARAM
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn EnumChildWindows(
        hWndParent: *mut core::ffi::c_void,  // HWND optional
        lpEnumFunc: *const core::ffi::c_void,  // WNDENUMPROC
        lParam: isize  // LPARAM
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll")]
public static extern bool EnumChildWindows(IntPtr hWndParent, IntPtr lpEnumFunc, IntPtr lParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_EnumChildWindows' -Namespace Win32 -PassThru
# $api::EnumChildWindows(hWndParent, lpEnumFunc, lParam)
#uselib "USER32.dll"
#func global EnumChildWindows "EnumChildWindows" sptr, sptr, sptr
; EnumChildWindows hWndParent, lpEnumFunc, lParam   ; 戻り値は stat
; hWndParent : HWND optional -> "sptr"
; lpEnumFunc : WNDENUMPROC -> "sptr"
; lParam : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global EnumChildWindows "EnumChildWindows" sptr, sptr, sptr
; res = EnumChildWindows(hWndParent, lpEnumFunc, lParam)
; hWndParent : HWND optional -> "sptr"
; lpEnumFunc : WNDENUMPROC -> "sptr"
; lParam : LPARAM -> "sptr"
; BOOL EnumChildWindows(HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM lParam)
#uselib "USER32.dll"
#cfunc global EnumChildWindows "EnumChildWindows" intptr, intptr, intptr
; res = EnumChildWindows(hWndParent, lpEnumFunc, lParam)
; hWndParent : HWND optional -> "intptr"
; lpEnumFunc : WNDENUMPROC -> "intptr"
; lParam : LPARAM -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procEnumChildWindows = user32.NewProc("EnumChildWindows")
)

// hWndParent (HWND optional), lpEnumFunc (WNDENUMPROC), lParam (LPARAM)
r1, _, err := procEnumChildWindows.Call(
	uintptr(hWndParent),
	uintptr(lpEnumFunc),
	uintptr(lParam),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function EnumChildWindows(
  hWndParent: THandle;   // HWND optional
  lpEnumFunc: Pointer;   // WNDENUMPROC
  lParam: NativeInt   // LPARAM
): BOOL; stdcall;
  external 'USER32.dll' name 'EnumChildWindows';
result := DllCall("USER32\EnumChildWindows"
    , "Ptr", hWndParent   ; HWND optional
    , "Ptr", lpEnumFunc   ; WNDENUMPROC
    , "Ptr", lParam   ; LPARAM
    , "Int")   ; return: BOOL
●EnumChildWindows(hWndParent, lpEnumFunc, lParam) = DLL("USER32.dll", "bool EnumChildWindows(void*, void*, int)")
# 呼び出し: EnumChildWindows(hWndParent, lpEnumFunc, lParam)
# hWndParent : HWND optional -> "void*"
# lpEnumFunc : WNDENUMPROC -> "void*"
# lParam : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "user32" fn EnumChildWindows(
    hWndParent: ?*anyopaque, // HWND optional
    lpEnumFunc: ?*anyopaque, // WNDENUMPROC
    lParam: isize // LPARAM
) callconv(std.os.windows.WINAPI) i32;
proc EnumChildWindows(
    hWndParent: pointer,  # HWND optional
    lpEnumFunc: pointer,  # WNDENUMPROC
    lParam: int  # LPARAM
): int32 {.importc: "EnumChildWindows", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
int EnumChildWindows(
    void* hWndParent,   // HWND optional
    void* lpEnumFunc,   // WNDENUMPROC
    ptrdiff_t lParam   // LPARAM
);
ccall((:EnumChildWindows, "USER32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Int),
      hWndParent, lpEnumFunc, lParam)
# hWndParent : HWND optional -> Ptr{Cvoid}
# lpEnumFunc : WNDENUMPROC -> Ptr{Cvoid}
# lParam : LPARAM -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t EnumChildWindows(
    void* hWndParent,
    void* lpEnumFunc,
    intptr_t lParam);
]]
local user32 = ffi.load("user32")
-- user32.EnumChildWindows(hWndParent, lpEnumFunc, lParam)
-- hWndParent : HWND optional
-- lpEnumFunc : WNDENUMPROC
-- lParam : LPARAM
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const EnumChildWindows = lib.func('__stdcall', 'EnumChildWindows', 'int32_t', ['void *', 'void *', 'intptr_t']);
// EnumChildWindows(hWndParent, lpEnumFunc, lParam)
// hWndParent : HWND optional -> 'void *'
// lpEnumFunc : WNDENUMPROC -> 'void *'
// lParam : LPARAM -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("USER32.dll", {
  EnumChildWindows: { parameters: ["pointer", "pointer", "isize"], result: "i32" },
});
// lib.symbols.EnumChildWindows(hWndParent, lpEnumFunc, lParam)
// hWndParent : HWND optional -> "pointer"
// lpEnumFunc : WNDENUMPROC -> "pointer"
// lParam : LPARAM -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t EnumChildWindows(
    void* hWndParent,
    void* lpEnumFunc,
    intptr_t lParam);
C, "USER32.dll");
// $ffi->EnumChildWindows(hWndParent, lpEnumFunc, lParam);
// hWndParent : HWND optional
// lpEnumFunc : WNDENUMPROC
// 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);
    boolean EnumChildWindows(
        Pointer hWndParent,   // HWND optional
        Callback lpEnumFunc,   // WNDENUMPROC
        long lParam   // LPARAM
    );
}
@[Link("user32")]
lib LibUSER32
  fun EnumChildWindows = EnumChildWindows(
    hWndParent : Void*,   # HWND optional
    lpEnumFunc : Void*,   # WNDENUMPROC
    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 EnumChildWindowsNative = Int32 Function(Pointer<Void>, Pointer<Void>, IntPtr);
typedef EnumChildWindowsDart = int Function(Pointer<Void>, Pointer<Void>, int);
final EnumChildWindows = DynamicLibrary.open('USER32.dll')
    .lookupFunction<EnumChildWindowsNative, EnumChildWindowsDart>('EnumChildWindows');
// hWndParent : HWND optional -> Pointer<Void>
// lpEnumFunc : WNDENUMPROC -> Pointer<Void>
// lParam : LPARAM -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function EnumChildWindows(
  hWndParent: THandle;   // HWND optional
  lpEnumFunc: Pointer;   // WNDENUMPROC
  lParam: NativeInt   // LPARAM
): BOOL; stdcall;
  external 'USER32.dll' name 'EnumChildWindows';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "EnumChildWindows"
  c_EnumChildWindows :: Ptr () -> Ptr () -> CIntPtr -> IO CInt
-- hWndParent : HWND optional -> Ptr ()
-- lpEnumFunc : WNDENUMPROC -> Ptr ()
-- lParam : LPARAM -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let enumchildwindows =
  foreign "EnumChildWindows"
    ((ptr void) @-> (ptr void) @-> intptr_t @-> returning int32_t)
(* hWndParent : HWND optional -> (ptr void) *)
(* lpEnumFunc : WNDENUMPROC -> (ptr void) *)
(* 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 ("EnumChildWindows" enum-child-windows :convention :stdcall) :int32
  (h-wnd-parent :pointer)   ; HWND optional
  (lp-enum-func :pointer)   ; WNDENUMPROC
  (l-param :int64))   ; LPARAM
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $EnumChildWindows = Win32::API::More->new('USER32',
    'BOOL EnumChildWindows(HANDLE hWndParent, LPVOID lpEnumFunc, LPARAM lParam)');
# my $ret = $EnumChildWindows->Call($hWndParent, $lpEnumFunc, $lParam);
# hWndParent : HWND optional -> HANDLE
# lpEnumFunc : WNDENUMPROC -> LPVOID
# lParam : LPARAM -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

公式の関連項目
使用する型