Win32 API 日本語リファレンス
ホームUI.Shell › GetScaleFactorForMonitor

GetScaleFactorForMonitor

関数
指定モニターの表示スケール係数を取得する。
DLLapi-ms-win-shcore-scaling-l1-1-1.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

// api-ms-win-shcore-scaling-l1-1-1.dll
#include <windows.h>

HRESULT GetScaleFactorForMonitor(
    HMONITOR hMon,
    DEVICE_SCALE_FACTOR* pScale
);

パラメーター

名前方向
hMonHMONITORin
pScaleDEVICE_SCALE_FACTOR*out

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-shcore-scaling-l1-1-1.dll
#include <windows.h>

HRESULT GetScaleFactorForMonitor(
    HMONITOR hMon,
    DEVICE_SCALE_FACTOR* pScale
);
[DllImport("api-ms-win-shcore-scaling-l1-1-1.dll", ExactSpelling = true)]
static extern int GetScaleFactorForMonitor(
    IntPtr hMon,   // HMONITOR
    out int pScale   // DEVICE_SCALE_FACTOR* out
);
<DllImport("api-ms-win-shcore-scaling-l1-1-1.dll", ExactSpelling:=True)>
Public Shared Function GetScaleFactorForMonitor(
    hMon As IntPtr,   ' HMONITOR
    <Out> ByRef pScale As Integer   ' DEVICE_SCALE_FACTOR* out
) As Integer
End Function
' hMon : HMONITOR
' pScale : DEVICE_SCALE_FACTOR* out
Declare PtrSafe Function GetScaleFactorForMonitor Lib "api-ms-win-shcore-scaling-l1-1-1" ( _
    ByVal hMon As LongPtr, _
    ByRef pScale As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetScaleFactorForMonitor = ctypes.windll.LoadLibrary("api-ms-win-shcore-scaling-l1-1-1.dll").GetScaleFactorForMonitor
GetScaleFactorForMonitor.restype = ctypes.c_int
GetScaleFactorForMonitor.argtypes = [
    wintypes.HANDLE,  # hMon : HMONITOR
    ctypes.c_void_p,  # pScale : DEVICE_SCALE_FACTOR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-shcore-scaling-l1-1-1.dll')
GetScaleFactorForMonitor = Fiddle::Function.new(
  lib['GetScaleFactorForMonitor'],
  [
    Fiddle::TYPE_VOIDP,  # hMon : HMONITOR
    Fiddle::TYPE_VOIDP,  # pScale : DEVICE_SCALE_FACTOR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-shcore-scaling-l1-1-1")]
extern "system" {
    fn GetScaleFactorForMonitor(
        hMon: *mut core::ffi::c_void,  // HMONITOR
        pScale: *mut i32  // DEVICE_SCALE_FACTOR* 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 GetScaleFactorForMonitor(IntPtr hMon, out int pScale);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-shcore-scaling-l1-1-1_GetScaleFactorForMonitor' -Namespace Win32 -PassThru
# $api::GetScaleFactorForMonitor(hMon, pScale)
#uselib "api-ms-win-shcore-scaling-l1-1-1.dll"
#func global GetScaleFactorForMonitor "GetScaleFactorForMonitor" sptr, sptr
; GetScaleFactorForMonitor hMon, pScale   ; 戻り値は stat
; hMon : HMONITOR -> "sptr"
; pScale : DEVICE_SCALE_FACTOR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "api-ms-win-shcore-scaling-l1-1-1.dll"
#cfunc global GetScaleFactorForMonitor "GetScaleFactorForMonitor" sptr, int
; res = GetScaleFactorForMonitor(hMon, pScale)
; hMon : HMONITOR -> "sptr"
; pScale : DEVICE_SCALE_FACTOR* out -> "int"
; HRESULT GetScaleFactorForMonitor(HMONITOR hMon, DEVICE_SCALE_FACTOR* pScale)
#uselib "api-ms-win-shcore-scaling-l1-1-1.dll"
#cfunc global GetScaleFactorForMonitor "GetScaleFactorForMonitor" intptr, int
; res = GetScaleFactorForMonitor(hMon, pScale)
; hMon : HMONITOR -> "intptr"
; pScale : DEVICE_SCALE_FACTOR* out -> "int"
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")
	procGetScaleFactorForMonitor = api_ms_win_shcore_scaling_l1_1_1.NewProc("GetScaleFactorForMonitor")
)

// hMon (HMONITOR), pScale (DEVICE_SCALE_FACTOR* out)
r1, _, err := procGetScaleFactorForMonitor.Call(
	uintptr(hMon),
	uintptr(pScale),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetScaleFactorForMonitor(
  hMon: THandle;   // HMONITOR
  pScale: Pointer   // DEVICE_SCALE_FACTOR* out
): Integer; stdcall;
  external 'api-ms-win-shcore-scaling-l1-1-1.dll' name 'GetScaleFactorForMonitor';
result := DllCall("api-ms-win-shcore-scaling-l1-1-1\GetScaleFactorForMonitor"
    , "Ptr", hMon   ; HMONITOR
    , "Ptr", pScale   ; DEVICE_SCALE_FACTOR* out
    , "Int")   ; return: HRESULT
●GetScaleFactorForMonitor(hMon, pScale) = DLL("api-ms-win-shcore-scaling-l1-1-1.dll", "int GetScaleFactorForMonitor(void*, void*)")
# 呼び出し: GetScaleFactorForMonitor(hMon, pScale)
# hMon : HMONITOR -> "void*"
# pScale : DEVICE_SCALE_FACTOR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。