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