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