GetDpiForMonitor
関数指定モニターのDPI値(X・Y)を取得する。
シグネチャ
// api-ms-win-shcore-scaling-l1-1-1.dll
#include <windows.h>
HRESULT GetDpiForMonitor(
HMONITOR hmonitor,
MONITOR_DPI_TYPE dpiType,
DWORD* dpiX,
DWORD* dpiY
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hmonitor | HMONITOR | in |
| dpiType | MONITOR_DPI_TYPE | in |
| dpiX | DWORD* | out |
| dpiY | DWORD* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// api-ms-win-shcore-scaling-l1-1-1.dll
#include <windows.h>
HRESULT GetDpiForMonitor(
HMONITOR hmonitor,
MONITOR_DPI_TYPE dpiType,
DWORD* dpiX,
DWORD* dpiY
);[DllImport("api-ms-win-shcore-scaling-l1-1-1.dll", ExactSpelling = true)]
static extern int GetDpiForMonitor(
IntPtr hmonitor, // HMONITOR
int dpiType, // MONITOR_DPI_TYPE
out uint dpiX, // DWORD* out
out uint dpiY // DWORD* out
);<DllImport("api-ms-win-shcore-scaling-l1-1-1.dll", ExactSpelling:=True)>
Public Shared Function GetDpiForMonitor(
hmonitor As IntPtr, ' HMONITOR
dpiType As Integer, ' MONITOR_DPI_TYPE
<Out> ByRef dpiX As UInteger, ' DWORD* out
<Out> ByRef dpiY As UInteger ' DWORD* out
) As Integer
End Function' hmonitor : HMONITOR
' dpiType : MONITOR_DPI_TYPE
' dpiX : DWORD* out
' dpiY : DWORD* out
Declare PtrSafe Function GetDpiForMonitor Lib "api-ms-win-shcore-scaling-l1-1-1" ( _
ByVal hmonitor As LongPtr, _
ByVal dpiType As Long, _
ByRef dpiX As Long, _
ByRef dpiY As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDpiForMonitor = ctypes.windll.LoadLibrary("api-ms-win-shcore-scaling-l1-1-1.dll").GetDpiForMonitor
GetDpiForMonitor.restype = ctypes.c_int
GetDpiForMonitor.argtypes = [
wintypes.HANDLE, # hmonitor : HMONITOR
ctypes.c_int, # dpiType : MONITOR_DPI_TYPE
ctypes.POINTER(wintypes.DWORD), # dpiX : DWORD* out
ctypes.POINTER(wintypes.DWORD), # dpiY : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-shcore-scaling-l1-1-1.dll')
GetDpiForMonitor = Fiddle::Function.new(
lib['GetDpiForMonitor'],
[
Fiddle::TYPE_VOIDP, # hmonitor : HMONITOR
Fiddle::TYPE_INT, # dpiType : MONITOR_DPI_TYPE
Fiddle::TYPE_VOIDP, # dpiX : DWORD* out
Fiddle::TYPE_VOIDP, # dpiY : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-shcore-scaling-l1-1-1")]
extern "system" {
fn GetDpiForMonitor(
hmonitor: *mut core::ffi::c_void, // HMONITOR
dpiType: i32, // MONITOR_DPI_TYPE
dpiX: *mut u32, // DWORD* out
dpiY: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-shcore-scaling-l1-1-1.dll")]
public static extern int GetDpiForMonitor(IntPtr hmonitor, int dpiType, out uint dpiX, out uint dpiY);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-shcore-scaling-l1-1-1_GetDpiForMonitor' -Namespace Win32 -PassThru
# $api::GetDpiForMonitor(hmonitor, dpiType, dpiX, dpiY)#uselib "api-ms-win-shcore-scaling-l1-1-1.dll"
#func global GetDpiForMonitor "GetDpiForMonitor" sptr, sptr, sptr, sptr
; GetDpiForMonitor hmonitor, dpiType, varptr(dpiX), varptr(dpiY) ; 戻り値は stat
; hmonitor : HMONITOR -> "sptr"
; dpiType : MONITOR_DPI_TYPE -> "sptr"
; dpiX : DWORD* out -> "sptr"
; dpiY : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-shcore-scaling-l1-1-1.dll" #cfunc global GetDpiForMonitor "GetDpiForMonitor" sptr, int, var, var ; res = GetDpiForMonitor(hmonitor, dpiType, dpiX, dpiY) ; hmonitor : HMONITOR -> "sptr" ; dpiType : MONITOR_DPI_TYPE -> "int" ; dpiX : DWORD* out -> "var" ; dpiY : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-shcore-scaling-l1-1-1.dll" #cfunc global GetDpiForMonitor "GetDpiForMonitor" sptr, int, sptr, sptr ; res = GetDpiForMonitor(hmonitor, dpiType, varptr(dpiX), varptr(dpiY)) ; hmonitor : HMONITOR -> "sptr" ; dpiType : MONITOR_DPI_TYPE -> "int" ; dpiX : DWORD* out -> "sptr" ; dpiY : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetDpiForMonitor(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, DWORD* dpiX, DWORD* dpiY) #uselib "api-ms-win-shcore-scaling-l1-1-1.dll" #cfunc global GetDpiForMonitor "GetDpiForMonitor" intptr, int, var, var ; res = GetDpiForMonitor(hmonitor, dpiType, dpiX, dpiY) ; hmonitor : HMONITOR -> "intptr" ; dpiType : MONITOR_DPI_TYPE -> "int" ; dpiX : DWORD* out -> "var" ; dpiY : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetDpiForMonitor(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, DWORD* dpiX, DWORD* dpiY) #uselib "api-ms-win-shcore-scaling-l1-1-1.dll" #cfunc global GetDpiForMonitor "GetDpiForMonitor" intptr, int, intptr, intptr ; res = GetDpiForMonitor(hmonitor, dpiType, varptr(dpiX), varptr(dpiY)) ; hmonitor : HMONITOR -> "intptr" ; dpiType : MONITOR_DPI_TYPE -> "int" ; dpiX : DWORD* out -> "intptr" ; dpiY : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_shcore_scaling_l1_1_1 = windows.NewLazySystemDLL("api-ms-win-shcore-scaling-l1-1-1.dll")
procGetDpiForMonitor = api_ms_win_shcore_scaling_l1_1_1.NewProc("GetDpiForMonitor")
)
// hmonitor (HMONITOR), dpiType (MONITOR_DPI_TYPE), dpiX (DWORD* out), dpiY (DWORD* out)
r1, _, err := procGetDpiForMonitor.Call(
uintptr(hmonitor),
uintptr(dpiType),
uintptr(dpiX),
uintptr(dpiY),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetDpiForMonitor(
hmonitor: THandle; // HMONITOR
dpiType: Integer; // MONITOR_DPI_TYPE
dpiX: Pointer; // DWORD* out
dpiY: Pointer // DWORD* out
): Integer; stdcall;
external 'api-ms-win-shcore-scaling-l1-1-1.dll' name 'GetDpiForMonitor';result := DllCall("api-ms-win-shcore-scaling-l1-1-1\GetDpiForMonitor"
, "Ptr", hmonitor ; HMONITOR
, "Int", dpiType ; MONITOR_DPI_TYPE
, "Ptr", dpiX ; DWORD* out
, "Ptr", dpiY ; DWORD* out
, "Int") ; return: HRESULT●GetDpiForMonitor(hmonitor, dpiType, dpiX, dpiY) = DLL("api-ms-win-shcore-scaling-l1-1-1.dll", "int GetDpiForMonitor(void*, int, void*, void*)")
# 呼び出し: GetDpiForMonitor(hmonitor, dpiType, dpiX, dpiY)
# hmonitor : HMONITOR -> "void*"
# dpiType : MONITOR_DPI_TYPE -> "int"
# dpiX : DWORD* out -> "void*"
# dpiY : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。