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

GetThemeMetric

関数
指定プロパティのテーマメトリクス(整数値)を取得する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// UXTHEME.dll
#include <windows.h>

HRESULT GetThemeMetric(
    HTHEME hTheme,
    HDC hdc,   // optional
    INT iPartId,
    INT iStateId,
    INT iPropId,
    INT* piVal
);

パラメーター

名前方向説明
hThemeHTHEMEinウィンドウの指定したテーマデータへのハンドルです。HTHEME を作成するには OpenThemeData を使用します。
hdcHDCinoptionalHDC です。このパラメーターには NULL を指定できます。
iPartIdINTinメトリックプロパティを含むパーツを指定する int 型の値です。Parts and States を参照してください。
iStateIdINTinパーツの状態を指定する int 型の値です。Parts and States を参照してください。
iPropIdINTin

取得するプロパティを指定する int 型の値です。次のいずれかの値を指定できます。

説明
TMT_ALPHALEVEL
DrawThemeIcon に使用されるアルファ値 (0~255) です。
TMT_ALPHATHRESHOLD
ピクセルを不透明とみなすために必要な最小アルファ値 (0~255) です。
TMT_BORDERSIZE
このパーツがボーダーフィルを使用する場合に描画されるボーダーの太さです。
TMT_GLYPHINDEX
パーツがフォントベースのグリフを使用する場合に、グリフに使用される、選択されたフォント内の文字インデックスです。
TMT_GRADIENTRATIO1
パーツの描画に使用する 1 番目のグラデーション色の割合です。この値は 0 から 255 まで指定できますが、この値と各 GRADIENTRATIO 値の合計が 255 にならなければなりません。GetThemeColorTMT_GRADIENTCOLOR1 値を参照してください。
TMT_GRADIENTRATIO2
パーツの描画に使用する 2 番目のグラデーション色の割合です。
TMT_GRADIENTRATIO3
パーツの描画に使用する 3 番目のグラデーション色の割合です。
TMT_GRADIENTRATIO4
パーツの描画に使用する 4 番目のグラデーション色の割合です。
TMT_GRADIENTRATIO5
パーツの描画に使用する 5 番目のグラデーション色の割合です。
TMT_HEIGHT
パーツの高さです。
TMT_IMAGECOUNT
画像ファイルに含まれる状態イメージの数です。
TMT_MINDPI1
1 番目の画像ファイルが設計された最小 dpi です。GetThemeFilename を参照してください。
TMT_MINDPI2
2 番目の画像ファイルが設計された最小 dpi です。
TMT_MINDPI3
3 番目の画像ファイルが設計された最小 dpi です。
TMT_MINDPI4
4 番目の画像ファイルが設計された最小 dpi です。
TMT_MINDPI5
5 番目の画像ファイルが設計された最小 dpi です。
TMT_PROGRESSCHUNKSIZE
操作の進捗度合いを表すプログレスコントロールの「チャンク」形状のサイズです。
TMT_PROGRESSSPACESIZE
プログレスコントロールのすべての「チャンク」を合わせた全体のサイズです。
TMT_ROUNDCORNERWIDTH
パーツの角の丸み (0~100%) です。
TMT_ROUNDCORNERHEIGHT
パーツの角の丸み (0~100%) です。
TMT_SATURATION
DrawThemeIcon を使用して描画されるアイコンに適用する彩度 (0~255) の量です。
TMT_TEXTBORDERSIZE
テキスト文字の周囲に描画されるボーダーの太さです。
TMT_TRUESIZESTRETCHMARK
true-size イメージが引き伸ばされる、元のサイズに対する割合 (パーセント) です。
TMT_WIDTH
パーツの幅です。
piValINT*outメトリックプロパティの値を受け取る int へのポインターです。

戻り値の型: HRESULT

公式ドキュメント

メトリックプロパティの値を取得します。

戻り値

型: HRESULT

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

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

