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

TextOutW

関数
指定座標に文字列を出力する(Unicode版)。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL TextOutW(
    HDC hdc,
    INT x,
    INT y,
    LPCWSTR lpString,
    INT c
);

パラメーター

名前方向
hdcHDCin
xINTin
yINTin
lpStringLPCWSTRin
cINTin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL TextOutW(
    HDC hdc,
    INT x,
    INT y,
    LPCWSTR lpString,
    INT c
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool TextOutW(
    IntPtr hdc,   // HDC
    int x,   // INT
    int y,   // INT
    [MarshalAs(UnmanagedType.LPWStr)] string lpString,   // LPCWSTR
    int c   // INT
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function TextOutW(
    hdc As IntPtr,   ' HDC
    x As Integer,   ' INT
    y As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPWStr)> lpString As String,   ' LPCWSTR
    c As Integer   ' INT
) As Boolean
End Function
' hdc : HDC
' x : INT
' y : INT
' lpString : LPCWSTR
' c : INT
Declare PtrSafe Function TextOutW Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal lpString As LongPtr, _
    ByVal c 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

TextOutW = ctypes.windll.gdi32.TextOutW
TextOutW.restype = wintypes.BOOL
TextOutW.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # x : INT
    ctypes.c_int,  # y : INT
    wintypes.LPCWSTR,  # lpString : LPCWSTR
    ctypes.c_int,  # c : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
TextOutW = Fiddle::Function.new(
  lib['TextOutW'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # x : INT
    Fiddle::TYPE_INT,  # y : INT
    Fiddle::TYPE_VOIDP,  # lpString : LPCWSTR
    Fiddle::TYPE_INT,  # c : INT
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn TextOutW(
        hdc: *mut core::ffi::c_void,  // HDC
        x: i32,  // INT
        y: i32,  // INT
        lpString: *const u16,  // LPCWSTR
        c: i32  // INT
    ) -> 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 TextOutW(IntPtr hdc, int x, int y, [MarshalAs(UnmanagedType.LPWStr)] string lpString, int c);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_TextOutW' -Namespace Win32 -PassThru
# $api::TextOutW(hdc, x, y, lpString, c)
#uselib "GDI32.dll"
#func global TextOutW "TextOutW" wptr, wptr, wptr, wptr, wptr
; TextOutW hdc, x, y, lpString, c   ; 戻り値は stat
; hdc : HDC -> "wptr"
; x : INT -> "wptr"
; y : INT -> "wptr"
; lpString : LPCWSTR -> "wptr"
; c : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global TextOutW "TextOutW" sptr, int, int, wstr, int
; res = TextOutW(hdc, x, y, lpString, c)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; lpString : LPCWSTR -> "wstr"
; c : INT -> "int"
; BOOL TextOutW(HDC hdc, INT x, INT y, LPCWSTR lpString, INT c)
#uselib "GDI32.dll"
#cfunc global TextOutW "TextOutW" intptr, int, int, wstr, int
; res = TextOutW(hdc, x, y, lpString, c)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; lpString : LPCWSTR -> "wstr"
; c : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procTextOutW = gdi32.NewProc("TextOutW")
)

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