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

GdipDrawString

関数
指定矩形内に文字列を描画する。
DLLgdiplus.dll呼出規約winapi

シグネチャ

// gdiplus.dll
#include <windows.h>

Status GdipDrawString(
    GpGraphics* graphics,
    LPCWSTR string,
    INT length,
    const GpFont* font,
    const RectF* layoutRect,
    const GpStringFormat* stringFormat,
    const GpBrush* brush
);

パラメーター

名前方向
graphicsGpGraphics*inout
stringLPCWSTRin
lengthINTin
fontGpFont*in
layoutRectRectF*in
stringFormatGpStringFormat*in
brushGpBrush*in

戻り値の型: Status

各言語での呼び出し定義

// gdiplus.dll
#include <windows.h>

Status GdipDrawString(
    GpGraphics* graphics,
    LPCWSTR string,
    INT length,
    const GpFont* font,
    const RectF* layoutRect,
    const GpStringFormat* stringFormat,
    const GpBrush* brush
);
[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipDrawString(
    IntPtr graphics,   // GpGraphics* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string string,   // LPCWSTR
    int length,   // INT
    IntPtr font,   // GpFont*
    IntPtr layoutRect,   // RectF*
    IntPtr stringFormat,   // GpStringFormat*
    IntPtr brush   // GpBrush*
);
<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipDrawString(
    graphics As IntPtr,   ' GpGraphics* in/out
    <MarshalAs(UnmanagedType.LPWStr)> [string] As String,   ' LPCWSTR
    length As Integer,   ' INT
    font As IntPtr,   ' GpFont*
    layoutRect As IntPtr,   ' RectF*
    stringFormat As IntPtr,   ' GpStringFormat*
    brush As IntPtr   ' GpBrush*
) As Integer
End Function
' graphics : GpGraphics* in/out
' string : LPCWSTR
' length : INT
' font : GpFont*
' layoutRect : RectF*
' stringFormat : GpStringFormat*
' brush : GpBrush*
Declare PtrSafe Function GdipDrawString Lib "gdiplus" ( _
    ByVal graphics As LongPtr, _
    ByVal string As LongPtr, _
    ByVal length As Long, _
    ByVal font As LongPtr, _
    ByVal layoutRect As LongPtr, _
    ByVal stringFormat As LongPtr, _
    ByVal brush As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GdipDrawString = ctypes.windll.gdiplus.GdipDrawString
GdipDrawString.restype = ctypes.c_int
GdipDrawString.argtypes = [
    ctypes.c_void_p,  # graphics : GpGraphics* in/out
    wintypes.LPCWSTR,  # string : LPCWSTR
    ctypes.c_int,  # length : INT
    ctypes.c_void_p,  # font : GpFont*
    ctypes.c_void_p,  # layoutRect : RectF*
    ctypes.c_void_p,  # stringFormat : GpStringFormat*
    ctypes.c_void_p,  # brush : GpBrush*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('gdiplus.dll')
GdipDrawString = Fiddle::Function.new(
  lib['GdipDrawString'],
  [
    Fiddle::TYPE_VOIDP,  # graphics : GpGraphics* in/out
    Fiddle::TYPE_VOIDP,  # string : LPCWSTR
    Fiddle::TYPE_INT,  # length : INT
    Fiddle::TYPE_VOIDP,  # font : GpFont*
    Fiddle::TYPE_VOIDP,  # layoutRect : RectF*
    Fiddle::TYPE_VOIDP,  # stringFormat : GpStringFormat*
    Fiddle::TYPE_VOIDP,  # brush : GpBrush*
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdiplus")]
extern "system" {
    fn GdipDrawString(
        graphics: *mut GpGraphics,  // GpGraphics* in/out
        string: *const u16,  // LPCWSTR
        length: i32,  // INT
        font: *const GpFont,  // GpFont*
        layoutRect: *const RectF,  // RectF*
        stringFormat: *const GpStringFormat,  // GpStringFormat*
        brush: *const GpBrush  // GpBrush*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipDrawString(IntPtr graphics, [MarshalAs(UnmanagedType.LPWStr)] string string, int length, IntPtr font, IntPtr layoutRect, IntPtr stringFormat, IntPtr brush);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipDrawString' -Namespace Win32 -PassThru
# $api::GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
#uselib "gdiplus.dll"
#func global GdipDrawString "GdipDrawString" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GdipDrawString varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(brush)   ; 戻り値は stat
; graphics : GpGraphics* in/out -> "sptr"
; string : LPCWSTR -> "sptr"
; length : INT -> "sptr"
; font : GpFont* -> "sptr"
; layoutRect : RectF* -> "sptr"
; stringFormat : GpStringFormat* -> "sptr"
; brush : GpBrush* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "gdiplus.dll"
#cfunc global GdipDrawString "GdipDrawString" var, wstr, int, var, var, var, var
; res = GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
; graphics : GpGraphics* in/out -> "var"
; string : LPCWSTR -> "wstr"
; length : INT -> "int"
; font : GpFont* -> "var"
; layoutRect : RectF* -> "var"
; stringFormat : GpStringFormat* -> "var"
; brush : GpBrush* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; Status GdipDrawString(GpGraphics* graphics, LPCWSTR string, INT length, GpFont* font, RectF* layoutRect, GpStringFormat* stringFormat, GpBrush* brush)
#uselib "gdiplus.dll"
#cfunc global GdipDrawString "GdipDrawString" var, wstr, int, var, var, var, var
; res = GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
; graphics : GpGraphics* in/out -> "var"
; string : LPCWSTR -> "wstr"
; length : INT -> "int"
; font : GpFont* -> "var"
; layoutRect : RectF* -> "var"
; stringFormat : GpStringFormat* -> "var"
; brush : GpBrush* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
	procGdipDrawString = gdiplus.NewProc("GdipDrawString")
)

// graphics (GpGraphics* in/out), string (LPCWSTR), length (INT), font (GpFont*), layoutRect (RectF*), stringFormat (GpStringFormat*), brush (GpBrush*)
r1, _, err := procGdipDrawString.Call(
	uintptr(graphics),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(string))),
	uintptr(length),
	uintptr(font),
	uintptr(layoutRect),
	uintptr(stringFormat),
	uintptr(brush),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // Status
function GdipDrawString(
  graphics: Pointer;   // GpGraphics* in/out
  string: PWideChar;   // LPCWSTR
  length: Integer;   // INT
  font: Pointer;   // GpFont*
  layoutRect: Pointer;   // RectF*
  stringFormat: Pointer;   // GpStringFormat*
  brush: Pointer   // GpBrush*
): Integer; stdcall;
  external 'gdiplus.dll' name 'GdipDrawString';
result := DllCall("gdiplus\GdipDrawString"
    , "Ptr", graphics   ; GpGraphics* in/out
    , "WStr", string   ; LPCWSTR
    , "Int", length   ; INT
    , "Ptr", font   ; GpFont*
    , "Ptr", layoutRect   ; RectF*
    , "Ptr", stringFormat   ; GpStringFormat*
    , "Ptr", brush   ; GpBrush*
    , "Int")   ; return: Status
●GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush) = DLL("gdiplus.dll", "int GdipDrawString(void*, char*, int, void*, void*, void*, void*)")
# 呼び出し: GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
# graphics : GpGraphics* in/out -> "void*"
# string : LPCWSTR -> "char*"
# length : INT -> "int"
# font : GpFont* -> "void*"
# layoutRect : RectF* -> "void*"
# stringFormat : GpStringFormat* -> "void*"
# brush : GpBrush* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。