GetTextExtentExPointA
関数シグネチャ
// GDI32.dll (ANSI / -A)
#include <windows.h>
BOOL GetTextExtentExPointA(
HDC hdc,
LPCSTR lpszString,
INT cchString,
INT nMaxExtent,
INT* lpnFit, // optional
INT* lpnDx, // optional
SIZE* lpSize
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドルです。 |
| lpszString | LPCSTR | in | 幅を取得する対象の、null で終端された文字列へのポインターです。 |
| cchString | INT | in | lpszStr パラメーターが指す文字列の文字数です。ANSI 呼び出しではバイト単位の文字列長を、Unicode 呼び出しでは WORD 単位の文字列長を指定します。ANSI 関数では、SBCS コードページの文字は 1 文字あたり 1 バイトを使用しますが、DBCS コードページのほとんどの文字は 2 バイトを使用します。Unicode 関数では、現在定義されているほとんどの Unicode 文字(基本多言語面 (BMP) に含まれる文字)は 1 WORD ですが、Unicode サロゲートは 2 WORD です。 |
| nMaxExtent | INT | in | 整形された文字列の許容される最大幅を、論理単位で指定します。 |
| lpnFit | INT* | outoptional | nMaxExtent パラメーターで指定された領域に収まる最大文字数を受け取る整数へのポインターです。lpnFit パラメーターが NULL の場合、nMaxExtent パラメーターは無視されます。 |
| lpnDx | INT* | outoptional | 部分文字列の幅を受け取る整数配列へのポインターです。配列の各要素は、文字列の先頭から nMaxExtent パラメーターで指定された領域に収まる各文字までの距離を、論理単位で表します。配列全体が内部的に使用されるため、この配列には少なくとも cchString パラメーターで指定された文字数と同じ数の要素が必要です。関数は、lpnFit パラメーターで指定された文字数分だけ有効な幅を配列に格納します。配列の残りの値は無視してください。alpDx が NULL の場合、関数は部分文字列の幅を計算しません。 複数の文字の並びが任意の数のグリフで表現される可能性がある複雑なスクリプトでは、alpDx 配列内の lpnFit パラメーターで指定された数までの値が、コードポイントと 1 対 1 で対応します。この場合も、alpDx 配列の残りの値は無視してください。 |
| lpSize | SIZE* | out | 文字列の寸法を論理単位で受け取る SIZE 構造体へのポインターです。このパラメーターを NULL にすることはできません。 |
戻り値の型: BOOL
公式ドキュメント
GetTextExtentExPoint 関数は、指定した領域に収まる文字数を指定された文字列から取得し、それらの各文字のテキストの幅を配列に格納します。(ANSI)
戻り値
関数が成功すると、0 以外の値が返されます。
関数が失敗すると、0 が返されます。
解説(Remarks)
lpnFit と alpDx の両方のパラメーターが NULL の場合、GetTextExtentExPoint 関数の呼び出しは GetTextExtentPoint 関数の呼び出しと同等です。
GetTextExtentExPoint の ANSI バージョンでは、lpDx 配列は lpString 内のバイト数と同じ数の INT 値を持ちます。DBCS 文字の 2 バイトに対応する INT 値は、いずれもその合成文字全体の幅になります。
なお、GetTextExtentExPoint の alpDx 値は、ExtTextOut の lpDx 値とは異なります。alpDx 値を lpDx で使用するには、まずそれらを処理する必要があります。
この関数がテキストの幅を返すとき、テキストは水平方向である(つまり、文字送り角度が常に 0 である)と想定します。これはテキストの水平方向と垂直方向の両方の測定について当てはまります。0 以外の文字送り角度を指定するフォントを使用していても、この関数はテキストの幅を計算する際にその角度を使用しません。アプリケーションは明示的に変換する必要があります。ただし、グラフィックスモードが GM_ADVANCED に設定され、文字の向きが印刷の向きから 90 度回転している場合、この関数が返す値はこの規則に従いません。ある文字列について文字の向きと印刷の向きが一致する場合、この関数は SIZE 構造体に文字列の寸法を { cx : 116, cy : 18 } として返します。同じ文字列について文字の向きと印刷の向きが 90 度異なる場合、この関数は SIZE 構造体に文字列の寸法を { cx : 18, cy : 116 } として返します。
この関数は、文字列内の連続する各文字の幅を返します。これらを論理単位に丸めると、各文字の幅を論理単位に丸めて返す GetCharWidth から返される結果とは異なる結果が得られます。
wingdi.h ヘッダーは、GetTextExtentExPoint を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして定義します。このエンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll (ANSI / -A)
#include <windows.h>
BOOL GetTextExtentExPointA(
HDC hdc,
LPCSTR lpszString,
INT cchString,
INT nMaxExtent,
INT* lpnFit, // optional
INT* lpnDx, // optional
SIZE* lpSize
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool GetTextExtentExPointA(
IntPtr hdc, // HDC
[MarshalAs(UnmanagedType.LPStr)] string lpszString, // LPCSTR
int cchString, // INT
int nMaxExtent, // INT
IntPtr lpnFit, // INT* optional, out
IntPtr lpnDx, // INT* optional, out
IntPtr lpSize // SIZE* out
);<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetTextExtentExPointA(
hdc As IntPtr, ' HDC
<MarshalAs(UnmanagedType.LPStr)> lpszString As String, ' LPCSTR
cchString As Integer, ' INT
nMaxExtent As Integer, ' INT
lpnFit As IntPtr, ' INT* optional, out
lpnDx As IntPtr, ' INT* optional, out
lpSize As IntPtr ' SIZE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' lpszString : LPCSTR
' cchString : INT
' nMaxExtent : INT
' lpnFit : INT* optional, out
' lpnDx : INT* optional, out
' lpSize : SIZE* out
Declare PtrSafe Function GetTextExtentExPointA Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal lpszString As String, _
ByVal cchString As Long, _
ByVal nMaxExtent As Long, _
ByVal lpnFit As LongPtr, _
ByVal lpnDx As LongPtr, _
ByVal lpSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetTextExtentExPointA = ctypes.windll.gdi32.GetTextExtentExPointA
GetTextExtentExPointA.restype = wintypes.BOOL
GetTextExtentExPointA.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.LPCSTR, # lpszString : LPCSTR
ctypes.c_int, # cchString : INT
ctypes.c_int, # nMaxExtent : INT
ctypes.POINTER(ctypes.c_int), # lpnFit : INT* optional, out
ctypes.POINTER(ctypes.c_int), # lpnDx : INT* optional, out
ctypes.c_void_p, # lpSize : SIZE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetTextExtentExPointA = Fiddle::Function.new(
lib['GetTextExtentExPointA'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # lpszString : LPCSTR
Fiddle::TYPE_INT, # cchString : INT
Fiddle::TYPE_INT, # nMaxExtent : INT
Fiddle::TYPE_VOIDP, # lpnFit : INT* optional, out
Fiddle::TYPE_VOIDP, # lpnDx : INT* optional, out
Fiddle::TYPE_VOIDP, # lpSize : SIZE* out
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn GetTextExtentExPointA(
hdc: *mut core::ffi::c_void, // HDC
lpszString: *const u8, // LPCSTR
cchString: i32, // INT
nMaxExtent: i32, // INT
lpnFit: *mut i32, // INT* optional, out
lpnDx: *mut i32, // INT* optional, out
lpSize: *mut SIZE // SIZE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Ansi)]
public static extern bool GetTextExtentExPointA(IntPtr hdc, [MarshalAs(UnmanagedType.LPStr)] string lpszString, int cchString, int nMaxExtent, IntPtr lpnFit, IntPtr lpnDx, IntPtr lpSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetTextExtentExPointA' -Namespace Win32 -PassThru
# $api::GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)#uselib "GDI32.dll"
#func global GetTextExtentExPointA "GetTextExtentExPointA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetTextExtentExPointA hdc, lpszString, cchString, nMaxExtent, varptr(lpnFit), varptr(lpnDx), varptr(lpSize) ; 戻り値は stat
; hdc : HDC -> "sptr"
; lpszString : LPCSTR -> "sptr"
; cchString : INT -> "sptr"
; nMaxExtent : INT -> "sptr"
; lpnFit : INT* optional, out -> "sptr"
; lpnDx : INT* optional, out -> "sptr"
; lpSize : SIZE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll" #cfunc global GetTextExtentExPointA "GetTextExtentExPointA" sptr, str, int, int, var, var, var ; res = GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize) ; hdc : HDC -> "sptr" ; lpszString : LPCSTR -> "str" ; cchString : INT -> "int" ; nMaxExtent : INT -> "int" ; lpnFit : INT* optional, out -> "var" ; lpnDx : INT* optional, out -> "var" ; lpSize : SIZE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global GetTextExtentExPointA "GetTextExtentExPointA" sptr, str, int, int, sptr, sptr, sptr ; res = GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, varptr(lpnFit), varptr(lpnDx), varptr(lpSize)) ; hdc : HDC -> "sptr" ; lpszString : LPCSTR -> "str" ; cchString : INT -> "int" ; nMaxExtent : INT -> "int" ; lpnFit : INT* optional, out -> "sptr" ; lpnDx : INT* optional, out -> "sptr" ; lpSize : SIZE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL GetTextExtentExPointA(HDC hdc, LPCSTR lpszString, INT cchString, INT nMaxExtent, INT* lpnFit, INT* lpnDx, SIZE* lpSize) #uselib "GDI32.dll" #cfunc global GetTextExtentExPointA "GetTextExtentExPointA" intptr, str, int, int, var, var, var ; res = GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize) ; hdc : HDC -> "intptr" ; lpszString : LPCSTR -> "str" ; cchString : INT -> "int" ; nMaxExtent : INT -> "int" ; lpnFit : INT* optional, out -> "var" ; lpnDx : INT* optional, out -> "var" ; lpSize : SIZE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetTextExtentExPointA(HDC hdc, LPCSTR lpszString, INT cchString, INT nMaxExtent, INT* lpnFit, INT* lpnDx, SIZE* lpSize) #uselib "GDI32.dll" #cfunc global GetTextExtentExPointA "GetTextExtentExPointA" intptr, str, int, int, intptr, intptr, intptr ; res = GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, varptr(lpnFit), varptr(lpnDx), varptr(lpSize)) ; hdc : HDC -> "intptr" ; lpszString : LPCSTR -> "str" ; cchString : INT -> "int" ; nMaxExtent : INT -> "int" ; lpnFit : INT* optional, out -> "intptr" ; lpnDx : INT* optional, out -> "intptr" ; lpSize : SIZE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetTextExtentExPointA = gdi32.NewProc("GetTextExtentExPointA")
)
// hdc (HDC), lpszString (LPCSTR), cchString (INT), nMaxExtent (INT), lpnFit (INT* optional, out), lpnDx (INT* optional, out), lpSize (SIZE* out)
r1, _, err := procGetTextExtentExPointA.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszString))),
uintptr(cchString),
uintptr(nMaxExtent),
uintptr(lpnFit),
uintptr(lpnDx),
uintptr(lpSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetTextExtentExPointA(
hdc: THandle; // HDC
lpszString: PAnsiChar; // LPCSTR
cchString: Integer; // INT
nMaxExtent: Integer; // INT
lpnFit: Pointer; // INT* optional, out
lpnDx: Pointer; // INT* optional, out
lpSize: Pointer // SIZE* out
): BOOL; stdcall;
external 'GDI32.dll' name 'GetTextExtentExPointA';result := DllCall("GDI32\GetTextExtentExPointA"
, "Ptr", hdc ; HDC
, "AStr", lpszString ; LPCSTR
, "Int", cchString ; INT
, "Int", nMaxExtent ; INT
, "Ptr", lpnFit ; INT* optional, out
, "Ptr", lpnDx ; INT* optional, out
, "Ptr", lpSize ; SIZE* out
, "Int") ; return: BOOL●GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize) = DLL("GDI32.dll", "bool GetTextExtentExPointA(void*, char*, int, int, void*, void*, void*)")
# 呼び出し: GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)
# hdc : HDC -> "void*"
# lpszString : LPCSTR -> "char*"
# cchString : INT -> "int"
# nMaxExtent : INT -> "int"
# lpnFit : INT* optional, out -> "void*"
# lpnDx : INT* optional, out -> "void*"
# lpSize : SIZE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn GetTextExtentExPointA(
hdc: ?*anyopaque, // HDC
lpszString: [*c]const u8, // LPCSTR
cchString: i32, // INT
nMaxExtent: i32, // INT
lpnFit: [*c]i32, // INT* optional, out
lpnDx: [*c]i32, // INT* optional, out
lpSize: [*c]SIZE // SIZE* out
) callconv(std.os.windows.WINAPI) i32;proc GetTextExtentExPointA(
hdc: pointer, # HDC
lpszString: cstring, # LPCSTR
cchString: int32, # INT
nMaxExtent: int32, # INT
lpnFit: ptr int32, # INT* optional, out
lpnDx: ptr int32, # INT* optional, out
lpSize: ptr SIZE # SIZE* out
): int32 {.importc: "GetTextExtentExPointA", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int GetTextExtentExPointA(
void* hdc, // HDC
const(char)* lpszString, // LPCSTR
int cchString, // INT
int nMaxExtent, // INT
int* lpnFit, // INT* optional, out
int* lpnDx, // INT* optional, out
SIZE* lpSize // SIZE* out
);ccall((:GetTextExtentExPointA, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cstring, Int32, Int32, Ptr{Int32}, Ptr{Int32}, Ptr{SIZE}),
hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)
# hdc : HDC -> Ptr{Cvoid}
# lpszString : LPCSTR -> Cstring
# cchString : INT -> Int32
# nMaxExtent : INT -> Int32
# lpnFit : INT* optional, out -> Ptr{Int32}
# lpnDx : INT* optional, out -> Ptr{Int32}
# lpSize : SIZE* out -> Ptr{SIZE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetTextExtentExPointA(
void* hdc,
const char* lpszString,
int32_t cchString,
int32_t nMaxExtent,
int32_t* lpnFit,
int32_t* lpnDx,
void* lpSize);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)
-- hdc : HDC
-- lpszString : LPCSTR
-- cchString : INT
-- nMaxExtent : INT
-- lpnFit : INT* optional, out
-- lpnDx : INT* optional, out
-- lpSize : SIZE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const GetTextExtentExPointA = lib.func('__stdcall', 'GetTextExtentExPointA', 'int32_t', ['void *', 'str', 'int32_t', 'int32_t', 'int32_t *', 'int32_t *', 'void *']);
// GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)
// hdc : HDC -> 'void *'
// lpszString : LPCSTR -> 'str'
// cchString : INT -> 'int32_t'
// nMaxExtent : INT -> 'int32_t'
// lpnFit : INT* optional, out -> 'int32_t *'
// lpnDx : INT* optional, out -> 'int32_t *'
// lpSize : SIZE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
GetTextExtentExPointA: { parameters: ["pointer", "buffer", "i32", "i32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize)
// hdc : HDC -> "pointer"
// lpszString : LPCSTR -> "buffer"
// cchString : INT -> "i32"
// nMaxExtent : INT -> "i32"
// lpnFit : INT* optional, out -> "pointer"
// lpnDx : INT* optional, out -> "pointer"
// lpSize : SIZE* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetTextExtentExPointA(
void* hdc,
const char* lpszString,
int32_t cchString,
int32_t nMaxExtent,
int32_t* lpnFit,
int32_t* lpnDx,
void* lpSize);
C, "GDI32.dll");
// $ffi->GetTextExtentExPointA(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize);
// hdc : HDC
// lpszString : LPCSTR
// cchString : INT
// nMaxExtent : INT
// lpnFit : INT* optional, out
// lpnDx : INT* optional, out
// lpSize : SIZE* 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 Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class, W32APIOptions.ASCII_OPTIONS);
boolean GetTextExtentExPointA(
Pointer hdc, // HDC
String lpszString, // LPCSTR
int cchString, // INT
int nMaxExtent, // INT
IntByReference lpnFit, // INT* optional, out
IntByReference lpnDx, // INT* optional, out
Pointer lpSize // SIZE* out
);
}@[Link("gdi32")]
lib LibGDI32
fun GetTextExtentExPointA = GetTextExtentExPointA(
hdc : Void*, # HDC
lpszString : UInt8*, # LPCSTR
cchString : Int32, # INT
nMaxExtent : Int32, # INT
lpnFit : Int32*, # INT* optional, out
lpnDx : Int32*, # INT* optional, out
lpSize : SIZE* # SIZE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetTextExtentExPointANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Int32, Int32, Pointer<Int32>, Pointer<Int32>, Pointer<Void>);
typedef GetTextExtentExPointADart = int Function(Pointer<Void>, Pointer<Utf8>, int, int, Pointer<Int32>, Pointer<Int32>, Pointer<Void>);
final GetTextExtentExPointA = DynamicLibrary.open('GDI32.dll')
.lookupFunction<GetTextExtentExPointANative, GetTextExtentExPointADart>('GetTextExtentExPointA');
// hdc : HDC -> Pointer<Void>
// lpszString : LPCSTR -> Pointer<Utf8>
// cchString : INT -> Int32
// nMaxExtent : INT -> Int32
// lpnFit : INT* optional, out -> Pointer<Int32>
// lpnDx : INT* optional, out -> Pointer<Int32>
// lpSize : SIZE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetTextExtentExPointA(
hdc: THandle; // HDC
lpszString: PAnsiChar; // LPCSTR
cchString: Integer; // INT
nMaxExtent: Integer; // INT
lpnFit: Pointer; // INT* optional, out
lpnDx: Pointer; // INT* optional, out
lpSize: Pointer // SIZE* out
): BOOL; stdcall;
external 'GDI32.dll' name 'GetTextExtentExPointA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetTextExtentExPointA"
c_GetTextExtentExPointA :: Ptr () -> CString -> Int32 -> Int32 -> Ptr Int32 -> Ptr Int32 -> Ptr () -> IO CInt
-- hdc : HDC -> Ptr ()
-- lpszString : LPCSTR -> CString
-- cchString : INT -> Int32
-- nMaxExtent : INT -> Int32
-- lpnFit : INT* optional, out -> Ptr Int32
-- lpnDx : INT* optional, out -> Ptr Int32
-- lpSize : SIZE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gettextextentexpointa =
foreign "GetTextExtentExPointA"
((ptr void) @-> string @-> int32_t @-> int32_t @-> (ptr int32_t) @-> (ptr int32_t) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* lpszString : LPCSTR -> string *)
(* cchString : INT -> int32_t *)
(* nMaxExtent : INT -> int32_t *)
(* lpnFit : INT* optional, out -> (ptr int32_t) *)
(* lpnDx : INT* optional, out -> (ptr int32_t) *)
(* lpSize : SIZE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("GetTextExtentExPointA" get-text-extent-ex-point-a :convention :stdcall) :int32
(hdc :pointer) ; HDC
(lpsz-string :string) ; LPCSTR
(cch-string :int32) ; INT
(n-max-extent :int32) ; INT
(lpn-fit :pointer) ; INT* optional, out
(lpn-dx :pointer) ; INT* optional, out
(lp-size :pointer)) ; SIZE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetTextExtentExPointA = Win32::API::More->new('GDI32',
'BOOL GetTextExtentExPointA(HANDLE hdc, LPCSTR lpszString, int cchString, int nMaxExtent, LPVOID lpnFit, LPVOID lpnDx, LPVOID lpSize)');
# my $ret = $GetTextExtentExPointA->Call($hdc, $lpszString, $cchString, $nMaxExtent, $lpnFit, $lpnDx, $lpSize);
# hdc : HDC -> HANDLE
# lpszString : LPCSTR -> LPCSTR
# cchString : INT -> int
# nMaxExtent : INT -> int
# lpnFit : INT* optional, out -> LPVOID
# lpnDx : INT* optional, out -> LPVOID
# lpSize : SIZE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetTextExtentExPointW (Unicode版) — 指定幅に収まる文字数と寸法を取得する。
- f GetTextExtentPointA — 文字列を描画した際の寸法を取得する。