ホーム › UI.Controls › GetThemeTextMetrics
GetThemeTextMetrics
関数テーマフォントのテキストメトリクス情報を取得する。
シグネチャ
// UxTheme.dll
#include <windows.h>
HRESULT GetThemeTextMetrics(
HTHEME hTheme,
HDC hdc,
INT iPartId,
INT iStateId,
TEXTMETRICW* ptm
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hTheme | HTHEME | in |
| hdc | HDC | in |
| iPartId | INT | in |
| iStateId | INT | in |
| ptm | TEXTMETRICW* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// UxTheme.dll
#include <windows.h>
HRESULT GetThemeTextMetrics(
HTHEME hTheme,
HDC hdc,
INT iPartId,
INT iStateId,
TEXTMETRICW* ptm
);[DllImport("UxTheme.dll", ExactSpelling = true)]
static extern int GetThemeTextMetrics(
IntPtr hTheme, // HTHEME
IntPtr hdc, // HDC
int iPartId, // INT
int iStateId, // INT
IntPtr ptm // TEXTMETRICW* out
);<DllImport("UxTheme.dll", ExactSpelling:=True)>
Public Shared Function GetThemeTextMetrics(
hTheme As IntPtr, ' HTHEME
hdc As IntPtr, ' HDC
iPartId As Integer, ' INT
iStateId As Integer, ' INT
ptm As IntPtr ' TEXTMETRICW* out
) As Integer
End Function' hTheme : HTHEME
' hdc : HDC
' iPartId : INT
' iStateId : INT
' ptm : TEXTMETRICW* out
Declare PtrSafe Function GetThemeTextMetrics Lib "uxtheme" ( _
ByVal hTheme As LongPtr, _
ByVal hdc As LongPtr, _
ByVal iPartId As Long, _
ByVal iStateId As Long, _
ByVal ptm As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetThemeTextMetrics = ctypes.windll.uxtheme.GetThemeTextMetrics
GetThemeTextMetrics.restype = ctypes.c_int
GetThemeTextMetrics.argtypes = [
ctypes.c_ssize_t, # hTheme : HTHEME
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # iPartId : INT
ctypes.c_int, # iStateId : INT
ctypes.c_void_p, # ptm : TEXTMETRICW* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('UxTheme.dll')
GetThemeTextMetrics = Fiddle::Function.new(
lib['GetThemeTextMetrics'],
[
Fiddle::TYPE_INTPTR_T, # hTheme : HTHEME
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # iPartId : INT
Fiddle::TYPE_INT, # iStateId : INT
Fiddle::TYPE_VOIDP, # ptm : TEXTMETRICW* out
],
Fiddle::TYPE_INT)#[link(name = "uxtheme")]
extern "system" {
fn GetThemeTextMetrics(
hTheme: isize, // HTHEME
hdc: *mut core::ffi::c_void, // HDC
iPartId: i32, // INT
iStateId: i32, // INT
ptm: *mut TEXTMETRICW // TEXTMETRICW* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("UxTheme.dll")]
public static extern int GetThemeTextMetrics(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, IntPtr ptm);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UxTheme_GetThemeTextMetrics' -Namespace Win32 -PassThru
# $api::GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, ptm)#uselib "UxTheme.dll"
#func global GetThemeTextMetrics "GetThemeTextMetrics" sptr, sptr, sptr, sptr, sptr
; GetThemeTextMetrics hTheme, hdc, iPartId, iStateId, varptr(ptm) ; 戻り値は stat
; hTheme : HTHEME -> "sptr"
; hdc : HDC -> "sptr"
; iPartId : INT -> "sptr"
; iStateId : INT -> "sptr"
; ptm : TEXTMETRICW* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "UxTheme.dll" #cfunc global GetThemeTextMetrics "GetThemeTextMetrics" sptr, sptr, int, int, var ; res = GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, ptm) ; hTheme : HTHEME -> "sptr" ; hdc : HDC -> "sptr" ; iPartId : INT -> "int" ; iStateId : INT -> "int" ; ptm : TEXTMETRICW* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "UxTheme.dll" #cfunc global GetThemeTextMetrics "GetThemeTextMetrics" sptr, sptr, int, int, sptr ; res = GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, varptr(ptm)) ; hTheme : HTHEME -> "sptr" ; hdc : HDC -> "sptr" ; iPartId : INT -> "int" ; iStateId : INT -> "int" ; ptm : TEXTMETRICW* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetThemeTextMetrics(HTHEME hTheme, HDC hdc, INT iPartId, INT iStateId, TEXTMETRICW* ptm) #uselib "UxTheme.dll" #cfunc global GetThemeTextMetrics "GetThemeTextMetrics" intptr, intptr, int, int, var ; res = GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, ptm) ; hTheme : HTHEME -> "intptr" ; hdc : HDC -> "intptr" ; iPartId : INT -> "int" ; iStateId : INT -> "int" ; ptm : TEXTMETRICW* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetThemeTextMetrics(HTHEME hTheme, HDC hdc, INT iPartId, INT iStateId, TEXTMETRICW* ptm) #uselib "UxTheme.dll" #cfunc global GetThemeTextMetrics "GetThemeTextMetrics" intptr, intptr, int, int, intptr ; res = GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, varptr(ptm)) ; hTheme : HTHEME -> "intptr" ; hdc : HDC -> "intptr" ; iPartId : INT -> "int" ; iStateId : INT -> "int" ; ptm : TEXTMETRICW* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
uxtheme = windows.NewLazySystemDLL("UxTheme.dll")
procGetThemeTextMetrics = uxtheme.NewProc("GetThemeTextMetrics")
)
// hTheme (HTHEME), hdc (HDC), iPartId (INT), iStateId (INT), ptm (TEXTMETRICW* out)
r1, _, err := procGetThemeTextMetrics.Call(
uintptr(hTheme),
uintptr(hdc),
uintptr(iPartId),
uintptr(iStateId),
uintptr(ptm),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetThemeTextMetrics(
hTheme: NativeInt; // HTHEME
hdc: THandle; // HDC
iPartId: Integer; // INT
iStateId: Integer; // INT
ptm: Pointer // TEXTMETRICW* out
): Integer; stdcall;
external 'UxTheme.dll' name 'GetThemeTextMetrics';result := DllCall("UxTheme\GetThemeTextMetrics"
, "Ptr", hTheme ; HTHEME
, "Ptr", hdc ; HDC
, "Int", iPartId ; INT
, "Int", iStateId ; INT
, "Ptr", ptm ; TEXTMETRICW* out
, "Int") ; return: HRESULT●GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, ptm) = DLL("UxTheme.dll", "int GetThemeTextMetrics(int, void*, int, int, void*)")
# 呼び出し: GetThemeTextMetrics(hTheme, hdc, iPartId, iStateId, ptm)
# hTheme : HTHEME -> "int"
# hdc : HDC -> "void*"
# iPartId : INT -> "int"
# iStateId : INT -> "int"
# ptm : TEXTMETRICW* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。