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

DrawThemeText

関数
テーマの書式に従ってテキストを描画する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT DrawThemeText(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    LPCWSTR pszText,
    INT cchText,
    DRAW_TEXT_FORMAT dwTextFlags,
    DWORD dwTextFlags2,
    RECT* pRect
);

パラメーター

名前方向説明
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 を参照してください。

注意 DrawThemeText は DT_CALCRECT をサポートしていません。 ただし、DrawThemeTextExDT_CALCRECT をサポートしています。
dwTextFlags2DWORDin使用されません。ゼロに設定します。
pRectRECT*inテキストを描画する矩形(論理座標)を含む RECT 構造体へのポインター。 正しい座標を取得するには、GetThemeTextExtentpExtentRect を使用することをお勧めします。

戻り値の型: HRESULT

公式ドキュメント

ビジュアルスタイルで定義された色とフォントを使用してテキストを描画します。

戻り値

型: HRESULT

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

解説(Remarks)

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

DrawThemeText は Win32 の DrawText 関数と同様のパラメーターを使用しますが、いくつかの違いがあります。最も顕著な違いの 1 つは、ワイド文字列をサポートしている点です。したがって、次の例のように、ワイドでない文字列はワイド文字列に変換する必要があります。

セキュリティに関する警告: MultiByteToWideChar を誤って使用すると、アプリケーションのセキュリティが損なわれる可能性があります。ワイド文字バッファーを作成する際は、バイト単位ではなくワイド文字単位での文字列サイズを収容できる十分な大きさであることを確認してください。

INT cchText = GetWindowTextLength(_hwnd);
if (cchText > 0)
{
    TCHAR *pszText = new TCHAR[cchText+1];
    if (pszText)
    {
        if (GetWindowText(_hwnd, pszText, cchText+1))
        {
            int widelen = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(pszText), 
                    cchText+1, NULL, 0);
            WCHAR *pszWideText = new WCHAR[widelen+1];
            MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(pszText), cchText, 
                    pszWideText, widelen);

            SetBkMode(hdcPaint, TRANSPARENT);
            DrawThemeText(_hTheme,
                    hdcPaint,
                    BP_PUSHBUTTON,
                    _iStateId,
                    pszWideText,
                    cchText,
                    DT_CENTER | DT_VCENTER | DT_SINGLELINE,
                    NULL,
                    &rcContent);

            delete [] pszWideText;
        }

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

各言語での呼び出し定義

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

HRESULT DrawThemeText(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    LPCWSTR pszText,
    INT cchText,
    DRAW_TEXT_FORMAT dwTextFlags,
    DWORD dwTextFlags2,
    RECT* pRect
);
[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern int DrawThemeText(
    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
    uint dwTextFlags2,   // DWORD
    IntPtr pRect   // RECT*
);
<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function DrawThemeText(
    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
    dwTextFlags2 As UInteger,   ' DWORD
    pRect As IntPtr   ' RECT*
) As Integer
End Function
' hTheme : HTHEME
' hdc : HDC
' iPartId : INT
' iStateId : INT
' pszText : LPCWSTR
' cchText : INT
' dwTextFlags : DRAW_TEXT_FORMAT
' dwTextFlags2 : DWORD
' pRect : RECT*
Declare PtrSafe Function DrawThemeText 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 dwTextFlags2 As Long, _
    ByVal pRect As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrawThemeText = ctypes.windll.uxtheme.DrawThemeText
DrawThemeText.restype = ctypes.c_int
DrawThemeText.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
    wintypes.DWORD,  # dwTextFlags2 : DWORD
    ctypes.c_void_p,  # pRect : RECT*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procDrawThemeText = uxtheme.NewProc("DrawThemeText")
)

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

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

typedef DrawThemeTextNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Int32, Pointer<Utf16>, Int32, Uint32, Uint32, Pointer<Void>);
typedef DrawThemeTextDart = int Function(int, Pointer<Void>, int, int, Pointer<Utf16>, int, int, int, Pointer<Void>);
final DrawThemeText = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<DrawThemeTextNative, DrawThemeTextDart>('DrawThemeText');
// 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
// dwTextFlags2 : DWORD -> Uint32
// pRect : RECT* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DrawThemeText(
  hTheme: NativeInt;   // HTHEME
  hdc: THandle;   // HDC
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  pszText: PWideChar;   // LPCWSTR
  cchText: Integer;   // INT
  dwTextFlags: DWORD;   // DRAW_TEXT_FORMAT
  dwTextFlags2: DWORD;   // DWORD
  pRect: Pointer   // RECT*
): Integer; stdcall;
  external 'UXTHEME.dll' name 'DrawThemeText';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DrawThemeText"
  c_DrawThemeText :: CIntPtr -> Ptr () -> Int32 -> Int32 -> CWString -> Int32 -> Word32 -> Word32 -> 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
-- dwTextFlags2 : DWORD -> Word32
-- pRect : RECT* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drawthemetext =
  foreign "DrawThemeText"
    (intptr_t @-> (ptr void) @-> int32_t @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> uint32_t @-> (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 *)
(* dwTextFlags2 : DWORD -> uint32_t *)
(* pRect : RECT* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)

(cffi:defcfun ("DrawThemeText" draw-theme-text :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
  (dw-text-flags2 :uint32)   ; DWORD
  (p-rect :pointer))   ; RECT*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DrawThemeText = Win32::API::More->new('UXTHEME',
    'int DrawThemeText(LPARAM hTheme, HANDLE hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, DWORD dwTextFlags2, LPVOID pRect)');
# my $ret = $DrawThemeText->Call($hTheme, $hdc, $iPartId, $iStateId, $pszText, $cchText, $dwTextFlags, $dwTextFlags2, $pRect);
# hTheme : HTHEME -> LPARAM
# hdc : HDC -> HANDLE
# iPartId : INT -> int
# iStateId : INT -> int
# pszText : LPCWSTR -> LPCWSTR
# cchText : INT -> int
# dwTextFlags : DRAW_TEXT_FORMAT -> DWORD
# dwTextFlags2 : DWORD -> DWORD
# pRect : RECT* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型