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ウィンドウに指定されたテーマデータへのハンドルです。HTHEME を作成するには OpenThemeData を使用します。
hdcHDCin描画に使用する HDC です。
iPartIdINTin目的のテキスト外観を持つコントロールのパートです。Parts and States を参照してください。この値が 0 の場合、テキストは既定のフォント、またはデバイスコンテキストに選択されているフォントで描画されます。
iStateIdINTin目的のテキスト外観を持つコントロールの状態です。Parts and States を参照してください。
pszTextLPCWSTRin描画するテキストを含む文字列へのポインターです。
cchTextINTin描画する文字数を含む int 型の値です。このパラメーターを -1 に設定すると、文字列内のすべての文字が描画されます。
dwTextFlagsDRAW_TEXT_FORMATin文字列の書式を指定する 1 つ以上の値を含む DWORD です。指定可能なパラメーター値については Format Values を参照してください。
pRectRECT*inoutテキストを描画する論理座標での矩形を含む RECT 構造体へのポインターです。
pOptionsDTTOPTS*inoptional描画されるテキストに適用される追加の書式オプションを定義する DTTOPTS 構造体です。

戻り値の型: HRESULT

公式ドキュメント

ビジュアルスタイルで定義された色とフォントを使用してテキストを描画します。DrawThemeText を拡張し、追加のテキスト書式オプションを指定できるようにします。

戻り値

型: HRESULT

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

解説(Remarks)

この関数は、指定されたパートと状態にテーマ化されたフォントが定義されている場合は、常にそのフォントを使用します。定義されていない場合は、デバイスコンテキストに現在選択されているフォントを使用します。テーマ化されたフォントが定義されているかどうかを調べるには、プロパティ識別子として TMT_FONT を指定して GetThemeFont または GetThemePropertyOrigin を呼び出します。

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

各言語での呼び出し定義

// 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)。
const std = @import("std");

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

typedef DrawThemeTextExNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Int32, Pointer<Utf16>, Int32, Uint32, Pointer<Void>, Pointer<Void>);
typedef DrawThemeTextExDart = int Function(int, Pointer<Void>, int, int, Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Void>);
final DrawThemeTextEx = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<DrawThemeTextExNative, DrawThemeTextExDart>('DrawThemeTextEx');
// hTheme : HTHEME -> IntPtr
// hdc : HDC -> Pointer<Void>
// iPartId : INT -> Int32
// iStateId : INT -> Int32
// pszText : LPCWSTR -> Pointer<Utf16>
// cchText : INT -> Int32
// dwTextFlags : DRAW_TEXT_FORMAT -> Uint32
// pRect : RECT* in/out -> Pointer<Void>
// pOptions : DTTOPTS* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DrawThemeTextEx"
  c_DrawThemeTextEx :: CIntPtr -> Ptr () -> Int32 -> Int32 -> CWString -> Int32 -> Word32 -> Ptr () -> Ptr () -> IO Int32
-- hTheme : HTHEME -> CIntPtr
-- hdc : HDC -> Ptr ()
-- iPartId : INT -> Int32
-- iStateId : INT -> Int32
-- pszText : LPCWSTR -> CWString
-- cchText : INT -> Int32
-- dwTextFlags : DRAW_TEXT_FORMAT -> Word32
-- pRect : RECT* in/out -> Ptr ()
-- pOptions : DTTOPTS* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drawthemetextex =
  foreign "DrawThemeTextEx"
    (intptr_t @-> (ptr void) @-> int32_t @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hTheme : HTHEME -> intptr_t *)
(* hdc : HDC -> (ptr void) *)
(* iPartId : INT -> int32_t *)
(* iStateId : INT -> int32_t *)
(* pszText : LPCWSTR -> (ptr uint16_t) *)
(* cchText : INT -> int32_t *)
(* dwTextFlags : DRAW_TEXT_FORMAT -> uint32_t *)
(* pRect : RECT* in/out -> (ptr void) *)
(* pOptions : DTTOPTS* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)

(cffi:defcfun ("DrawThemeTextEx" draw-theme-text-ex :convention :stdcall) :int32
  (h-theme :int64)   ; HTHEME
  (hdc :pointer)   ; HDC
  (i-part-id :int32)   ; INT
  (i-state-id :int32)   ; INT
  (psz-text (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-text :int32)   ; INT
  (dw-text-flags :uint32)   ; DRAW_TEXT_FORMAT
  (p-rect :pointer)   ; RECT* in/out
  (p-options :pointer))   ; DTTOPTS* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DrawThemeTextEx = Win32::API::More->new('UXTHEME',
    'int DrawThemeTextEx(LPARAM hTheme, HANDLE hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, LPVOID pRect, LPVOID pOptions)');
# my $ret = $DrawThemeTextEx->Call($hTheme, $hdc, $iPartId, $iStateId, $pszText, $cchText, $dwTextFlags, $pRect, $pOptions);
# hTheme : HTHEME -> LPARAM
# hdc : HDC -> HANDLE
# iPartId : INT -> int
# iStateId : INT -> int
# pszText : LPCWSTR -> LPCWSTR
# cchText : INT -> int
# dwTextFlags : DRAW_TEXT_FORMAT -> DWORD
# pRect : RECT* in/out -> LPVOID
# pOptions : DTTOPTS* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型