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