ホーム › Graphics.Gdi › DrawTextExA
DrawTextExA
関数書式オプションを指定して矩形内に文字列を描画する(ANSI版)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
INT DrawTextExA(
HDC hdc,
LPSTR lpchText,
INT cchText,
RECT* lprc,
DRAW_TEXT_FORMAT format,
DRAWTEXTPARAMS* lpdtp // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | in |
| lpchText | LPSTR | inout |
| cchText | INT | in |
| lprc | RECT* | inout |
| format | DRAW_TEXT_FORMAT | in |
| lpdtp | DRAWTEXTPARAMS* | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
INT DrawTextExA(
HDC hdc,
LPSTR lpchText,
INT cchText,
RECT* lprc,
DRAW_TEXT_FORMAT format,
DRAWTEXTPARAMS* lpdtp // optional
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int DrawTextExA(
IntPtr hdc, // HDC
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpchText, // LPSTR in/out
int cchText, // INT
IntPtr lprc, // RECT* in/out
uint format, // DRAW_TEXT_FORMAT
IntPtr lpdtp // DRAWTEXTPARAMS* optional
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DrawTextExA(
hdc As IntPtr, ' HDC
<MarshalAs(UnmanagedType.LPStr)> lpchText As System.Text.StringBuilder, ' LPSTR 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 : LPSTR in/out
' cchText : INT
' lprc : RECT* in/out
' format : DRAW_TEXT_FORMAT
' lpdtp : DRAWTEXTPARAMS* optional
Declare PtrSafe Function DrawTextExA Lib "user32" ( _
ByVal hdc As LongPtr, _
ByVal lpchText As String, _
ByVal cchText As Long, _
ByVal lprc As LongPtr, _
ByVal format As Long, _
ByVal lpdtp As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DrawTextExA = ctypes.windll.user32.DrawTextExA
DrawTextExA.restype = ctypes.c_int
DrawTextExA.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.LPSTR, # lpchText : LPSTR 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')
DrawTextExA = Fiddle::Function.new(
lib['DrawTextExA'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # lpchText : LPSTR 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)#[link(name = "user32")]
extern "system" {
fn DrawTextExA(
hdc: *mut core::ffi::c_void, // HDC
lpchText: *mut u8, // LPSTR 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.Ansi)]
public static extern int DrawTextExA(IntPtr hdc, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpchText, int cchText, IntPtr lprc, uint format, IntPtr lpdtp);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DrawTextExA' -Namespace Win32 -PassThru
# $api::DrawTextExA(hdc, lpchText, cchText, lprc, format, lpdtp)#uselib "USER32.dll"
#func global DrawTextExA "DrawTextExA" sptr, sptr, sptr, sptr, sptr, sptr
; DrawTextExA hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp) ; 戻り値は stat
; hdc : HDC -> "sptr"
; lpchText : LPSTR in/out -> "sptr"
; cchText : INT -> "sptr"
; lprc : RECT* in/out -> "sptr"
; format : DRAW_TEXT_FORMAT -> "sptr"
; lpdtp : DRAWTEXTPARAMS* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global DrawTextExA "DrawTextExA" sptr, var, int, var, int, var ; res = DrawTextExA(hdc, lpchText, cchText, lprc, format, lpdtp) ; hdc : HDC -> "sptr" ; lpchText : LPSTR 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 DrawTextExA "DrawTextExA" sptr, sptr, int, sptr, int, sptr ; res = DrawTextExA(hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp)) ; hdc : HDC -> "sptr" ; lpchText : LPSTR in/out -> "sptr" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "sptr" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT DrawTextExA(HDC hdc, LPSTR lpchText, INT cchText, RECT* lprc, DRAW_TEXT_FORMAT format, DRAWTEXTPARAMS* lpdtp) #uselib "USER32.dll" #cfunc global DrawTextExA "DrawTextExA" intptr, var, int, var, int, var ; res = DrawTextExA(hdc, lpchText, cchText, lprc, format, lpdtp) ; hdc : HDC -> "intptr" ; lpchText : LPSTR in/out -> "var" ; cchText : INT -> "int" ; lprc : RECT* in/out -> "var" ; format : DRAW_TEXT_FORMAT -> "int" ; lpdtp : DRAWTEXTPARAMS* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT DrawTextExA(HDC hdc, LPSTR lpchText, INT cchText, RECT* lprc, DRAW_TEXT_FORMAT format, DRAWTEXTPARAMS* lpdtp) #uselib "USER32.dll" #cfunc global DrawTextExA "DrawTextExA" intptr, intptr, int, intptr, int, intptr ; res = DrawTextExA(hdc, varptr(lpchText), cchText, varptr(lprc), format, varptr(lpdtp)) ; hdc : HDC -> "intptr" ; lpchText : LPSTR 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")
procDrawTextExA = user32.NewProc("DrawTextExA")
)
// hdc (HDC), lpchText (LPSTR in/out), cchText (INT), lprc (RECT* in/out), format (DRAW_TEXT_FORMAT), lpdtp (DRAWTEXTPARAMS* optional)
r1, _, err := procDrawTextExA.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 DrawTextExA(
hdc: THandle; // HDC
lpchText: PAnsiChar; // LPSTR 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 'DrawTextExA';result := DllCall("USER32\DrawTextExA"
, "Ptr", hdc ; HDC
, "Ptr", lpchText ; LPSTR in/out
, "Int", cchText ; INT
, "Ptr", lprc ; RECT* in/out
, "UInt", format ; DRAW_TEXT_FORMAT
, "Ptr", lpdtp ; DRAWTEXTPARAMS* optional
, "Int") ; return: INT●DrawTextExA(hdc, lpchText, cchText, lprc, format, lpdtp) = DLL("USER32.dll", "int DrawTextExA(void*, char*, int, void*, dword, void*)")
# 呼び出し: DrawTextExA(hdc, lpchText, cchText, lprc, format, lpdtp)
# hdc : HDC -> "void*"
# lpchText : LPSTR 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)。