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

GetThemeSysFont

関数
テーマで定義されたシステムフォント情報を取得する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT GetThemeSysFont(
    HTHEME hTheme,   // optional
    INT iFontId,
    LOGFONTW* plf
);

パラメーター

名前方向説明
hThemeHTHEMEinoptionalテーマデータへのハンドルです。
iFontIdINTin

システムフォントを指定する int 型の値です。次のいずれかの値を指定できます。

意味
TMT_CAPTIONFONT
ウィンドウのキャプションで使用されるフォント。
TMT_SMALLCAPTIONFONT
ウィンドウの小さいキャプションで使用されるフォント。
TMT_MENUFONT
メニューで使用されるフォント。
TMT_STATUSFONT
ステータスメッセージで使用されるフォント。
TMT_MSGBOXFONT
メッセージボックスにメッセージを表示するために使用されるフォント。
TMT_ICONTITLEFONT
アイコンで使用されるフォント。
plfLOGFONTW*outこの関数からフォント情報を受け取る LOGFONT 構造体へのポインターです。

戻り値の型: HRESULT

公式ドキュメント

システムフォントの LOGFONT を取得します。

戻り値

種類: HRESULT

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

解説(Remarks)

この関数には vssym32.h と uxtheme.h が必要です。

テーマデータのハンドルが NULL ハンドルでない場合、この関数はビジュアルスタイルの SysMetrics セクションから目的の LOGFONT を返します。テーマデータのハンドルが NULL の場合、この関数は同じ種類のグローバルシステムメトリックの値を返します。

フォントは、現在の論理画面の dots per inch (DPI) に合わせてスケーリングされます。

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

各言語での呼び出し定義

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

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

GetThemeSysFont = ctypes.windll.uxtheme.GetThemeSysFont
GetThemeSysFont.restype = ctypes.c_int
GetThemeSysFont.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME optional
    ctypes.c_int,  # iFontId : INT
    ctypes.c_void_p,  # plf : LOGFONTW* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procGetThemeSysFont = uxtheme.NewProc("GetThemeSysFont")
)

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

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

typedef GetThemeSysFontNative = Int32 Function(IntPtr, Int32, Pointer<Void>);
typedef GetThemeSysFontDart = int Function(int, int, Pointer<Void>);
final GetThemeSysFont = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<GetThemeSysFontNative, GetThemeSysFontDart>('GetThemeSysFont');
// hTheme : HTHEME optional -> IntPtr
// iFontId : INT -> Int32
// plf : LOGFONTW* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetThemeSysFont(
  hTheme: NativeInt;   // HTHEME optional
  iFontId: Integer;   // INT
  plf: Pointer   // LOGFONTW* out
): Integer; stdcall;
  external 'UXTHEME.dll' name 'GetThemeSysFont';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetThemeSysFont"
  c_GetThemeSysFont :: CIntPtr -> Int32 -> Ptr () -> IO Int32
-- hTheme : HTHEME optional -> CIntPtr
-- iFontId : INT -> Int32
-- plf : LOGFONTW* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("GetThemeSysFont" get-theme-sys-font :convention :stdcall) :int32
  (h-theme :int64)   ; HTHEME optional
  (i-font-id :int32)   ; INT
  (plf :pointer))   ; LOGFONTW* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetThemeSysFont = Win32::API::More->new('UXTHEME',
    'int GetThemeSysFont(LPARAM hTheme, int iFontId, LPVOID plf)');
# my $ret = $GetThemeSysFont->Call($hTheme, $iFontId, $plf);
# hTheme : HTHEME optional -> LPARAM
# iFontId : INT -> int
# plf : LOGFONTW* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型