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

GetMonitorInfoA

関数
指定したモニタの情報を取得する(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

BOOL GetMonitorInfoA(
    HMONITOR hMonitor,
    MONITORINFO* lpmi
);

パラメーター

名前方向
hMonitorHMONITORin
lpmiMONITORINFO*inout

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

BOOL GetMonitorInfoA(
    HMONITOR hMonitor,
    MONITORINFO* lpmi
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool GetMonitorInfoA(
    IntPtr hMonitor,   // HMONITOR
    IntPtr lpmi   // MONITORINFO* in/out
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetMonitorInfoA(
    hMonitor As IntPtr,   ' HMONITOR
    lpmi As IntPtr   ' MONITORINFO* in/out
) As Boolean
End Function
' hMonitor : HMONITOR
' lpmi : MONITORINFO* in/out
Declare PtrSafe Function GetMonitorInfoA Lib "user32" ( _
    ByVal hMonitor As LongPtr, _
    ByVal lpmi As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetMonitorInfoA = ctypes.windll.user32.GetMonitorInfoA
GetMonitorInfoA.restype = wintypes.BOOL
GetMonitorInfoA.argtypes = [
    wintypes.HANDLE,  # hMonitor : HMONITOR
    ctypes.c_void_p,  # lpmi : MONITORINFO* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetMonitorInfoA = Fiddle::Function.new(
  lib['GetMonitorInfoA'],
  [
    Fiddle::TYPE_VOIDP,  # hMonitor : HMONITOR
    Fiddle::TYPE_VOIDP,  # lpmi : MONITORINFO* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn GetMonitorInfoA(
        hMonitor: *mut core::ffi::c_void,  // HMONITOR
        lpmi: *mut MONITORINFO  // MONITORINFO* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Ansi)]
public static extern bool GetMonitorInfoA(IntPtr hMonitor, IntPtr lpmi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMonitorInfoA' -Namespace Win32 -PassThru
# $api::GetMonitorInfoA(hMonitor, lpmi)
#uselib "USER32.dll"
#func global GetMonitorInfoA "GetMonitorInfoA" sptr, sptr
; GetMonitorInfoA hMonitor, varptr(lpmi)   ; 戻り値は stat
; hMonitor : HMONITOR -> "sptr"
; lpmi : MONITORINFO* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetMonitorInfoA "GetMonitorInfoA" sptr, var
; res = GetMonitorInfoA(hMonitor, lpmi)
; hMonitor : HMONITOR -> "sptr"
; lpmi : MONITORINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetMonitorInfoA(HMONITOR hMonitor, MONITORINFO* lpmi)
#uselib "USER32.dll"
#cfunc global GetMonitorInfoA "GetMonitorInfoA" intptr, var
; res = GetMonitorInfoA(hMonitor, lpmi)
; hMonitor : HMONITOR -> "intptr"
; lpmi : MONITORINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetMonitorInfoA = user32.NewProc("GetMonitorInfoA")
)

// hMonitor (HMONITOR), lpmi (MONITORINFO* in/out)
r1, _, err := procGetMonitorInfoA.Call(
	uintptr(hMonitor),
	uintptr(lpmi),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetMonitorInfoA(
  hMonitor: THandle;   // HMONITOR
  lpmi: Pointer   // MONITORINFO* in/out
): BOOL; stdcall;
  external 'USER32.dll' name 'GetMonitorInfoA';
result := DllCall("USER32\GetMonitorInfoA"
    , "Ptr", hMonitor   ; HMONITOR
    , "Ptr", lpmi   ; MONITORINFO* in/out
    , "Int")   ; return: BOOL
●GetMonitorInfoA(hMonitor, lpmi) = DLL("USER32.dll", "bool GetMonitorInfoA(void*, void*)")
# 呼び出し: GetMonitorInfoA(hMonitor, lpmi)
# hMonitor : HMONITOR -> "void*"
# lpmi : MONITORINFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。