Win32 API 日本語リファレンス
ホームGraphics.Gdi › GetTextExtentExPointI

GetTextExtentExPointI

関数
指定幅に収まるグリフ数と寸法を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL GetTextExtentExPointI(
    HDC hdc,
    WORD* lpwszString,
    INT cwchString,
    INT nMaxExtent,
    INT* lpnFit,   // optional
    INT* lpnDx,   // optional
    SIZE* lpSize
);

パラメーター

名前方向
hdcHDCin
lpwszStringWORD*in
cwchStringINTin
nMaxExtentINTin
lpnFitINT*outoptional
lpnDxINT*outoptional
lpSizeSIZE*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetTextExtentExPointI(
    HDC hdc,
    WORD* lpwszString,
    INT cwchString,
    INT nMaxExtent,
    INT* lpnFit,   // optional
    INT* lpnDx,   // optional
    SIZE* lpSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool GetTextExtentExPointI(
    IntPtr hdc,   // HDC
    ref ushort lpwszString,   // WORD*
    int cwchString,   // INT
    int nMaxExtent,   // INT
    IntPtr lpnFit,   // INT* optional, out
    IntPtr lpnDx,   // INT* optional, out
    IntPtr lpSize   // SIZE* out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetTextExtentExPointI(
    hdc As IntPtr,   ' HDC
    ByRef lpwszString As UShort,   ' WORD*
    cwchString 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 Boolean
End Function
' hdc : HDC
' lpwszString : WORD*
' cwchString : INT
' nMaxExtent : INT
' lpnFit : INT* optional, out
' lpnDx : INT* optional, out
' lpSize : SIZE* out
Declare PtrSafe Function GetTextExtentExPointI Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByRef lpwszString As Integer, _
    ByVal cwchString 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

GetTextExtentExPointI = ctypes.windll.gdi32.GetTextExtentExPointI
GetTextExtentExPointI.restype = wintypes.BOOL
GetTextExtentExPointI.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.POINTER(ctypes.c_ushort),  # lpwszString : WORD*
    ctypes.c_int,  # cwchString : 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')
GetTextExtentExPointI = Fiddle::Function.new(
  lib['GetTextExtentExPointI'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpwszString : WORD*
    Fiddle::TYPE_INT,  # cwchString : 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 GetTextExtentExPointI(
        hdc: *mut core::ffi::c_void,  // HDC
        lpwszString: *mut u16,  // WORD*
        cwchString: 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")]
public static extern bool GetTextExtentExPointI(IntPtr hdc, ref ushort lpwszString, int cwchString, int nMaxExtent, IntPtr lpnFit, IntPtr lpnDx, IntPtr lpSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetTextExtentExPointI' -Namespace Win32 -PassThru
# $api::GetTextExtentExPointI(hdc, lpwszString, cwchString, nMaxExtent, lpnFit, lpnDx, lpSize)
#uselib "GDI32.dll"
#func global GetTextExtentExPointI "GetTextExtentExPointI" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetTextExtentExPointI hdc, varptr(lpwszString), cwchString, nMaxExtent, varptr(lpnFit), varptr(lpnDx), varptr(lpSize)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; lpwszString : WORD* -> "sptr"
; cwchString : 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 GetTextExtentExPointI "GetTextExtentExPointI" sptr, var, int, int, var, var, var
; res = GetTextExtentExPointI(hdc, lpwszString, cwchString, nMaxExtent, lpnFit, lpnDx, lpSize)
; hdc : HDC -> "sptr"
; lpwszString : WORD* -> "var"
; cwchString : INT -> "int"
; nMaxExtent : INT -> "int"
; lpnFit : INT* optional, out -> "var"
; lpnDx : INT* optional, out -> "var"
; lpSize : SIZE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetTextExtentExPointI(HDC hdc, WORD* lpwszString, INT cwchString, INT nMaxExtent, INT* lpnFit, INT* lpnDx, SIZE* lpSize)
#uselib "GDI32.dll"
#cfunc global GetTextExtentExPointI "GetTextExtentExPointI" intptr, var, int, int, var, var, var
; res = GetTextExtentExPointI(hdc, lpwszString, cwchString, nMaxExtent, lpnFit, lpnDx, lpSize)
; hdc : HDC -> "intptr"
; lpwszString : WORD* -> "var"
; cwchString : INT -> "int"
; nMaxExtent : INT -> "int"
; lpnFit : INT* optional, out -> "var"
; lpnDx : INT* optional, out -> "var"
; lpSize : SIZE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetTextExtentExPointI = gdi32.NewProc("GetTextExtentExPointI")
)

// hdc (HDC), lpwszString (WORD*), cwchString (INT), nMaxExtent (INT), lpnFit (INT* optional, out), lpnDx (INT* optional, out), lpSize (SIZE* out)
r1, _, err := procGetTextExtentExPointI.Call(
	uintptr(hdc),
	uintptr(lpwszString),
	uintptr(cwchString),
	uintptr(nMaxExtent),
	uintptr(lpnFit),
	uintptr(lpnDx),
	uintptr(lpSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetTextExtentExPointI(
  hdc: THandle;   // HDC
  lpwszString: Pointer;   // WORD*
  cwchString: 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 'GetTextExtentExPointI';
result := DllCall("GDI32\GetTextExtentExPointI"
    , "Ptr", hdc   ; HDC
    , "Ptr", lpwszString   ; WORD*
    , "Int", cwchString   ; INT
    , "Int", nMaxExtent   ; INT
    , "Ptr", lpnFit   ; INT* optional, out
    , "Ptr", lpnDx   ; INT* optional, out
    , "Ptr", lpSize   ; SIZE* out
    , "Int")   ; return: BOOL
●GetTextExtentExPointI(hdc, lpwszString, cwchString, nMaxExtent, lpnFit, lpnDx, lpSize) = DLL("GDI32.dll", "bool GetTextExtentExPointI(void*, void*, int, int, void*, void*, void*)")
# 呼び出し: GetTextExtentExPointI(hdc, lpwszString, cwchString, nMaxExtent, lpnFit, lpnDx, lpSize)
# hdc : HDC -> "void*"
# lpwszString : WORD* -> "void*"
# cwchString : 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)。