ホーム › UI.WindowsAndMessaging › EnumWindows
EnumWindows
関数全トップレベルウィンドウをコールバックで列挙する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpEnumFunc | WNDENUMPROC | in | 各トップレベルウィンドウごとに呼ばれるコールバック関数へのポインター。 |
| lParam | LPARAM | in | コールバックに渡すアプリ定義の値。 |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EnumWindows(
IntPtr lpEnumFunc, // WNDENUMPROC
IntPtr lParam // LPARAM
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EnumWindows(
lpEnumFunc As IntPtr, ' WNDENUMPROC
lParam As IntPtr ' LPARAM
) As Boolean
End Function' lpEnumFunc : WNDENUMPROC
' lParam : LPARAM
Declare PtrSafe Function EnumWindows Lib "user32" ( _
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
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindows.restype = wintypes.BOOL
EnumWindows.argtypes = [
ctypes.c_void_p, # lpEnumFunc : WNDENUMPROC
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')
EnumWindows = Fiddle::Function.new(
lib['EnumWindows'],
[
Fiddle::TYPE_VOIDP, # lpEnumFunc : WNDENUMPROC
Fiddle::TYPE_INTPTR_T, # lParam : LPARAM
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn EnumWindows(
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", SetLastError = true)]
public static extern bool EnumWindows(IntPtr lpEnumFunc, IntPtr lParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_EnumWindows' -Namespace Win32 -PassThru
# $api::EnumWindows(lpEnumFunc, lParam)#uselib "USER32.dll"
#func global EnumWindows "EnumWindows" sptr, sptr
; EnumWindows lpEnumFunc, lParam ; 戻り値は stat
; lpEnumFunc : WNDENUMPROC -> "sptr"
; lParam : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global EnumWindows "EnumWindows" sptr, sptr
; res = EnumWindows(lpEnumFunc, lParam)
; lpEnumFunc : WNDENUMPROC -> "sptr"
; lParam : LPARAM -> "sptr"; BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)
#uselib "USER32.dll"
#cfunc global EnumWindows "EnumWindows" intptr, intptr
; res = EnumWindows(lpEnumFunc, lParam)
; lpEnumFunc : WNDENUMPROC -> "intptr"
; lParam : LPARAM -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procEnumWindows = user32.NewProc("EnumWindows")
)
// lpEnumFunc (WNDENUMPROC), lParam (LPARAM)
r1, _, err := procEnumWindows.Call(
uintptr(lpEnumFunc),
uintptr(lParam),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction EnumWindows(
lpEnumFunc: Pointer; // WNDENUMPROC
lParam: NativeInt // LPARAM
): BOOL; stdcall;
external 'USER32.dll' name 'EnumWindows';result := DllCall("USER32\EnumWindows"
, "Ptr", lpEnumFunc ; WNDENUMPROC
, "Ptr", lParam ; LPARAM
, "Int") ; return: BOOL●EnumWindows(lpEnumFunc, lParam) = DLL("USER32.dll", "bool EnumWindows(void*, int)")
# 呼び出し: EnumWindows(lpEnumFunc, lParam)
# lpEnumFunc : WNDENUMPROC -> "void*"
# lParam : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。