ホーム › Graphics.Gdi › GetTextExtentPointW
GetTextExtentPointW
関数文字列を描画した際の寸法を取得する。
シグネチャ
// GDI32.dll (Unicode / -W)
#include <windows.h>
BOOL GetTextExtentPointW(
HDC hdc,
LPCWSTR lpString,
INT c,
SIZE* lpsz
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | in |
| lpString | LPCWSTR | in |
| c | INT | in |
| lpsz | SIZE* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// GDI32.dll (Unicode / -W)
#include <windows.h>
BOOL GetTextExtentPointW(
HDC hdc,
LPCWSTR lpString,
INT c,
SIZE* lpsz
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetTextExtentPointW(
IntPtr hdc, // HDC
[MarshalAs(UnmanagedType.LPWStr)] string lpString, // LPCWSTR
int c, // INT
IntPtr lpsz // SIZE* out
);<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetTextExtentPointW(
hdc As IntPtr, ' HDC
<MarshalAs(UnmanagedType.LPWStr)> lpString As String, ' LPCWSTR
c As Integer, ' INT
lpsz As IntPtr ' SIZE* out
) As Boolean
End Function' hdc : HDC
' lpString : LPCWSTR
' c : INT
' lpsz : SIZE* out
Declare PtrSafe Function GetTextExtentPointW Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal lpString As LongPtr, _
ByVal c As Long, _
ByVal lpsz 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
GetTextExtentPointW = ctypes.windll.gdi32.GetTextExtentPointW
GetTextExtentPointW.restype = wintypes.BOOL
GetTextExtentPointW.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.LPCWSTR, # lpString : LPCWSTR
ctypes.c_int, # c : INT
ctypes.c_void_p, # lpsz : SIZE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetTextExtentPointW = Fiddle::Function.new(
lib['GetTextExtentPointW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # lpString : LPCWSTR
Fiddle::TYPE_INT, # c : INT
Fiddle::TYPE_VOIDP, # lpsz : SIZE* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "gdi32")]
extern "system" {
fn GetTextExtentPointW(
hdc: *mut core::ffi::c_void, // HDC
lpString: *const u16, // LPCWSTR
c: i32, // INT
lpsz: *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.Unicode)]
public static extern bool GetTextExtentPointW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpString, int c, IntPtr lpsz);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetTextExtentPointW' -Namespace Win32 -PassThru
# $api::GetTextExtentPointW(hdc, lpString, c, lpsz)#uselib "GDI32.dll"
#func global GetTextExtentPointW "GetTextExtentPointW" wptr, wptr, wptr, wptr
; GetTextExtentPointW hdc, lpString, c, varptr(lpsz) ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpString : LPCWSTR -> "wptr"
; c : INT -> "wptr"
; lpsz : SIZE* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global GetTextExtentPointW "GetTextExtentPointW" sptr, wstr, int, var ; res = GetTextExtentPointW(hdc, lpString, c, lpsz) ; hdc : HDC -> "sptr" ; lpString : LPCWSTR -> "wstr" ; c : INT -> "int" ; lpsz : SIZE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global GetTextExtentPointW "GetTextExtentPointW" sptr, wstr, int, sptr ; res = GetTextExtentPointW(hdc, lpString, c, varptr(lpsz)) ; hdc : HDC -> "sptr" ; lpString : LPCWSTR -> "wstr" ; c : INT -> "int" ; lpsz : SIZE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetTextExtentPointW(HDC hdc, LPCWSTR lpString, INT c, SIZE* lpsz) #uselib "GDI32.dll" #cfunc global GetTextExtentPointW "GetTextExtentPointW" intptr, wstr, int, var ; res = GetTextExtentPointW(hdc, lpString, c, lpsz) ; hdc : HDC -> "intptr" ; lpString : LPCWSTR -> "wstr" ; c : INT -> "int" ; lpsz : SIZE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetTextExtentPointW(HDC hdc, LPCWSTR lpString, INT c, SIZE* lpsz) #uselib "GDI32.dll" #cfunc global GetTextExtentPointW "GetTextExtentPointW" intptr, wstr, int, intptr ; res = GetTextExtentPointW(hdc, lpString, c, varptr(lpsz)) ; hdc : HDC -> "intptr" ; lpString : LPCWSTR -> "wstr" ; c : INT -> "int" ; lpsz : SIZE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetTextExtentPointW = gdi32.NewProc("GetTextExtentPointW")
)
// hdc (HDC), lpString (LPCWSTR), c (INT), lpsz (SIZE* out)
r1, _, err := procGetTextExtentPointW.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpString))),
uintptr(c),
uintptr(lpsz),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetTextExtentPointW(
hdc: THandle; // HDC
lpString: PWideChar; // LPCWSTR
c: Integer; // INT
lpsz: Pointer // SIZE* out
): BOOL; stdcall;
external 'GDI32.dll' name 'GetTextExtentPointW';result := DllCall("GDI32\GetTextExtentPointW"
, "Ptr", hdc ; HDC
, "WStr", lpString ; LPCWSTR
, "Int", c ; INT
, "Ptr", lpsz ; SIZE* out
, "Int") ; return: BOOL●GetTextExtentPointW(hdc, lpString, c, lpsz) = DLL("GDI32.dll", "bool GetTextExtentPointW(void*, char*, int, void*)")
# 呼び出し: GetTextExtentPointW(hdc, lpString, c, lpsz)
# hdc : HDC -> "void*"
# lpString : LPCWSTR -> "char*"
# c : INT -> "int"
# lpsz : SIZE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。