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

GetDpiForShellUIComponent

関数
シェルUIコンポーネントのDPI値を取得する。
DLLapi-ms-win-shcore-scaling-l1-1-2.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

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

DWORD GetDpiForShellUIComponent(
    SHELL_UI_COMPONENT param0
);

パラメーター

名前方向説明
param0SHELL_UI_COMPONENTinDPIを取得する対象シェルUIコンポーネントを示すSHELL_UI_COMPONENT値。

戻り値の型: DWORD

公式ドキュメント

現在のスケール係数と PROCESS_DPI_AWARENESS に基づいて、SHELL_UI_COMPONENT が占める dpi (dots per inch) を取得します。

戻り値

この種類のアイコンに必要な DPI。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD GetDpiForShellUIComponent(
    SHELL_UI_COMPONENT param0
);
[DllImport("api-ms-win-shcore-scaling-l1-1-2.dll", ExactSpelling = true)]
static extern uint GetDpiForShellUIComponent(
    int param0   // SHELL_UI_COMPONENT
);
<DllImport("api-ms-win-shcore-scaling-l1-1-2.dll", ExactSpelling:=True)>
Public Shared Function GetDpiForShellUIComponent(
    param0 As Integer   ' SHELL_UI_COMPONENT
) As UInteger
End Function
' param0 : SHELL_UI_COMPONENT
Declare PtrSafe Function GetDpiForShellUIComponent Lib "api-ms-win-shcore-scaling-l1-1-2" ( _
    ByVal param0 As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetDpiForShellUIComponent = ctypes.windll.LoadLibrary("api-ms-win-shcore-scaling-l1-1-2.dll").GetDpiForShellUIComponent
GetDpiForShellUIComponent.restype = wintypes.DWORD
GetDpiForShellUIComponent.argtypes = [
    ctypes.c_int,  # param0 : SHELL_UI_COMPONENT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-shcore-scaling-l1-1-2.dll')
GetDpiForShellUIComponent = Fiddle::Function.new(
  lib['GetDpiForShellUIComponent'],
  [
    Fiddle::TYPE_INT,  # param0 : SHELL_UI_COMPONENT
  ],
  -Fiddle::TYPE_INT)
#[link(name = "api-ms-win-shcore-scaling-l1-1-2")]
extern "system" {
    fn GetDpiForShellUIComponent(
        param0: i32  // SHELL_UI_COMPONENT
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-shcore-scaling-l1-1-2.dll")]
public static extern uint GetDpiForShellUIComponent(int param0);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-shcore-scaling-l1-1-2_GetDpiForShellUIComponent' -Namespace Win32 -PassThru
# $api::GetDpiForShellUIComponent(param0)
#uselib "api-ms-win-shcore-scaling-l1-1-2.dll"
#func global GetDpiForShellUIComponent "GetDpiForShellUIComponent" sptr
; GetDpiForShellUIComponent param0   ; 戻り値は stat
; param0 : SHELL_UI_COMPONENT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "api-ms-win-shcore-scaling-l1-1-2.dll"
#cfunc global GetDpiForShellUIComponent "GetDpiForShellUIComponent" int
; res = GetDpiForShellUIComponent(param0)
; param0 : SHELL_UI_COMPONENT -> "int"
; DWORD GetDpiForShellUIComponent(SHELL_UI_COMPONENT param0)
#uselib "api-ms-win-shcore-scaling-l1-1-2.dll"
#cfunc global GetDpiForShellUIComponent "GetDpiForShellUIComponent" int
; res = GetDpiForShellUIComponent(param0)
; param0 : SHELL_UI_COMPONENT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_shcore_scaling_l1_1_2 = windows.NewLazySystemDLL("api-ms-win-shcore-scaling-l1-1-2.dll")
	procGetDpiForShellUIComponent = api_ms_win_shcore_scaling_l1_1_2.NewProc("GetDpiForShellUIComponent")
)

// param0 (SHELL_UI_COMPONENT)
r1, _, err := procGetDpiForShellUIComponent.Call(
	uintptr(param0),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetDpiForShellUIComponent(
  param0: Integer   // SHELL_UI_COMPONENT
): DWORD; stdcall;
  external 'api-ms-win-shcore-scaling-l1-1-2.dll' name 'GetDpiForShellUIComponent';
result := DllCall("api-ms-win-shcore-scaling-l1-1-2\GetDpiForShellUIComponent"
    , "Int", param0   ; SHELL_UI_COMPONENT
    , "UInt")   ; return: DWORD
●GetDpiForShellUIComponent(param0) = DLL("api-ms-win-shcore-scaling-l1-1-2.dll", "dword GetDpiForShellUIComponent(int)")
# 呼び出し: GetDpiForShellUIComponent(param0)
# param0 : SHELL_UI_COMPONENT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "api-ms-win-shcore-scaling-l1-1-2" fn GetDpiForShellUIComponent(
    param0: i32 // SHELL_UI_COMPONENT
) callconv(std.os.windows.WINAPI) u32;
proc GetDpiForShellUIComponent(
    param0: int32  # SHELL_UI_COMPONENT
): uint32 {.importc: "GetDpiForShellUIComponent", stdcall, dynlib: "api-ms-win-shcore-scaling-l1-1-2.dll".}
pragma(lib, "api-ms-win-shcore-scaling-l1-1-2");
extern(Windows)
uint GetDpiForShellUIComponent(
    int param0   // SHELL_UI_COMPONENT
);
ccall((:GetDpiForShellUIComponent, "api-ms-win-shcore-scaling-l1-1-2.dll"), stdcall, UInt32,
      (Int32,),
      param0)
# param0 : SHELL_UI_COMPONENT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetDpiForShellUIComponent(
    int32_t param0);
]]
local api-ms-win-shcore-scaling-l1-1-2 = ffi.load("api-ms-win-shcore-scaling-l1-1-2")
-- api-ms-win-shcore-scaling-l1-1-2.GetDpiForShellUIComponent(param0)
-- param0 : SHELL_UI_COMPONENT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-shcore-scaling-l1-1-2.dll');
const GetDpiForShellUIComponent = lib.func('__stdcall', 'GetDpiForShellUIComponent', 'uint32_t', ['int32_t']);
// GetDpiForShellUIComponent(param0)
// param0 : SHELL_UI_COMPONENT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-shcore-scaling-l1-1-2.dll", {
  GetDpiForShellUIComponent: { parameters: ["i32"], result: "u32" },
});
// lib.symbols.GetDpiForShellUIComponent(param0)
// param0 : SHELL_UI_COMPONENT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetDpiForShellUIComponent(
    int32_t param0);
