ホーム › Graphics.Gdi › DrawTextExW
DrawTextExW
関数書式オプションを指定して矩形内に文字列を描画する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
INT DrawTextExW(
HDC hdc,
LPWSTR lpchText,
INT cchText,
RECT* lprc,
DRAW_TEXT_FORMAT format,
DRAWTEXTPARAMS* lpdtp // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | in |
| lpchText | LPWSTR | inout |
| cchText | INT | in |
| lprc | RECT* | inout |
| format | DRAW_TEXT_FORMAT | in |
| lpdtp | DRAWTEXTPARAMS* | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
INT DrawTextExW(
HDC hdc,
LPWSTR lpchText,
INT cchText,
RECT* lprc,
DRAW_TEXT_FORMAT format,
DRAWTEXTPARAMS* lpdtp // optional
);[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int DrawTextExW(
IntPtr hdc, // HDC
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpchText, // LPWSTR in/out
int cchText, // INT
IntPtr lprc, // RECT* in/out
uint format, // DRAW_TEXT_FORMAT
IntPtr lpdtp // DRAWTEXTPARAMS* optional
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DrawTextExW(
hdc As IntPtr, ' HDC
<MarshalAs(UnmanagedType.LPWStr)> lpchText As System.Text.StringBuilder, ' LPWSTR in/out
cchText As Integer, ' INT
lprc As IntPtr, ' RECT* in/out
format As UInteger, ' DRAW_TEXT_FORMAT
lpdtp As IntPtr ' DRAWTEXTPARAMS* optional
) As Integer
End Function' hdc : HDC
' lpchText : LPWSTR in/out
' cchText : INT
' lprc : RECT* in/out
' format : DRAW_TEXT_FORMAT
' lpdtp : DRAWTEXTPARAMS* optional
Declare PtrSafe Function DrawTextExW Lib "user32" ( _
ByVal hdc As LongPtr, _
ByVal lpchText As LongPtr, _
ByVal cchText As Long, _
ByVal lprc As LongPtr, _
ByVal format As Long, _
ByVal lpdtp 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
DrawTextExW = ctypes.windll.user32.DrawTextExW
DrawTextExW.restype = ctypes.c_int
DrawTextExW.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.LPWSTR, # lpchText : LPWSTR in/out
ctypes.c_int, # cchText : INT
ctypes.c_void_p, # lprc : RECT* in/out
wintypes.DWORD, # format : DRAW_TEXT_FORMAT
ctypes.c_void_p, # lpdtp : DRAWTEXTPARAMS* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DrawTextExW = Fiddle::Function.new(
lib['DrawTextExW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # lpchText : LPWSTR in/out
Fiddle::TYPE_INT, # cchText : INT
Fiddle::TYPE_VOIDP, # lprc : RECT* in/out
-Fiddle::TYPE_INT, # format : DRAW_TEXT_FORMAT
Fiddle::TYPE_VOIDP, # lpdtp : DRAWTEXTPARAMS* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn DrawTextExW(
hdc: *mut core::ffi::c_void, // HDC
lpchText: *mut u16, // LPWSTR in/out
cchText: i32, // INT
lprc: *mut RECT, // RECT* in/out
format: u32, // DRAW_TEXT_FORMAT
lpdtp: *mut DRAWTEXTPARAMS // DRAWTEXTPARAMS* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern int DrawTextExW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpchText, int cchText, IntPtr lprc, uint format, IntPtr lpdtp);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DrawTextExW' -Namespace Win32 -PassThru
# $api::DrawTextExW(hdc, lpchText, cchText, lprc, format, lpdtp)#uselib "USER32.dll"
#func global DrawTextExW "DrawTextExW" wptr, wptr, wptr, wptr, wptr, wptr
; DrawTextExW hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp) ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpchText : LPWSTR in/out -> "wptr"
; cchText : INT -> "wptr"
; lprc : RECT* in/out -> "wptr"
; format : DRAW_TEXT_FORMAT -> "wptr"
; lpdtp : DRAWTEXTPARAMS* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global DrawTextExW "DrawTextExW" sptr, var, int, var, int, var ; res = DrawTextExW(hdc, lpchText, cchText, lprc, format, lpdtp) ; hdc : HDC -> "sptr" ; lpchText : LPWSTR in/out -> "var" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "var" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global DrawTextExW "DrawTextExW" sptr, sptr, int, sptr, int, sptr ; res = DrawTextExW(hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp)) ; hdc : HDC -> "sptr" ; lpchText : LPWSTR in/out -> "sptr" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "sptr" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT DrawTextExW(HDC hdc, LPWSTR lpchText, INT cchText, RECT* lprc, DRAW_TEXT_FORMAT format, DRAWTEXTPARAMS* lpdtp) #uselib "USER32.dll" #cfunc global DrawTextExW "DrawTextExW" intptr, var, int, var, int, var ; res = DrawTextExW(hdc, lpchText, cchText, lprc, format, lpdtp) ; hdc : HDC -> "intptr" ; lpchText : LPWSTR in/out -> "var" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "var" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT DrawTextExW(HDC hdc, LPWSTR lpchText, INT cchText, RECT* lprc, DRAW_TEXT_FORMAT format, DRAWTEXTPARAMS* lpdtp) #uselib "USER32.dll" #cfunc global DrawTextExW "DrawTextExW" intptr, intptr, int, intptr, int, intptr ; res = DrawTextExW(hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp)) ; hdc : HDC -> "intptr" ; lpchText : LPWSTR in/out -> "intptr" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "intptr" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procDrawTextExW = user32.NewProc("DrawTextExW")
)
// hdc (HDC), lpchText (LPWSTR in/out), cchText (INT), lprc (RECT* in/out), format (DRAW_TEXT_FORMAT), lpdtp (DRAWTEXTPARAMS* optional)
r1, _, err := procDrawTextExW.Call(
uintptr(hdc),
uintptr(lpchText),
uintptr(cchText),
uintptr(lprc),
uintptr(format),
uintptr(lpdtp),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction DrawTextExW(
hdc: THandle; // HDC
lpchText: PWideChar; // LPWSTR in/out
cchText: Integer; // INT
lprc: Pointer; // RECT* in/out
format: DWORD; // DRAW_TEXT_FORMAT
lpdtp: Pointer // DRAWTEXTPARAMS* optional
): Integer; stdcall;
external 'USER32.dll' name 'DrawTextExW';result := DllCall("USER32\DrawTextExW"
, "Ptr", hdc ; HDC
, "Ptr", lpchText ; LPWSTR in/out
, "Int", cchText ; INT
, "Ptr", lprc ; RECT* in/out
, "UInt", format ; DRAW_TEXT_FORMAT
, "Ptr", lpdtp ; DRAWTEXTPARAMS* optional
, "Int") ; return: INT●DrawTextExW(hdc, lpchText, cchText, lprc, format, lpdtp) = DLL("USER32.dll", "int DrawTextExW(void*, char*, int, void*, dword, void*)")
# 呼び出し: DrawTextExW(hdc, lpchText, cchText, lprc, format, lpdtp)
# hdc : HDC -> "void*"
# lpchText : LPWSTR in/out -> "char*"
# cchText : INT -> "int"
# lprc : RECT* in/out -> "void*"
# format : DRAW_TEXT_FORMAT -> "dword"
# lpdtp : DRAWTEXTPARAMS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。