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

GetCharABCWidthsW

関数
TrueTypeフォントの文字のABC幅を取得する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll  (Unicode / -W)
#include <windows.h>

BOOL GetCharABCWidthsW(
    HDC hdc,
    DWORD wFirst,
    DWORD wLast,
    ABC* lpABC
);

パラメーター

名前方向
hdcHDCin
wFirstDWORDin
wLastDWORDin
lpABCABC*out

戻り値の型: BOOL

各言語での呼び出し定義

// GDI32.dll  (Unicode / -W)
#include <windows.h>

BOOL GetCharABCWidthsW(
    HDC hdc,
    DWORD wFirst,
    DWORD wLast,
    ABC* lpABC
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetCharABCWidthsW(
    IntPtr hdc,   // HDC
    uint wFirst,   // DWORD
    uint wLast,   // DWORD
    IntPtr lpABC   // ABC* out
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetCharABCWidthsW(
    hdc As IntPtr,   ' HDC
    wFirst As UInteger,   ' DWORD
    wLast As UInteger,   ' DWORD
    lpABC As IntPtr   ' ABC* out
) As Boolean
End Function
' hdc : HDC
' wFirst : DWORD
' wLast : DWORD
' lpABC : ABC* out
Declare PtrSafe Function GetCharABCWidthsW Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal wFirst As Long, _
    ByVal wLast As Long, _
    ByVal lpABC 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

GetCharABCWidthsW = ctypes.windll.gdi32.GetCharABCWidthsW
GetCharABCWidthsW.restype = wintypes.BOOL
GetCharABCWidthsW.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # wFirst : DWORD
    wintypes.DWORD,  # wLast : DWORD
    ctypes.c_void_p,  # lpABC : ABC* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetCharABCWidthsW = Fiddle::Function.new(
  lib['GetCharABCWidthsW'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    -Fiddle::TYPE_INT,  # wFirst : DWORD
    -Fiddle::TYPE_INT,  # wLast : DWORD
    Fiddle::TYPE_VOIDP,  # lpABC : ABC* out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn GetCharABCWidthsW(
        hdc: *mut core::ffi::c_void,  // HDC
        wFirst: u32,  // DWORD
        wLast: u32,  // DWORD
        lpABC: *mut ABC  // ABC* 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 GetCharABCWidthsW(IntPtr hdc, uint wFirst, uint wLast, IntPtr lpABC);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetCharABCWidthsW' -Namespace Win32 -PassThru
# $api::GetCharABCWidthsW(hdc, wFirst, wLast, lpABC)
#uselib "GDI32.dll"
#func global GetCharABCWidthsW "GetCharABCWidthsW" wptr, wptr, wptr, wptr
; GetCharABCWidthsW hdc, wFirst, wLast, varptr(lpABC)   ; 戻り値は stat
; hdc : HDC -> "wptr"
; wFirst : DWORD -> "wptr"
; wLast : DWORD -> "wptr"
; lpABC : ABC* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetCharABCWidthsW "GetCharABCWidthsW" sptr, int, int, var
; res = GetCharABCWidthsW(hdc, wFirst, wLast, lpABC)
; hdc : HDC -> "sptr"
; wFirst : DWORD -> "int"
; wLast : DWORD -> "int"
; lpABC : ABC* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetCharABCWidthsW(HDC hdc, DWORD wFirst, DWORD wLast, ABC* lpABC)
#uselib "GDI32.dll"
#cfunc global GetCharABCWidthsW "GetCharABCWidthsW" intptr, int, int, var
; res = GetCharABCWidthsW(hdc, wFirst, wLast, lpABC)
; hdc : HDC -> "intptr"
; wFirst : DWORD -> "int"
; wLast : DWORD -> "int"
; lpABC : ABC* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetCharABCWidthsW = gdi32.NewProc("GetCharABCWidthsW")
)

// hdc (HDC), wFirst (DWORD), wLast (DWORD), lpABC (ABC* out)
r1, _, err := procGetCharABCWidthsW.Call(
	uintptr(hdc),
	uintptr(wFirst),
	uintptr(wLast),
	uintptr(lpABC),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetCharABCWidthsW(
  hdc: THandle;   // HDC
  wFirst: DWORD;   // DWORD
  wLast: DWORD;   // DWORD
  lpABC: Pointer   // ABC* out
): BOOL; stdcall;
  external 'GDI32.dll' name 'GetCharABCWidthsW';
result := DllCall("GDI32\GetCharABCWidthsW"
    , "Ptr", hdc   ; HDC
    , "UInt", wFirst   ; DWORD
    , "UInt", wLast   ; DWORD
    , "Ptr", lpABC   ; ABC* out
    , "Int")   ; return: BOOL
●GetCharABCWidthsW(hdc, wFirst, wLast, lpABC) = DLL("GDI32.dll", "bool GetCharABCWidthsW(void*, dword, dword, void*)")
# 呼び出し: GetCharABCWidthsW(hdc, wFirst, wLast, lpABC)
# hdc : HDC -> "void*"
# wFirst : DWORD -> "dword"
# wLast : DWORD -> "dword"
# lpABC : ABC* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。