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

GetCharWidthI

関数
グリフインデックスごとの文字幅を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL GetCharWidthI(
    HDC hdc,
    DWORD giFirst,
    DWORD cgi,
    WORD* pgi,   // optional
    INT* piWidths
);

パラメーター

名前方向
hdcHDCin
giFirstDWORDin
cgiDWORDin
pgiWORD*inoptional
piWidthsINT*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetCharWidthI(
    HDC hdc,
    DWORD giFirst,
    DWORD cgi,
    WORD* pgi,   // optional
    INT* piWidths
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool GetCharWidthI(
    IntPtr hdc,   // HDC
    uint giFirst,   // DWORD
    uint cgi,   // DWORD
    IntPtr pgi,   // WORD* optional
    out int piWidths   // INT* out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetCharWidthI(
    hdc As IntPtr,   ' HDC
    giFirst As UInteger,   ' DWORD
    cgi As UInteger,   ' DWORD
    pgi As IntPtr,   ' WORD* optional
    <Out> ByRef piWidths As Integer   ' INT* out
) As Boolean
End Function
' hdc : HDC
' giFirst : DWORD
' cgi : DWORD
' pgi : WORD* optional
' piWidths : INT* out
Declare PtrSafe Function GetCharWidthI Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal giFirst As Long, _
    ByVal cgi As Long, _
    ByVal pgi As LongPtr, _
    ByRef piWidths As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetCharWidthI = ctypes.windll.gdi32.GetCharWidthI
GetCharWidthI.restype = wintypes.BOOL
GetCharWidthI.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # giFirst : DWORD
    wintypes.DWORD,  # cgi : DWORD
    ctypes.POINTER(ctypes.c_ushort),  # pgi : WORD* optional
    ctypes.POINTER(ctypes.c_int),  # piWidths : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetCharWidthI = Fiddle::Function.new(
  lib['GetCharWidthI'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    -Fiddle::TYPE_INT,  # giFirst : DWORD
    -Fiddle::TYPE_INT,  # cgi : DWORD
    Fiddle::TYPE_VOIDP,  # pgi : WORD* optional
    Fiddle::TYPE_VOIDP,  # piWidths : INT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetCharWidthI(
        hdc: *mut core::ffi::c_void,  // HDC
        giFirst: u32,  // DWORD
        cgi: u32,  // DWORD
        pgi: *mut u16,  // WORD* optional
        piWidths: *mut i32  // INT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool GetCharWidthI(IntPtr hdc, uint giFirst, uint cgi, IntPtr pgi, out int piWidths);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetCharWidthI' -Namespace Win32 -PassThru
# $api::GetCharWidthI(hdc, giFirst, cgi, pgi, piWidths)
#uselib "GDI32.dll"
#func global GetCharWidthI "GetCharWidthI" sptr, sptr, sptr, sptr, sptr
; GetCharWidthI hdc, giFirst, cgi, varptr(pgi), varptr(piWidths)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; giFirst : DWORD -> "sptr"
; cgi : DWORD -> "sptr"
; pgi : WORD* optional -> "sptr"
; piWidths : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetCharWidthI "GetCharWidthI" sptr, int, int, var, var
; res = GetCharWidthI(hdc, giFirst, cgi, pgi, piWidths)
; hdc : HDC -> "sptr"
; giFirst : DWORD -> "int"
; cgi : DWORD -> "int"
; pgi : WORD* optional -> "var"
; piWidths : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetCharWidthI(HDC hdc, DWORD giFirst, DWORD cgi, WORD* pgi, INT* piWidths)
#uselib "GDI32.dll"
#cfunc global GetCharWidthI "GetCharWidthI" intptr, int, int, var, var
; res = GetCharWidthI(hdc, giFirst, cgi, pgi, piWidths)
; hdc : HDC -> "intptr"
; giFirst : DWORD -> "int"
; cgi : DWORD -> "int"
; pgi : WORD* optional -> "var"
; piWidths : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetCharWidthI = gdi32.NewProc("GetCharWidthI")
)

// hdc (HDC), giFirst (DWORD), cgi (DWORD), pgi (WORD* optional), piWidths (INT* out)
r1, _, err := procGetCharWidthI.Call(
	uintptr(hdc),
	uintptr(giFirst),
	uintptr(cgi),
	uintptr(pgi),
	uintptr(piWidths),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetCharWidthI(
  hdc: THandle;   // HDC
  giFirst: DWORD;   // DWORD
  cgi: DWORD;   // DWORD
  pgi: Pointer;   // WORD* optional
  piWidths: Pointer   // INT* out
): BOOL; stdcall;
  external 'GDI32.dll' name 'GetCharWidthI';
result := DllCall("GDI32\GetCharWidthI"
    , "Ptr", hdc   ; HDC
    , "UInt", giFirst   ; DWORD
    , "UInt", cgi   ; DWORD
    , "Ptr", pgi   ; WORD* optional
    , "Ptr", piWidths   ; INT* out
    , "Int")   ; return: BOOL
●GetCharWidthI(hdc, giFirst, cgi, pgi, piWidths) = DLL("GDI32.dll", "bool GetCharWidthI(void*, dword, dword, void*, void*)")
# 呼び出し: GetCharWidthI(hdc, giFirst, cgi, pgi, piWidths)
# hdc : HDC -> "void*"
# giFirst : DWORD -> "dword"
# cgi : DWORD -> "dword"
# pgi : WORD* optional -> "void*"
# piWidths : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。