Win32 API 日本語リファレンス
ホームGraphics.Gdi › EnumDisplayMonitors

EnumDisplayMonitors

関数
表示モニタの集合をコールバックで列挙する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL EnumDisplayMonitors(
    HDC hdc,   // optional
    RECT* lprcClip,   // optional
    MONITORENUMPROC lpfnEnum,
    LPARAM dwData
);

パラメーター

名前方向
hdcHDCinoptional
lprcClipRECT*inoptional
lpfnEnumMONITORENUMPROCin
dwDataLPARAMin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

EnumDisplayMonitors = ctypes.windll.user32.EnumDisplayMonitors
EnumDisplayMonitors.restype = wintypes.BOOL
EnumDisplayMonitors.argtypes = [
    wintypes.HANDLE,  # hdc : HDC optional
    ctypes.c_void_p,  # lprcClip : RECT* optional
    ctypes.c_void_p,  # lpfnEnum : MONITORENUMPROC
    ctypes.c_ssize_t,  # dwData : LPARAM
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
EnumDisplayMonitors = Fiddle::Function.new(
  lib['EnumDisplayMonitors'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC optional
    Fiddle::TYPE_VOIDP,  # lprcClip : RECT* optional
    Fiddle::TYPE_VOIDP,  # lpfnEnum : MONITORENUMPROC
    Fiddle::TYPE_INTPTR_T,  # dwData : LPARAM
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn EnumDisplayMonitors(
        hdc: *mut core::ffi::c_void,  // HDC optional
        lprcClip: *mut RECT,  // RECT* optional
        lpfnEnum: *const core::ffi::c_void,  // MONITORENUMPROC
        dwData: 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 EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, IntPtr lpfnEnum, IntPtr dwData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_EnumDisplayMonitors' -Namespace Win32 -PassThru
# $api::EnumDisplayMonitors(hdc, lprcClip, lpfnEnum, dwData)
#uselib "USER32.dll"
#func global EnumDisplayMonitors "EnumDisplayMonitors" sptr, sptr, sptr, sptr
; EnumDisplayMonitors hdc, varptr(lprcClip), lpfnEnum, dwData   ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; lprcClip : RECT* optional -> "sptr"
; lpfnEnum : MONITORENUMPROC -> "sptr"
; dwData : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global EnumDisplayMonitors "EnumDisplayMonitors" sptr, var, sptr, sptr
; res = EnumDisplayMonitors(hdc, lprcClip, lpfnEnum, dwData)
; hdc : HDC optional -> "sptr"
; lprcClip : RECT* optional -> "var"
; lpfnEnum : MONITORENUMPROC -> "sptr"
; dwData : LPARAM -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL EnumDisplayMonitors(HDC hdc, RECT* lprcClip, MONITORENUMPROC lpfnEnum, LPARAM dwData)
#uselib "USER32.dll"
#cfunc global EnumDisplayMonitors "EnumDisplayMonitors" intptr, var, intptr, intptr
; res = EnumDisplayMonitors(hdc, lprcClip, lpfnEnum, dwData)
; hdc : HDC optional -> "intptr"
; lprcClip : RECT* optional -> "var"
; lpfnEnum : MONITORENUMPROC -> "intptr"
; dwData : LPARAM -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procEnumDisplayMonitors = user32.NewProc("EnumDisplayMonitors")
)

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