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

DrawThemeTextEx

関数
オプション指定でテーマ書式のテキストを描画する拡張版。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT DrawThemeTextEx(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    LPCWSTR pszText,
    INT cchText,
    DRAW_TEXT_FORMAT dwTextFlags,
    RECT* pRect,
    const DTTOPTS* pOptions   // optional
);

パラメーター

名前方向
hThemeHTHEMEin
hdcHDCin
iPartIdINTin
iStateIdINTin
pszTextLPCWSTRin
cchTextINTin
dwTextFlagsDRAW_TEXT_FORMATin
pRectRECT*inout
pOptionsDTTOPTS*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

DrawThemeTextEx = ctypes.windll.uxtheme.DrawThemeTextEx
DrawThemeTextEx.restype = ctypes.c_int
DrawThemeTextEx.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,  # cchText : INT
    wintypes.DWORD,  # dwTextFlags : DRAW_TEXT_FORMAT
    ctypes.c_void_p,  # pRect : RECT* in/out
    ctypes.c_void_p,  # pOptions : DTTOPTS* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procDrawThemeTextEx = uxtheme.NewProc("DrawThemeTextEx")
)

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