ExtTextOutW
関数シグネチャ
// GDI32.dll (Unicode / -W)
#include <windows.h>
BOOL ExtTextOutW(
HDC hdc,
INT x,
INT y,
ETO_OPTIONS options,
const RECT* lprect, // optional
LPCWSTR lpString, // optional
DWORD c,
const INT* lpDx // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドル。 | ||||||||||||||||||
| x | INT | in | 文字列を配置するために使用される基準点の x 座標(論理座標)。 | ||||||||||||||||||
| y | INT | in | 文字列を配置するために使用される基準点の y 座標(論理座標)。 | ||||||||||||||||||
| options | ETO_OPTIONS | in | アプリケーション定義の矩形をどのように使用するかを指定します。このパラメーターには、次の値のうち 1 つ以上を指定できます。
ETO_GLYPH_INDEX と ETO_RTLREADING の値は併用できません。ETO_GLYPH_INDEX はすべての言語処理が完了していることを意味するため、ETO_RTLREADING フラグも併せて指定されている場合、関数はそれを無視します。 | ||||||||||||||||||
| lprect | RECT* | inoptional | クリッピング、塗りつぶし(opaquing)、またはその両方に使用される矩形の寸法を論理座標で指定する、任意の RECT 構造体へのポインター。 | ||||||||||||||||||
| lpString | LPCWSTR | inoptional | 描画するテキストを指定する文字列へのポインター。cbCount が文字列の長さを指定するため、文字列はゼロ終端である必要はありません。 | ||||||||||||||||||
| c | DWORD | in | lpString が指す文字列の長さ。 この値は 8192 を超えることはできません。 | ||||||||||||||||||
| lpDx | INT* | inoptional | 隣接する文字セルの原点間の距離を示す任意の値の配列へのポインター。たとえば、lpDx[i] 論理単位が文字セル i と文字セル i + 1 の原点を隔てます。 |
戻り値の型: BOOL
公式ドキュメント
ExtTextOut 関数は、現在選択されているフォント、背景色、テキスト色を使用してテキストを描画します。クリッピング、塗りつぶし(opaquing)、またはその両方に使用する寸法を任意で指定できます。(Unicode)
戻り値
文字列が描画された場合、戻り値は 0 以外です。ただし、ANSI 版の ExtTextOut が ETO_GLYPH_INDEX を指定して呼び出された場合、関数は何も行わないにもかかわらず TRUE を返します。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
指定したデバイスコンテキストの現在のテキスト配置設定により、基準点をどのようにテキストの配置に使用するかが決まります。テキスト配置設定は GetTextAlign 関数を呼び出すことで取得できます。テキスト配置設定は SetTextAlign 関数を呼び出すことで変更できます。テキスト配置には次の値を使用できます。水平方向および垂直方向の配置に影響する値からは 1 つのフラグのみを選択できます。さらに、現在位置を変更する 2 つのフラグからも 1 つのみを選択できます。
| 用語 | 説明 |
|---|---|
| TA_BASELINE | 基準点はテキストのベースライン上に置かれます。 |
| TA_BOTTOM | 基準点は外接矩形の下端に置かれます。 |
| TA_TOP | 基準点は外接矩形の上端に置かれます。 |
| TA_CENTER | 基準点は外接矩形の水平方向の中央に揃えられます。 |
| TA_LEFT | 基準点は外接矩形の左端に置かれます。 |
| TA_RIGHT | 基準点は外接矩形の右端に置かれます。 |
| TA_NOUPDATECP | 各テキスト出力呼び出しの後に現在位置は更新されません。基準点はテキスト出力関数に渡されます。 |
| TA_RTLREADING | Windows の中東言語版: テキストは既定の左から右への順序ではなく、右から左への読み取り順序でレイアウトされます。これはデバイスコンテキストに選択されているフォントがヘブライ語またはアラビア語の場合にのみ適用されます。 |
| TA_UPDATECP | 各テキスト出力呼び出しの後に現在位置が更新されます。現在位置が基準点として使用されます。 |
lpDx パラメーターが NULL の場合、ExtTextOut 関数は文字間の既定の間隔を使用します。文字セルの原点および lpDx パラメーターが指す配列の内容は論理単位で指定されます。文字セルの原点は、文字セルの左上隅として定義されます。
既定では、この関数によって現在位置が使用または更新されることはありません。ただし、アプリケーションは fMode パラメーターを TA_UPDATECP に設定して SetTextAlign 関数を呼び出すことで、指定したデバイスコンテキストに対してアプリケーションが ExtTextOut を呼び出すたびに、システムが現在位置を使用および更新できるようにすることができます。このフラグが設定されている場合、システムは以降の ExtTextOut 呼び出しにおける X および Y パラメーターを無視します。
ANSI 版の ExtTextOut では、lpDx 配列は lpString のバイト数と同じ数の INT 値を持ちます。DBCS 文字の場合、2 バイトの合計が目的の dx になる限り、lpDx エントリ内の dx を先頭バイトと末尾バイトに分配できます。Unicode 版の ExtTextOut で DBCS 文字を扱う場合、各 Unicode グリフは単一の pdx エントリを取得します。
なお、GetTextExtentExPoint の alpDx 値は ExtTextOut の lpDx 値と同じではありません。alpDx 値を lpDx で使用するには、まずそれらを処理する必要があります。
ExtTextOut は必要に応じて Uniscribe を使用し、フォントフォールバックを行います。ETO_IGNORELANGUAGE フラグはこの動作を抑制するため、渡すべきではありません。
さらに、ExtTextOut はカーネルモードへ移行する前に呼び出しの内部的なバッチ処理を行うため、PolyTextOut と ExtTextOut の使用を比較する際のパフォーマンス上の懸念の一部が軽減されます。
ExtTextOut は、さまざまな言語の表示を処理できる能力を持つため、現代の開発においては PolyTextOut よりも強く推奨されます。
Examples
例については、Using Menus の「Setting Fonts for Menu-Item Text Strings」を参照してください。
wingdi.h ヘッダーは ExtTextOut を、UNICODE プリプロセッサー定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll (Unicode / -W)
#include <windows.h>
BOOL ExtTextOutW(
HDC hdc,
INT x,
INT y,
ETO_OPTIONS options,
const RECT* lprect, // optional
LPCWSTR lpString, // optional
DWORD c,
const INT* lpDx // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool ExtTextOutW(
IntPtr hdc, // HDC
int x, // INT
int y, // INT
uint options, // ETO_OPTIONS
IntPtr lprect, // RECT* optional
[MarshalAs(UnmanagedType.LPWStr)] string lpString, // LPCWSTR optional
uint c, // DWORD
IntPtr lpDx // INT* optional
);<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ExtTextOutW(
hdc As IntPtr, ' HDC
x As Integer, ' INT
y As Integer, ' INT
options As UInteger, ' ETO_OPTIONS
lprect As IntPtr, ' RECT* optional
<MarshalAs(UnmanagedType.LPWStr)> lpString As String, ' LPCWSTR optional
c As UInteger, ' DWORD
lpDx As IntPtr ' INT* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' x : INT
' y : INT
' options : ETO_OPTIONS
' lprect : RECT* optional
' lpString : LPCWSTR optional
' c : DWORD
' lpDx : INT* optional
Declare PtrSafe Function ExtTextOutW Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal options As Long, _
ByVal lprect As LongPtr, _
ByVal lpString As LongPtr, _
ByVal c As Long, _
ByVal lpDx As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ExtTextOutW = ctypes.windll.gdi32.ExtTextOutW
ExtTextOutW.restype = wintypes.BOOL
ExtTextOutW.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # x : INT
ctypes.c_int, # y : INT
wintypes.DWORD, # options : ETO_OPTIONS
ctypes.c_void_p, # lprect : RECT* optional
wintypes.LPCWSTR, # lpString : LPCWSTR optional
wintypes.DWORD, # c : DWORD
ctypes.POINTER(ctypes.c_int), # lpDx : INT* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
ExtTextOutW = Fiddle::Function.new(
lib['ExtTextOutW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # x : INT
Fiddle::TYPE_INT, # y : INT
-Fiddle::TYPE_INT, # options : ETO_OPTIONS
Fiddle::TYPE_VOIDP, # lprect : RECT* optional
Fiddle::TYPE_VOIDP, # lpString : LPCWSTR optional
-Fiddle::TYPE_INT, # c : DWORD
Fiddle::TYPE_VOIDP, # lpDx : INT* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "gdi32")]
extern "system" {
fn ExtTextOutW(
hdc: *mut core::ffi::c_void, // HDC
x: i32, // INT
y: i32, // INT
options: u32, // ETO_OPTIONS
lprect: *const RECT, // RECT* optional
lpString: *const u16, // LPCWSTR optional
c: u32, // DWORD
lpDx: *const i32 // INT* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern bool ExtTextOutW(IntPtr hdc, int x, int y, uint options, IntPtr lprect, [MarshalAs(UnmanagedType.LPWStr)] string lpString, uint c, IntPtr lpDx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_ExtTextOutW' -Namespace Win32 -PassThru
# $api::ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx)#uselib "GDI32.dll"
#func global ExtTextOutW "ExtTextOutW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; ExtTextOutW hdc, x, y, options, varptr(lprect), lpString, c, varptr(lpDx) ; 戻り値は stat
; hdc : HDC -> "wptr"
; x : INT -> "wptr"
; y : INT -> "wptr"
; options : ETO_OPTIONS -> "wptr"
; lprect : RECT* optional -> "wptr"
; lpString : LPCWSTR optional -> "wptr"
; c : DWORD -> "wptr"
; lpDx : INT* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll" #cfunc global ExtTextOutW "ExtTextOutW" sptr, int, int, int, var, wstr, int, var ; res = ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx) ; hdc : HDC -> "sptr" ; x : INT -> "int" ; y : INT -> "int" ; options : ETO_OPTIONS -> "int" ; lprect : RECT* optional -> "var" ; lpString : LPCWSTR optional -> "wstr" ; c : DWORD -> "int" ; lpDx : INT* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global ExtTextOutW "ExtTextOutW" sptr, int, int, int, sptr, wstr, int, sptr ; res = ExtTextOutW(hdc, x, y, options, varptr(lprect), lpString, c, varptr(lpDx)) ; hdc : HDC -> "sptr" ; x : INT -> "int" ; y : INT -> "int" ; options : ETO_OPTIONS -> "int" ; lprect : RECT* optional -> "sptr" ; lpString : LPCWSTR optional -> "wstr" ; c : DWORD -> "int" ; lpDx : INT* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL ExtTextOutW(HDC hdc, INT x, INT y, ETO_OPTIONS options, RECT* lprect, LPCWSTR lpString, DWORD c, INT* lpDx) #uselib "GDI32.dll" #cfunc global ExtTextOutW "ExtTextOutW" intptr, int, int, int, var, wstr, int, var ; res = ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx) ; hdc : HDC -> "intptr" ; x : INT -> "int" ; y : INT -> "int" ; options : ETO_OPTIONS -> "int" ; lprect : RECT* optional -> "var" ; lpString : LPCWSTR optional -> "wstr" ; c : DWORD -> "int" ; lpDx : INT* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ExtTextOutW(HDC hdc, INT x, INT y, ETO_OPTIONS options, RECT* lprect, LPCWSTR lpString, DWORD c, INT* lpDx) #uselib "GDI32.dll" #cfunc global ExtTextOutW "ExtTextOutW" intptr, int, int, int, intptr, wstr, int, intptr ; res = ExtTextOutW(hdc, x, y, options, varptr(lprect), lpString, c, varptr(lpDx)) ; hdc : HDC -> "intptr" ; x : INT -> "int" ; y : INT -> "int" ; options : ETO_OPTIONS -> "int" ; lprect : RECT* optional -> "intptr" ; lpString : LPCWSTR optional -> "wstr" ; c : DWORD -> "int" ; lpDx : INT* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procExtTextOutW = gdi32.NewProc("ExtTextOutW")
)
// hdc (HDC), x (INT), y (INT), options (ETO_OPTIONS), lprect (RECT* optional), lpString (LPCWSTR optional), c (DWORD), lpDx (INT* optional)
r1, _, err := procExtTextOutW.Call(
uintptr(hdc),
uintptr(x),
uintptr(y),
uintptr(options),
uintptr(lprect),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpString))),
uintptr(c),
uintptr(lpDx),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ExtTextOutW(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
options: DWORD; // ETO_OPTIONS
lprect: Pointer; // RECT* optional
lpString: PWideChar; // LPCWSTR optional
c: DWORD; // DWORD
lpDx: Pointer // INT* optional
): BOOL; stdcall;
external 'GDI32.dll' name 'ExtTextOutW';result := DllCall("GDI32\ExtTextOutW"
, "Ptr", hdc ; HDC
, "Int", x ; INT
, "Int", y ; INT
, "UInt", options ; ETO_OPTIONS
, "Ptr", lprect ; RECT* optional
, "WStr", lpString ; LPCWSTR optional
, "UInt", c ; DWORD
, "Ptr", lpDx ; INT* optional
, "Int") ; return: BOOL●ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx) = DLL("GDI32.dll", "bool ExtTextOutW(void*, int, int, dword, void*, char*, dword, void*)")
# 呼び出し: ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# options : ETO_OPTIONS -> "dword"
# lprect : RECT* optional -> "void*"
# lpString : LPCWSTR optional -> "char*"
# c : DWORD -> "dword"
# lpDx : INT* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "gdi32" fn ExtTextOutW(
hdc: ?*anyopaque, // HDC
x: i32, // INT
y: i32, // INT
options: u32, // ETO_OPTIONS
lprect: [*c]RECT, // RECT* optional
lpString: [*c]const u16, // LPCWSTR optional
c: u32, // DWORD
lpDx: [*c]i32 // INT* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ExtTextOutW(
hdc: pointer, # HDC
x: int32, # INT
y: int32, # INT
options: uint32, # ETO_OPTIONS
lprect: ptr RECT, # RECT* optional
lpString: WideCString, # LPCWSTR optional
c: uint32, # DWORD
lpDx: ptr int32 # INT* optional
): int32 {.importc: "ExtTextOutW", stdcall, dynlib: "GDI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "gdi32");
extern(Windows)
int ExtTextOutW(
void* hdc, // HDC
int x, // INT
int y, // INT
uint options, // ETO_OPTIONS
RECT* lprect, // RECT* optional
const(wchar)* lpString, // LPCWSTR optional
uint c, // DWORD
int* lpDx // INT* optional
);ccall((:ExtTextOutW, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, UInt32, Ptr{RECT}, Cwstring, UInt32, Ptr{Int32}),
hdc, x, y, options, lprect, lpString, c, lpDx)
# hdc : HDC -> Ptr{Cvoid}
# x : INT -> Int32
# y : INT -> Int32
# options : ETO_OPTIONS -> UInt32
# lprect : RECT* optional -> Ptr{RECT}
# lpString : LPCWSTR optional -> Cwstring
# c : DWORD -> UInt32
# lpDx : INT* optional -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t ExtTextOutW(
void* hdc,
int32_t x,
int32_t y,
uint32_t options,
void* lprect,
const uint16_t* lpString,
uint32_t c,
int32_t* lpDx);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx)
-- hdc : HDC
-- x : INT
-- y : INT
-- options : ETO_OPTIONS
-- lprect : RECT* optional
-- lpString : LPCWSTR optional
-- c : DWORD
-- lpDx : INT* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const ExtTextOutW = lib.func('__stdcall', 'ExtTextOutW', 'int32_t', ['void *', 'int32_t', 'int32_t', 'uint32_t', 'void *', 'str16', 'uint32_t', 'int32_t *']);
// ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx)
// hdc : HDC -> 'void *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// options : ETO_OPTIONS -> 'uint32_t'
// lprect : RECT* optional -> 'void *'
// lpString : LPCWSTR optional -> 'str16'
// c : DWORD -> 'uint32_t'
// lpDx : INT* optional -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
ExtTextOutW: { parameters: ["pointer", "i32", "i32", "u32", "pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx)
// hdc : HDC -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// options : ETO_OPTIONS -> "u32"
// lprect : RECT* optional -> "pointer"
// lpString : LPCWSTR optional -> "buffer"
// c : DWORD -> "u32"
// lpDx : INT* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ExtTextOutW(
void* hdc,
int32_t x,
int32_t y,
uint32_t options,
void* lprect,
const uint16_t* lpString,
uint32_t c,
int32_t* lpDx);
C, "GDI32.dll");
// $ffi->ExtTextOutW(hdc, x, y, options, lprect, lpString, c, lpDx);
// hdc : HDC
// x : INT
// y : INT
// options : ETO_OPTIONS
// lprect : RECT* optional
// lpString : LPCWSTR optional
// c : DWORD
// lpDx : INT* 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 Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class, W32APIOptions.UNICODE_OPTIONS);
boolean ExtTextOutW(
Pointer hdc, // HDC
int x, // INT
int y, // INT
int options, // ETO_OPTIONS
Pointer lprect, // RECT* optional
WString lpString, // LPCWSTR optional
int c, // DWORD
IntByReference lpDx // INT* optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("gdi32")]
lib LibGDI32
fun ExtTextOutW = ExtTextOutW(
hdc : Void*, # HDC
x : Int32, # INT
y : Int32, # INT
options : UInt32, # ETO_OPTIONS
lprect : RECT*, # RECT* optional
lpString : UInt16*, # LPCWSTR optional
c : UInt32, # DWORD
lpDx : Int32* # INT* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ExtTextOutWNative = Int32 Function(Pointer<Void>, Int32, Int32, Uint32, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Int32>);
typedef ExtTextOutWDart = int Function(Pointer<Void>, int, int, int, Pointer<Void>, Pointer<Utf16>, int, Pointer<Int32>);
final ExtTextOutW = DynamicLibrary.open('GDI32.dll')
.lookupFunction<ExtTextOutWNative, ExtTextOutWDart>('ExtTextOutW');
// hdc : HDC -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// options : ETO_OPTIONS -> Uint32
// lprect : RECT* optional -> Pointer<Void>
// lpString : LPCWSTR optional -> Pointer<Utf16>
// c : DWORD -> Uint32
// lpDx : INT* optional -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ExtTextOutW(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
options: DWORD; // ETO_OPTIONS
lprect: Pointer; // RECT* optional
lpString: PWideChar; // LPCWSTR optional
c: DWORD; // DWORD
lpDx: Pointer // INT* optional
): BOOL; stdcall;
external 'GDI32.dll' name 'ExtTextOutW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ExtTextOutW"
c_ExtTextOutW :: Ptr () -> Int32 -> Int32 -> Word32 -> Ptr () -> CWString -> Word32 -> Ptr Int32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- options : ETO_OPTIONS -> Word32
-- lprect : RECT* optional -> Ptr ()
-- lpString : LPCWSTR optional -> CWString
-- c : DWORD -> Word32
-- lpDx : INT* optional -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let exttextoutw =
foreign "ExtTextOutW"
((ptr void) @-> int32_t @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* options : ETO_OPTIONS -> uint32_t *)
(* lprect : RECT* optional -> (ptr void) *)
(* lpString : LPCWSTR optional -> (ptr uint16_t) *)
(* c : DWORD -> uint32_t *)
(* lpDx : INT* optional -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("ExtTextOutW" ext-text-out-w :convention :stdcall) :int32
(hdc :pointer) ; HDC
(x :int32) ; INT
(y :int32) ; INT
(options :uint32) ; ETO_OPTIONS
(lprect :pointer) ; RECT* optional
(lp-string (:string :encoding :utf-16le)) ; LPCWSTR optional
(c :uint32) ; DWORD
(lp-dx :pointer)) ; INT* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ExtTextOutW = Win32::API::More->new('GDI32',
'BOOL ExtTextOutW(HANDLE hdc, int x, int y, DWORD options, LPVOID lprect, LPCWSTR lpString, DWORD c, LPVOID lpDx)');
# my $ret = $ExtTextOutW->Call($hdc, $x, $y, $options, $lprect, $lpString, $c, $lpDx);
# hdc : HDC -> HANDLE
# x : INT -> int
# y : INT -> int
# options : ETO_OPTIONS -> DWORD
# lprect : RECT* optional -> LPVOID
# lpString : LPCWSTR optional -> LPCWSTR
# c : DWORD -> DWORD
# lpDx : INT* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f ExtTextOutA (ANSI版) — 矩形や文字間隔を指定して文字列を描画する(ANSI版)。
- f GetTextAlign — DCの現在のテキスト配置設定を取得する。
- f SelectObject — デバイスコンテキストにGDIオブジェクトを選択し、同種の前のオブジェクトを返す。
- f SetBkColor — デバイスコンテキストの現在の背景色を設定する。
- f SetTextAlign — テキスト出力時の文字位置揃え方法を設定する。
- f SetTextColor — デバイスコンテキストの文字色を設定する。