ホーム › UI.Controls › GetThemeTextExtent
GetThemeTextExtent
関数テーマ書式で描画した際のテキストの外接矩形を取得する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hTheme | HTHEME | in | ウィンドウに指定されたテーマデータへのハンドル。HTHEME を作成するには OpenThemeData を使用します。 |
| hdc | HDC | in | フォントを選択する対象の HDC。 |
| iPartId | INT | in | テキストを描画するパートを指定する int 型の値。Parts and States を参照してください。 |
| iStateId | INT | in | パートの状態を指定する int 型の値。Parts and States を参照してください。 |
| pszText | LPCWSTR | in | 描画するテキストを格納した文字列へのポインター。 |
| cchCharCount | INT | in | 描画する文字数を格納する int 型の値。このパラメーターを -1 に設定すると、文字列内のすべての文字が描画されます。 |
| dwTextFlags | DRAW_TEXT_FORMAT | in | 文字列の書式設定を指定する 1 つ以上の値を格納する DWORD。指定可能なパラメーター値については Format Values を参照してください。 |
| pBoundingRect | RECT* | inoptional | テキストのレイアウトを制御するために使用する矩形を格納した RECT 構造体へのポインター。このパラメーターは NULL に設定できます。 |
| pExtentRect | RECT* | out | 描画されたテキストを収めるために必要な矩形を論理座標で格納する RECT 構造体へのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
指定したテキストをビジュアルスタイルのフォントで描画した場合のサイズと位置を計算します。
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "UXTHEME.dll" #cfunc global GetThemeTextExtent "GetThemeTextExtent" sptr, sptr, int, int, wstr, int, int, sptr, sptr ; res = GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, varptr(pBoundingRect), varptr(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 -> "sptr" ; pExtentRect : RECT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr ; res = GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, varptr(pBoundingRect), varptr(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 -> "intptr" ; pExtentRect : RECT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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)。const std = @import("std");
extern "uxtheme" fn GetThemeTextExtent(
hTheme: isize, // HTHEME
hdc: ?*anyopaque, // HDC
iPartId: i32, // INT
iStateId: i32, // INT
pszText: [*c]const u16, // LPCWSTR
cchCharCount: i32, // INT
dwTextFlags: u32, // DRAW_TEXT_FORMAT
pBoundingRect: [*c]RECT, // RECT* optional
pExtentRect: [*c]RECT // RECT* out
) callconv(std.os.windows.WINAPI) i32;proc GetThemeTextExtent(
hTheme: int, # HTHEME
hdc: pointer, # HDC
iPartId: int32, # INT
iStateId: int32, # INT
pszText: WideCString, # LPCWSTR
cchCharCount: int32, # INT
dwTextFlags: uint32, # DRAW_TEXT_FORMAT
pBoundingRect: ptr RECT, # RECT* optional
pExtentRect: ptr RECT # RECT* out
): int32 {.importc: "GetThemeTextExtent", stdcall, dynlib: "UXTHEME.dll".}pragma(lib, "uxtheme");
extern(Windows)
int GetThemeTextExtent(
ptrdiff_t hTheme, // HTHEME
void* hdc, // HDC
int iPartId, // INT
int iStateId, // INT
const(wchar)* pszText, // LPCWSTR
int cchCharCount, // INT
uint dwTextFlags, // DRAW_TEXT_FORMAT
RECT* pBoundingRect, // RECT* optional
RECT* pExtentRect // RECT* out
);ccall((:GetThemeTextExtent, "UXTHEME.dll"), stdcall, Int32,
(Int, Ptr{Cvoid}, Int32, Int32, Cwstring, Int32, UInt32, Ptr{RECT}, Ptr{RECT}),
hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect)
# hTheme : HTHEME -> Int
# hdc : HDC -> Ptr{Cvoid}
# iPartId : INT -> Int32
# iStateId : INT -> Int32
# pszText : LPCWSTR -> Cwstring
# cchCharCount : INT -> Int32
# dwTextFlags : DRAW_TEXT_FORMAT -> UInt32
# pBoundingRect : RECT* optional -> Ptr{RECT}
# pExtentRect : RECT* out -> Ptr{RECT}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetThemeTextExtent(
intptr_t hTheme,
void* hdc,
int32_t iPartId,
int32_t iStateId,
const uint16_t* pszText,
int32_t cchCharCount,
uint32_t dwTextFlags,
void* pBoundingRect,
void* pExtentRect);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect)
-- hTheme : HTHEME
-- hdc : HDC
-- iPartId : INT
-- iStateId : INT
-- pszText : LPCWSTR
-- cchCharCount : INT
-- dwTextFlags : DRAW_TEXT_FORMAT
-- pBoundingRect : RECT* optional
-- pExtentRect : RECT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const GetThemeTextExtent = lib.func('__stdcall', 'GetThemeTextExtent', 'int32_t', ['intptr_t', 'void *', 'int32_t', 'int32_t', 'str16', 'int32_t', 'uint32_t', 'void *', 'void *']);
// GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect)
// hTheme : HTHEME -> 'intptr_t'
// hdc : HDC -> 'void *'
// iPartId : INT -> 'int32_t'
// iStateId : INT -> 'int32_t'
// pszText : LPCWSTR -> 'str16'
// cchCharCount : INT -> 'int32_t'
// dwTextFlags : DRAW_TEXT_FORMAT -> 'uint32_t'
// pBoundingRect : RECT* optional -> 'void *'
// pExtentRect : RECT* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("UXTHEME.dll", {
GetThemeTextExtent: { parameters: ["isize", "pointer", "i32", "i32", "buffer", "i32", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect)
// hTheme : HTHEME -> "isize"
// hdc : HDC -> "pointer"
// iPartId : INT -> "i32"
// iStateId : INT -> "i32"
// pszText : LPCWSTR -> "buffer"
// cchCharCount : INT -> "i32"
// dwTextFlags : DRAW_TEXT_FORMAT -> "u32"
// pBoundingRect : RECT* optional -> "pointer"
// pExtentRect : RECT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetThemeTextExtent(
intptr_t hTheme,
void* hdc,
int32_t iPartId,
int32_t iStateId,
const uint16_t* pszText,
int32_t cchCharCount,
uint32_t dwTextFlags,
void* pBoundingRect,
void* pExtentRect);
C, "UXTHEME.dll");
// $ffi->GetThemeTextExtent(hTheme, hdc, iPartId, iStateId, pszText, cchCharCount, dwTextFlags, pBoundingRect, pExtentRect);
// hTheme : HTHEME
// hdc : HDC
// iPartId : INT
// iStateId : INT
// pszText : LPCWSTR
// cchCharCount : INT
// dwTextFlags : DRAW_TEXT_FORMAT
// pBoundingRect : RECT* optional
// pExtentRect : RECT* out
// 構造体/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 GetThemeTextExtent(
long hTheme, // HTHEME
Pointer hdc, // HDC
int iPartId, // INT
int iStateId, // INT
WString pszText, // LPCWSTR
int cchCharCount, // INT
int dwTextFlags, // DRAW_TEXT_FORMAT
Pointer pBoundingRect, // RECT* optional
Pointer pExtentRect // RECT* out
);
}@[Link("uxtheme")]
lib LibUXTHEME
fun GetThemeTextExtent = GetThemeTextExtent(
hTheme : LibC::SSizeT, # HTHEME
hdc : Void*, # HDC
iPartId : Int32, # INT
iStateId : Int32, # INT
pszText : UInt16*, # LPCWSTR
cchCharCount : Int32, # INT
dwTextFlags : UInt32, # DRAW_TEXT_FORMAT
pBoundingRect : RECT*, # RECT* optional
pExtentRect : RECT* # RECT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetThemeTextExtentNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Int32, Pointer<Utf16>, Int32, Uint32, Pointer<Void>, Pointer<Void>);
typedef GetThemeTextExtentDart = int Function(int, Pointer<Void>, int, int, Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Void>);
final GetThemeTextExtent = DynamicLibrary.open('UXTHEME.dll')
.lookupFunction<GetThemeTextExtentNative, GetThemeTextExtentDart>('GetThemeTextExtent');
// hTheme : HTHEME -> IntPtr
// hdc : HDC -> Pointer<Void>
// iPartId : INT -> Int32
// iStateId : INT -> Int32
// pszText : LPCWSTR -> Pointer<Utf16>
// cchCharCount : INT -> Int32
// dwTextFlags : DRAW_TEXT_FORMAT -> Uint32
// pBoundingRect : RECT* optional -> Pointer<Void>
// pExtentRect : RECT* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetThemeTextExtent"
c_GetThemeTextExtent :: 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
-- cchCharCount : INT -> Int32
-- dwTextFlags : DRAW_TEXT_FORMAT -> Word32
-- pBoundingRect : RECT* optional -> Ptr ()
-- pExtentRect : RECT* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getthemetextextent =
foreign "GetThemeTextExtent"
(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) *)
(* cchCharCount : INT -> int32_t *)
(* dwTextFlags : DRAW_TEXT_FORMAT -> uint32_t *)
(* pBoundingRect : RECT* optional -> (ptr void) *)
(* pExtentRect : RECT* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)
(cffi:defcfun ("GetThemeTextExtent" get-theme-text-extent :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-char-count :int32) ; INT
(dw-text-flags :uint32) ; DRAW_TEXT_FORMAT
(p-bounding-rect :pointer) ; RECT* optional
(p-extent-rect :pointer)) ; RECT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetThemeTextExtent = Win32::API::More->new('UXTHEME',
'int GetThemeTextExtent(LPARAM hTheme, HANDLE hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchCharCount, DWORD dwTextFlags, LPVOID pBoundingRect, LPVOID pExtentRect)');
# my $ret = $GetThemeTextExtent->Call($hTheme, $hdc, $iPartId, $iStateId, $pszText, $cchCharCount, $dwTextFlags, $pBoundingRect, $pExtentRect);
# hTheme : HTHEME -> LPARAM
# hdc : HDC -> HANDLE
# iPartId : INT -> int
# iStateId : INT -> int
# pszText : LPCWSTR -> LPCWSTR
# cchCharCount : INT -> int
# dwTextFlags : DRAW_TEXT_FORMAT -> DWORD
# pBoundingRect : RECT* optional -> LPVOID
# pExtentRect : RECT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。