ホーム › Graphics.Gdi › GetMonitorInfoW
GetMonitorInfoW
関数指定したモニタの情報を取得する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL GetMonitorInfoW(
HMONITOR hMonitor,
MONITORINFO* lpmi
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hMonitor | HMONITOR | in |
| lpmi | MONITORINFO* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL GetMonitorInfoW(
HMONITOR hMonitor,
MONITORINFO* lpmi
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetMonitorInfoW(
IntPtr hMonitor, // HMONITOR
IntPtr lpmi // MONITORINFO* in/out
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetMonitorInfoW(
hMonitor As IntPtr, ' HMONITOR
lpmi As IntPtr ' MONITORINFO* in/out
) As Boolean
End Function' hMonitor : HMONITOR
' lpmi : MONITORINFO* in/out
Declare PtrSafe Function GetMonitorInfoW Lib "user32" ( _
ByVal hMonitor As LongPtr, _
ByVal lpmi As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetMonitorInfoW = ctypes.windll.user32.GetMonitorInfoW
GetMonitorInfoW.restype = wintypes.BOOL
GetMonitorInfoW.argtypes = [
wintypes.HANDLE, # hMonitor : HMONITOR
ctypes.c_void_p, # lpmi : MONITORINFO* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetMonitorInfoW = Fiddle::Function.new(
lib['GetMonitorInfoW'],
[
Fiddle::TYPE_VOIDP, # hMonitor : HMONITOR
Fiddle::TYPE_VOIDP, # lpmi : MONITORINFO* in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn GetMonitorInfoW(
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.Unicode)]
public static extern bool GetMonitorInfoW(IntPtr hMonitor, IntPtr lpmi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMonitorInfoW' -Namespace Win32 -PassThru
# $api::GetMonitorInfoW(hMonitor, lpmi)#uselib "USER32.dll"
#func global GetMonitorInfoW "GetMonitorInfoW" wptr, wptr
; GetMonitorInfoW hMonitor, varptr(lpmi) ; 戻り値は stat
; hMonitor : HMONITOR -> "wptr"
; lpmi : MONITORINFO* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global GetMonitorInfoW "GetMonitorInfoW" sptr, var ; res = GetMonitorInfoW(hMonitor, lpmi) ; hMonitor : HMONITOR -> "sptr" ; lpmi : MONITORINFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global GetMonitorInfoW "GetMonitorInfoW" sptr, sptr ; res = GetMonitorInfoW(hMonitor, varptr(lpmi)) ; hMonitor : HMONITOR -> "sptr" ; lpmi : MONITORINFO* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetMonitorInfoW(HMONITOR hMonitor, MONITORINFO* lpmi) #uselib "USER32.dll" #cfunc global GetMonitorInfoW "GetMonitorInfoW" intptr, var ; res = GetMonitorInfoW(hMonitor, lpmi) ; hMonitor : HMONITOR -> "intptr" ; lpmi : MONITORINFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetMonitorInfoW(HMONITOR hMonitor, MONITORINFO* lpmi) #uselib "USER32.dll" #cfunc global GetMonitorInfoW "GetMonitorInfoW" intptr, intptr ; res = GetMonitorInfoW(hMonitor, varptr(lpmi)) ; hMonitor : HMONITOR -> "intptr" ; lpmi : MONITORINFO* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
)
// hMonitor (HMONITOR), lpmi (MONITORINFO* in/out)
r1, _, err := procGetMonitorInfoW.Call(
uintptr(hMonitor),
uintptr(lpmi),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetMonitorInfoW(
hMonitor: THandle; // HMONITOR
lpmi: Pointer // MONITORINFO* in/out
): BOOL; stdcall;
external 'USER32.dll' name 'GetMonitorInfoW';result := DllCall("USER32\GetMonitorInfoW"
, "Ptr", hMonitor ; HMONITOR
, "Ptr", lpmi ; MONITORINFO* in/out
, "Int") ; return: BOOL●GetMonitorInfoW(hMonitor, lpmi) = DLL("USER32.dll", "bool GetMonitorInfoW(void*, void*)")
# 呼び出し: GetMonitorInfoW(hMonitor, lpmi)
# hMonitor : HMONITOR -> "void*"
# lpmi : MONITORINFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。