C, "api-ms-win-shcore-scaling-l1-1-2.dll");
// $ffi->GetDpiForShellUIComponent(param0);
// param0 : SHELL_UI_COMPONENT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Api-ms-win-shcore-scaling-l1-1-2 extends StdCallLibrary {
    Api-ms-win-shcore-scaling-l1-1-2 INSTANCE = Native.load("api-ms-win-shcore-scaling-l1-1-2", Api-ms-win-shcore-scaling-l1-1-2.class);
    int GetDpiForShellUIComponent(
        int param0   // SHELL_UI_COMPONENT
    );
}
@[Link("api-ms-win-shcore-scaling-l1-1-2")]
lib Libapi-ms-win-shcore-scaling-l1-1-2
  fun GetDpiForShellUIComponent = GetDpiForShellUIComponent(
    param0 : Int32   # SHELL_UI_COMPONENT
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetDpiForShellUIComponentNative = Uint32 Function(Int32);
typedef GetDpiForShellUIComponentDart = int Function(int);
final GetDpiForShellUIComponent = DynamicLibrary.open('api-ms-win-shcore-scaling-l1-1-2.dll')
    .lookupFunction<GetDpiForShellUIComponentNative, GetDpiForShellUIComponentDart>('GetDpiForShellUIComponent');
// param0 : SHELL_UI_COMPONENT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetDpiForShellUIComponent(
  param0: Integer   // SHELL_UI_COMPONENT
): DWORD; stdcall;
  external 'api-ms-win-shcore-scaling-l1-1-2.dll' name 'GetDpiForShellUIComponent';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetDpiForShellUIComponent"
  c_GetDpiForShellUIComponent :: Int32 -> IO Word32
-- param0 : SHELL_UI_COMPONENT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getdpiforshelluicomponent =
  foreign "GetDpiForShellUIComponent"
    (int32_t @-> returning uint32_t)
(* param0 : SHELL_UI_COMPONENT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-shcore-scaling-l1-1-2 (t "api-ms-win-shcore-scaling-l1-1-2.dll"))
(cffi:use-foreign-library api-ms-win-shcore-scaling-l1-1-2)

(cffi:defcfun ("GetDpiForShellUIComponent" get-dpi-for-shell-uicomponent :convention :stdcall) :uint32
  (param0 :int32))   ; SHELL_UI_COMPONENT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetDpiForShellUIComponent = Win32::API::More->new('api-ms-win-shcore-scaling-l1-1-2',
    'DWORD GetDpiForShellUIComponent(int param0)');
# my $ret = $GetDpiForShellUIComponent->Call($param0);
# param0 : SHELL_UI_COMPONENT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型