各言語での呼び出し定義

// UXTHEME.dll
#include <windows.h>

HRESULT GetThemeMetric(
    HTHEME hTheme,
    HDC hdc,   // optional
    INT iPartId,
    INT iStateId,
    INT iPropId,
    INT* piVal
);
[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern int GetThemeMetric(
    IntPtr hTheme,   // HTHEME
    IntPtr hdc,   // HDC optional
    int iPartId,   // INT
    int iStateId,   // INT
    int iPropId,   // INT
    out int piVal   // INT* out
);
<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function GetThemeMetric(
    hTheme As IntPtr,   ' HTHEME
    hdc As IntPtr,   ' HDC optional
    iPartId As Integer,   ' INT
    iStateId As Integer,   ' INT
    iPropId As Integer,   ' INT
    <Out> ByRef piVal As Integer   ' INT* out
) As Integer
End Function
' hTheme : HTHEME
' hdc : HDC optional
' iPartId : INT
' iStateId : INT
' iPropId : INT
' piVal : INT* out
Declare PtrSafe Function GetThemeMetric Lib "uxtheme" ( _
    ByVal hTheme As LongPtr, _
    ByVal hdc As LongPtr, _
    ByVal iPartId As Long, _
    ByVal iStateId As Long, _
    ByVal iPropId As Long, _
    ByRef piVal As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetThemeMetric = ctypes.windll.uxtheme.GetThemeMetric
GetThemeMetric.restype = ctypes.c_int
GetThemeMetric.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME
    wintypes.HANDLE,  # hdc : HDC optional
    ctypes.c_int,  # iPartId : INT
    ctypes.c_int,  # iStateId : INT
    ctypes.c_int,  # iPropId : INT
    ctypes.POINTER(ctypes.c_int),  # piVal : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UXTHEME.dll')
GetThemeMetric = Fiddle::Function.new(
  lib['GetThemeMetric'],
  [
    Fiddle::TYPE_INTPTR_T,  # hTheme : HTHEME
    Fiddle::TYPE_VOIDP,  # hdc : HDC optional
    Fiddle::TYPE_INT,  # iPartId : INT
    Fiddle::TYPE_INT,  # iStateId : INT
    Fiddle::TYPE_INT,  # iPropId : INT
    Fiddle::TYPE_VOIDP,  # piVal : INT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "uxtheme")]
extern "system" {
    fn GetThemeMetric(
        hTheme: isize,  // HTHEME
        hdc: *mut core::ffi::c_void,  // HDC optional
        iPartId: i32,  // INT
        iStateId: i32,  // INT
        iPropId: i32,  // INT
        piVal: *mut i32  // INT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UXTHEME.dll")]
public static extern int GetThemeMetric(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, int iPropId, out int piVal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UXTHEME_GetThemeMetric' -Namespace Win32 -PassThru
# $api::GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
#uselib "UXTHEME.dll"
#func global GetThemeMetric "GetThemeMetric" sptr, sptr, sptr, sptr, sptr, sptr
; GetThemeMetric hTheme, hdc, iPartId, iStateId, iPropId, varptr(piVal)   ; 戻り値は stat
; hTheme : HTHEME -> "sptr"
; hdc : HDC optional -> "sptr"
; iPartId : INT -> "sptr"
; iStateId : INT -> "sptr"
; iPropId : INT -> "sptr"
; piVal : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UXTHEME.dll"
#cfunc global GetThemeMetric "GetThemeMetric" sptr, sptr, int, int, int, var
; res = GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
; hTheme : HTHEME -> "sptr"
; hdc : HDC optional -> "sptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; iPropId : INT -> "int"
; piVal : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT GetThemeMetric(HTHEME hTheme, HDC hdc, INT iPartId, INT iStateId, INT iPropId, INT* piVal)
#uselib "UXTHEME.dll"
#cfunc global GetThemeMetric "GetThemeMetric" intptr, intptr, int, int, int, var
; res = GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
; hTheme : HTHEME -> "intptr"
; hdc : HDC optional -> "intptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; iPropId : INT -> "int"
; piVal : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procGetThemeMetric = uxtheme.NewProc("GetThemeMetric")
)

// hTheme (HTHEME), hdc (HDC optional), iPartId (INT), iStateId (INT), iPropId (INT), piVal (INT* out)
r1, _, err := procGetThemeMetric.Call(
	uintptr(hTheme),
	uintptr(hdc),
	uintptr(iPartId),
	uintptr(iStateId),
	uintptr(iPropId),
	uintptr(piVal),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetThemeMetric(
  hTheme: NativeInt;   // HTHEME
  hdc: THandle;   // HDC optional
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  iPropId: Integer;   // INT
  piVal: Pointer   // INT* out
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeMetric';
result := DllCall("UXTHEME\GetThemeMetric"
    , "Ptr", hTheme   ; HTHEME
    , "Ptr", hdc   ; HDC optional
    , "Int", iPartId   ; INT
    , "Int", iStateId   ; INT
    , "Int", iPropId   ; INT
    , "Ptr", piVal   ; INT* out
    , "Int")   ; return: HRESULT
●GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal) = DLL("UXTHEME.dll", "int GetThemeMetric(int, void*, int, int, int, void*)")
# 呼び出し: GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
# hTheme : HTHEME -> "int"
# hdc : HDC optional -> "void*"
# iPartId : INT -> "int"
# iStateId : INT -> "int"
# iPropId : INT -> "int"
# piVal : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "uxtheme" fn GetThemeMetric(
    hTheme: isize, // HTHEME
    hdc: ?*anyopaque, // HDC optional
    iPartId: i32, // INT
    iStateId: i32, // INT
    iPropId: i32, // INT
    piVal: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;
proc GetThemeMetric(
    hTheme: int,  # HTHEME
    hdc: pointer,  # HDC optional
    iPartId: int32,  # INT
    iStateId: int32,  # INT
    iPropId: int32,  # INT
    piVal: ptr int32  # INT* out
): int32 {.importc: "GetThemeMetric", stdcall, dynlib: "UXTHEME.dll".}
pragma(lib, "uxtheme");
extern(Windows)
int GetThemeMetric(
    ptrdiff_t hTheme,   // HTHEME
    void* hdc,   // HDC optional
    int iPartId,   // INT
    int iStateId,   // INT
    int iPropId,   // INT
    int* piVal   // INT* out
);
ccall((:GetThemeMetric, "UXTHEME.dll"), stdcall, Int32,
      (Int, Ptr{Cvoid}, Int32, Int32, Int32, Ptr{Int32}),
      hTheme, hdc, iPartId, iStateId, iPropId, piVal)
# hTheme : HTHEME -> Int
# hdc : HDC optional -> Ptr{Cvoid}
# iPartId : INT -> Int32
# iStateId : INT -> Int32
# iPropId : INT -> Int32
# piVal : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetThemeMetric(
    intptr_t hTheme,
    void* hdc,
    int32_t iPartId,
    int32_t iStateId,
    int32_t iPropId,
    int32_t* piVal);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
-- hTheme : HTHEME
-- hdc : HDC optional
-- iPartId : INT
-- iStateId : INT
-- iPropId : INT
-- piVal : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const GetThemeMetric = lib.func('__stdcall', 'GetThemeMetric', 'int32_t', ['intptr_t', 'void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t *']);
// GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
// hTheme : HTHEME -> 'intptr_t'
// hdc : HDC optional -> 'void *'
// iPartId : INT -> 'int32_t'
// iStateId : INT -> 'int32_t'
// iPropId : INT -> 'int32_t'
// piVal : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UXTHEME.dll", {
  GetThemeMetric: { parameters: ["isize", "pointer", "i32", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal)
// hTheme : HTHEME -> "isize"
// hdc : HDC optional -> "pointer"
// iPartId : INT -> "i32"
// iStateId : INT -> "i32"
// iPropId : INT -> "i32"
// piVal : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetThemeMetric(
    intptr_t hTheme,
    void* hdc,
    int32_t iPartId,
    int32_t iStateId,
    int32_t iPropId,
    int32_t* piVal);
C, "UXTHEME.dll");
// $ffi->GetThemeMetric(hTheme, hdc, iPartId, iStateId, iPropId, piVal);
// hTheme : HTHEME
// hdc : HDC optional
// iPartId : INT
// iStateId : INT
// iPropId : INT
// piVal : INT* out
// 構造体/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 Uxtheme extends StdCallLibrary {
    Uxtheme INSTANCE = Native.load("uxtheme", Uxtheme.class);
    int GetThemeMetric(
        long hTheme,   // HTHEME
        Pointer hdc,   // HDC optional
        int iPartId,   // INT
        int iStateId,   // INT
        int iPropId,   // INT
        IntByReference piVal   // INT* out
    );
}
@[Link("uxtheme")]
lib LibUXTHEME
  fun GetThemeMetric = GetThemeMetric(
    hTheme : LibC::SSizeT,   # HTHEME
    hdc : Void*,   # HDC optional
    iPartId : Int32,   # INT
    iStateId : Int32,   # INT
    iPropId : Int32,   # INT
    piVal : Int32*   # INT* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetThemeMetricNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Int32, Int32, Pointer<Int32>);
typedef GetThemeMetricDart = int Function(int, Pointer<Void>, int, int, int, Pointer<Int32>);
final GetThemeMetric = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<GetThemeMetricNative, GetThemeMetricDart>('GetThemeMetric');
// hTheme : HTHEME -> IntPtr
// hdc : HDC optional -> Pointer<Void>
// iPartId : INT -> Int32
// iStateId : INT -> Int32
// iPropId : INT -> Int32
// piVal : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetThemeMetric(
  hTheme: NativeInt;   // HTHEME
  hdc: THandle;   // HDC optional
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  iPropId: Integer;   // INT
  piVal: Pointer   // INT* out
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeMetric';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetThemeMetric"
  c_GetThemeMetric :: CIntPtr -> Ptr () -> Int32 -> Int32 -> Int32 -> Ptr Int32 -> IO Int32
-- hTheme : HTHEME -> CIntPtr
-- hdc : HDC optional -> Ptr ()
-- iPartId : INT -> Int32
-- iStateId : INT -> Int32
-- iPropId : INT -> Int32
-- piVal : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getthememetric =
  foreign "GetThemeMetric"
    (intptr_t @-> (ptr void) @-> int32_t @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* hTheme : HTHEME -> intptr_t *)
(* hdc : HDC optional -> (ptr void) *)
(* iPartId : INT -> int32_t *)
(* iStateId : INT -> int32_t *)
(* iPropId : INT -> int32_t *)
(* piVal : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)

(cffi:defcfun ("GetThemeMetric" get-theme-metric :convention :stdcall) :int32
  (h-theme :int64)   ; HTHEME
  (hdc :pointer)   ; HDC optional
  (i-part-id :int32)   ; INT
  (i-state-id :int32)   ; INT
  (i-prop-id :int32)   ; INT
  (pi-val :pointer))   ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetThemeMetric = Win32::API::More->new('UXTHEME',
    'int GetThemeMetric(LPARAM hTheme, HANDLE hdc, int iPartId, int iStateId, int iPropId, LPVOID piVal)');
# my $ret = $GetThemeMetric->Call($hTheme, $hdc, $iPartId, $iStateId, $iPropId, $piVal);
# hTheme : HTHEME -> LPARAM
# hdc : HDC optional -> HANDLE
# iPartId : INT -> int
# iStateId : INT -> int
# iPropId : INT -> int
# piVal : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。