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

GetTabbedTextExtentW

関数
タブを展開した文字列の表示寸法を取得する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetTabbedTextExtentW(
    HDC hdc,
    LPCWSTR lpString,
    INT chCount,
    INT nTabPositions,
    const INT* lpnTabStopPositions   // optional
);

パラメーター

名前方向
hdcHDCin
lpStringLPCWSTRin
chCountINTin
nTabPositionsINTin
lpnTabStopPositionsINT*inoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetTabbedTextExtentW(
    HDC hdc,
    LPCWSTR lpString,
    INT chCount,
    INT nTabPositions,
    const INT* lpnTabStopPositions   // optional
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint GetTabbedTextExtentW(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPWStr)] string lpString,   // LPCWSTR
    int chCount,   // INT
    int nTabPositions,   // INT
    IntPtr lpnTabStopPositions   // INT* optional
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetTabbedTextExtentW(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPWStr)> lpString As String,   ' LPCWSTR
    chCount As Integer,   ' INT
    nTabPositions As Integer,   ' INT
    lpnTabStopPositions As IntPtr   ' INT* optional
) As UInteger
End Function
' hdc : HDC
' lpString : LPCWSTR
' chCount : INT
' nTabPositions : INT
' lpnTabStopPositions : INT* optional
Declare PtrSafe Function GetTabbedTextExtentW Lib "user32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpString As LongPtr, _
    ByVal chCount As Long, _
    ByVal nTabPositions As Long, _
    ByVal lpnTabStopPositions 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

GetTabbedTextExtentW = ctypes.windll.user32.GetTabbedTextExtentW
GetTabbedTextExtentW.restype = wintypes.DWORD
GetTabbedTextExtentW.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCWSTR,  # lpString : LPCWSTR
    ctypes.c_int,  # chCount : INT
    ctypes.c_int,  # nTabPositions : INT
    ctypes.POINTER(ctypes.c_int),  # lpnTabStopPositions : INT* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetTabbedTextExtentW = Fiddle::Function.new(
  lib['GetTabbedTextExtentW'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpString : LPCWSTR
    Fiddle::TYPE_INT,  # chCount : INT
    Fiddle::TYPE_INT,  # nTabPositions : INT
    Fiddle::TYPE_VOIDP,  # lpnTabStopPositions : INT* optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn GetTabbedTextExtentW(
        hdc: *mut core::ffi::c_void,  // HDC
        lpString: *const u16,  // LPCWSTR
        chCount: i32,  // INT
        nTabPositions: i32,  // INT
        lpnTabStopPositions: *const i32  // INT* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern uint GetTabbedTextExtentW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpString, int chCount, int nTabPositions, IntPtr lpnTabStopPositions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetTabbedTextExtentW' -Namespace Win32 -PassThru
# $api::GetTabbedTextExtentW(hdc, lpString, chCount, nTabPositions, lpnTabStopPositions)
#uselib "USER32.dll"
#func global GetTabbedTextExtentW "GetTabbedTextExtentW" wptr, wptr, wptr, wptr, wptr
; GetTabbedTextExtentW hdc, lpString, chCount, nTabPositions, varptr(lpnTabStopPositions)   ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpString : LPCWSTR -> "wptr"
; chCount : INT -> "wptr"
; nTabPositions : INT -> "wptr"
; lpnTabStopPositions : INT* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetTabbedTextExtentW "GetTabbedTextExtentW" sptr, wstr, int, int, var
; res = GetTabbedTextExtentW(hdc, lpString, chCount, nTabPositions, lpnTabStopPositions)
; hdc : HDC -> "sptr"
; lpString : LPCWSTR -> "wstr"
; chCount : INT -> "int"
; nTabPositions : INT -> "int"
; lpnTabStopPositions : INT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetTabbedTextExtentW(HDC hdc, LPCWSTR lpString, INT chCount, INT nTabPositions, INT* lpnTabStopPositions)
#uselib "USER32.dll"
#cfunc global GetTabbedTextExtentW "GetTabbedTextExtentW" intptr, wstr, int, int, var
; res = GetTabbedTextExtentW(hdc, lpString, chCount, nTabPositions, lpnTabStopPositions)
; hdc : HDC -> "intptr"
; lpString : LPCWSTR -> "wstr"
; chCount : INT -> "int"
; nTabPositions : INT -> "int"
; lpnTabStopPositions : INT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetTabbedTextExtentW = user32.NewProc("GetTabbedTextExtentW")
)

// hdc (HDC), lpString (LPCWSTR), chCount (INT), nTabPositions (INT), lpnTabStopPositions (INT* optional)
r1, _, err := procGetTabbedTextExtentW.Call(
	uintptr(hdc),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpString))),
	uintptr(chCount),
	uintptr(nTabPositions),
	uintptr(lpnTabStopPositions),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetTabbedTextExtentW(
  hdc: THandle;   // HDC
  lpString: PWideChar;   // LPCWSTR
  chCount: Integer;   // INT
  nTabPositions: Integer;   // INT
  lpnTabStopPositions: Pointer   // INT* optional
): DWORD; stdcall;
  external 'USER32.dll' name 'GetTabbedTextExtentW';
result := DllCall("USER32\GetTabbedTextExtentW"
    , "Ptr", hdc   ; HDC
    , "WStr", lpString   ; LPCWSTR
    , "Int", chCount   ; INT
    , "Int", nTabPositions   ; INT
    , "Ptr", lpnTabStopPositions   ; INT* optional
    , "UInt")   ; return: DWORD
●GetTabbedTextExtentW(hdc, lpString, chCount, nTabPositions, lpnTabStopPositions) = DLL("USER32.dll", "dword GetTabbedTextExtentW(void*, char*, int, int, void*)")
# 呼び出し: GetTabbedTextExtentW(hdc, lpString, chCount, nTabPositions, lpnTabStopPositions)
# hdc : HDC -> "void*"
# lpString : LPCWSTR -> "char*"
# chCount : INT -> "int"
# nTabPositions : INT -> "int"
# lpnTabStopPositions : INT* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。