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

GetThemeTextExtent

関数
テーマ書式で描画した際のテキストの外接矩形を取得する。
DLLUxTheme.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT GetThemeTextExtent(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    LPCWSTR pszText,
    INT cchCharCount,
    DRAW_TEXT_FORMAT dwTextFlags,
    RECT* pBoundingRect,   // optional
    RECT* pExtentRect
);

パラメーター

名前方向
hThemeHTHEMEin
hdcHDCin
iPartIdINTin
iStateIdINTin
pszTextLPCWSTRin
cchCharCountINTin
dwTextFlagsDRAW_TEXT_FORMATin
pBoundingRectRECT*inoptional
pExtentRectRECT*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT GetThemeTextExtent(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    LPCWSTR pszText,
    INT cchCharCount,
    DRAW_TEXT_FORMAT dwTextFlags,
    RECT* pBoundingRect,   // optional
    RECT* pExtentRect
);
[DllImport("UxTheme.dll", ExactSpelling = true)]
static extern int GetThemeTextExtent(
    IntPtr hTheme,   // HTHEME
    IntPtr hdc,   // HDC
    int iPartId,   // INT
    int iStateId,   // INT
    [MarshalAs(UnmanagedType.LPWStr)] string pszText,   // LPCWSTR
    int cchCharCount,   // INT
    uint dwTextFlags,   // DRAW_TEXT_FORMAT
    IntPtr pBoundingRect,   // RECT* optional
    IntPtr pExtentRect   // RECT* out
);
<DllImport("UxTheme.dll", ExactSpelling:=True)>
Public Shared Function GetThemeTextExtent(
    hTheme As IntPtr,   ' HTHEME
    hdc As IntPtr,   ' HDC
    iPartId As Integer,   ' INT
    iStateId As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPWStr)> pszText As String,   ' LPCWSTR
    cchCharCount As Integer,   ' INT
    dwTextFlags As UInteger,   ' DRAW_TEXT_FORMAT
    pBoundingRect As IntPtr,   ' RECT* optional
    pExtentRect As IntPtr   ' RECT* out
) As Integer
End Function
' hTheme : HTHEME
' hdc : HDC
' iPartId : INT
' iStateId : INT
' pszText : LPCWSTR
' cchCharCount : INT
' dwTextFlags : DRAW_TEXT_FORMAT
' pBoundingRect : RECT* optional
' pExtentRect : RECT* out
Declare PtrSafe Function GetThemeTextExtent Lib "uxtheme" ( _
    ByVal hTheme As LongPtr, _
    ByVal hdc As LongPtr, _
    ByVal iPartId As Long, _
    ByVal iStateId As Long, _
    ByVal pszText As LongPtr, _
    ByVal cchCharCount As Long, _
    ByVal dwTextFlags As Long, _
    ByVal pBoundingRect As LongPtr, _
    ByVal pExtentRect As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetThemeTextExtent = ctypes.windll.uxtheme.GetThemeTextExtent
GetThemeTextExtent.restype = ctypes.c_int
GetThemeTextExtent.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iPartId : INT
    ctypes.c_int,  # iStateId : INT
    wintypes.LPCWSTR,  # pszText : LPCWSTR
    ctypes.c_int,  # cchCharCount : INT
    wintypes.DWORD,  # dwTextFlags : DRAW_TEXT_FORMAT
    ctypes.c_void_p,  # pBoundingRect : RECT* optional
    ctypes.c_void_p,  # pExtentRect : RECT* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uxtheme = windows.NewLazySystemDLL("UxTheme.dll")
	procGetThemeTextExtent = uxtheme.NewProc("GetThemeTextExtent")
)

// hTheme (HTHEME), hdc (HDC), iPartId (INT), iStateId (INT), pszText (LPCWSTR), cchCharCount (INT), dwTextFlags (DRAW_TEXT_FORMAT), pBoundingRect (RECT* optional), pExtentRect (RECT* out)
r1, _, err := procGetThemeTextExtent.Call(
	uintptr(hTheme),
	uintptr(hdc),
	uintptr(iPartId),
	uintptr(iStateId),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszText))),
	uintptr(cchCharCount),
	uintptr(dwTextFlags),
	uintptr(pBoundingRect),
	uintptr(pExtentRect),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetThemeTextExtent(
  hTheme: NativeInt;   // HTHEME
  hdc: THandle;   // HDC
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  pszText: PWideChar;   // LPCWSTR
  cchCharCount: Integer;   // INT
  dwTextFlags: DWORD;   // DRAW_TEXT_FORMAT
  pBoundingRect: Pointer;   // RECT* optional
  pExtentRect: Pointer   // RECT* out
): Integer; stdcall;
  external 'UxTheme.dll' name 'GetThemeTextExtent';
result := DllCall("UxTheme\GetThemeTextExtent"
    , "Ptr", hTheme   ; HTHEME
    , "Ptr", hdc   ; HDC
    , "Int", iPartId   ; INT
    , "Int", iStateId   ; INT
    , "WStr", pszText   ; LPCWSTR
    , "Int", cchCharCount   ; INT
    , "UInt", dwTextFlags   ; DRAW_TEXT_FORMAT
    , "Ptr", pBoundingRect   ; RECT* optional
    , "Ptr", pExtentRect   ; RECT* out
    , "Int")   ; return: HRESULT
●GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect) = DLL("UxTheme.dll", "int GetThemeTextExtent(int, void*, int, int, char*, int, dword, void*, void*)")
# 呼び出し: GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect)
# hTheme : HTHEME -> "int"
# hdc : HDC -> "void*"
# iPartId : INT -> "int"
# iStateId : INT -> "int"
# pszText : LPCWSTR -> "char*"
# cchCharCount : INT -> "int"
# dwTextFlags : DRAW_TEXT_FORMAT -> "dword"
# pBoundingRect : RECT* optional -> "void*"
# pExtentRect : RECT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。