ホーム › Graphics.GdiPlus › GdipDrawString
GdipDrawString
関数指定矩形内に文字列を描画する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| graphics | GpGraphics* | inout | 描画先のGpGraphicsオブジェクトへのポインタ。 |
| string | LPCWSTR | in | 描画する文字列を示すワイド文字列。 |
| length | INT | in | 文字列の長さ(文字数)。-1指定でNULL終端まで描画する。 |
| font | GpFont* | in | 描画に使用するGpFontオブジェクトへのポインタ。 |
| layoutRect | RectF* | in | 文字列を配置する矩形領域を示すRectF構造体へのポインタ。 |
| stringFormat | GpStringFormat* | in | 配置や折り返し等を制御するGpStringFormatへのポインタ。NULL可。 |
| brush | GpBrush* | in | 文字の塗りつぶしに使用するGpBrushオブジェクトへのポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipDrawString "GdipDrawString" sptr, wstr, int, sptr, sptr, sptr, sptr ; res = GdipDrawString(varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(brush)) ; graphics : GpGraphics* in/out -> "sptr" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "sptr" ; layoutRect : RectF* -> "sptr" ; stringFormat : GpStringFormat* -> "sptr" ; brush : GpBrush* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; Status GdipDrawString(GpGraphics* graphics, LPCWSTR string, INT length, GpFont* font, RectF* layoutRect, GpStringFormat* stringFormat, GpBrush* brush) #uselib "gdiplus.dll" #cfunc global GdipDrawString "GdipDrawString" intptr, wstr, int, intptr, intptr, intptr, intptr ; res = GdipDrawString(varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(brush)) ; graphics : GpGraphics* in/out -> "intptr" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "intptr" ; layoutRect : RectF* -> "intptr" ; stringFormat : GpStringFormat* -> "intptr" ; brush : GpBrush* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // Statusfunction 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)。const std = @import("std");
extern "gdiplus" fn GdipDrawString(
graphics: [*c]GpGraphics, // GpGraphics* in/out
string: [*c]const u16, // LPCWSTR
length: i32, // INT
font: [*c]GpFont, // GpFont*
layoutRect: [*c]RectF, // RectF*
stringFormat: [*c]GpStringFormat, // GpStringFormat*
brush: [*c]GpBrush // GpBrush*
) callconv(std.os.windows.WINAPI) i32;proc GdipDrawString(
graphics: ptr GpGraphics, # GpGraphics* in/out
string: WideCString, # LPCWSTR
length: int32, # INT
font: ptr GpFont, # GpFont*
layoutRect: ptr RectF, # RectF*
stringFormat: ptr GpStringFormat, # GpStringFormat*
brush: ptr GpBrush # GpBrush*
): int32 {.importc: "GdipDrawString", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipDrawString(
GpGraphics* graphics, // GpGraphics* in/out
const(wchar)* string, // LPCWSTR
int length, // INT
GpFont* font, // GpFont*
RectF* layoutRect, // RectF*
GpStringFormat* stringFormat, // GpStringFormat*
GpBrush* brush // GpBrush*
);ccall((:GdipDrawString, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpGraphics}, Cwstring, Int32, Ptr{GpFont}, Ptr{RectF}, Ptr{GpStringFormat}, Ptr{GpBrush}),
graphics, string, length, font, layoutRect, stringFormat, brush)
# graphics : GpGraphics* in/out -> Ptr{GpGraphics}
# string : LPCWSTR -> Cwstring
# length : INT -> Int32
# font : GpFont* -> Ptr{GpFont}
# layoutRect : RectF* -> Ptr{RectF}
# stringFormat : GpStringFormat* -> Ptr{GpStringFormat}
# brush : GpBrush* -> Ptr{GpBrush}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipDrawString(
void* graphics,
const uint16_t* string,
int32_t length,
void* font,
void* layoutRect,
void* stringFormat,
void* brush);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
-- graphics : GpGraphics* in/out
-- string : LPCWSTR
-- length : INT
-- font : GpFont*
-- layoutRect : RectF*
-- stringFormat : GpStringFormat*
-- brush : GpBrush*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipDrawString = lib.func('__stdcall', 'GdipDrawString', 'int32_t', ['void *', 'str16', 'int32_t', 'void *', 'void *', 'void *', 'void *']);
// GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
// graphics : GpGraphics* in/out -> 'void *'
// string : LPCWSTR -> 'str16'
// length : INT -> 'int32_t'
// font : GpFont* -> 'void *'
// layoutRect : RectF* -> 'void *'
// stringFormat : GpStringFormat* -> 'void *'
// brush : GpBrush* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipDrawString: { parameters: ["pointer", "buffer", "i32", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush)
// graphics : GpGraphics* in/out -> "pointer"
// string : LPCWSTR -> "buffer"
// length : INT -> "i32"
// font : GpFont* -> "pointer"
// layoutRect : RectF* -> "pointer"
// stringFormat : GpStringFormat* -> "pointer"
// brush : GpBrush* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipDrawString(
void* graphics,
const uint16_t* string,
int32_t length,
void* font,
void* layoutRect,
void* stringFormat,
void* brush);
C, "gdiplus.dll");
// $ffi->GdipDrawString(graphics, string, length, font, layoutRect, stringFormat, brush);
// graphics : GpGraphics* in/out
// string : LPCWSTR
// length : INT
// font : GpFont*
// layoutRect : RectF*
// stringFormat : GpStringFormat*
// brush : GpBrush*
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Gdiplus extends StdCallLibrary {
Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
int GdipDrawString(
Pointer graphics, // GpGraphics* in/out
WString string, // LPCWSTR
int length, // INT
Pointer font, // GpFont*
Pointer layoutRect, // RectF*
Pointer stringFormat, // GpStringFormat*
Pointer brush // GpBrush*
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipDrawString = GdipDrawString(
graphics : GpGraphics*, # GpGraphics* in/out
string : UInt16*, # LPCWSTR
length : Int32, # INT
font : GpFont*, # GpFont*
layoutRect : RectF*, # RectF*
stringFormat : GpStringFormat*, # GpStringFormat*
brush : GpBrush* # GpBrush*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GdipDrawStringNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef GdipDrawStringDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final GdipDrawString = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipDrawStringNative, GdipDrawStringDart>('GdipDrawString');
// graphics : GpGraphics* in/out -> Pointer<Void>
// string : LPCWSTR -> Pointer<Utf16>
// length : INT -> Int32
// font : GpFont* -> Pointer<Void>
// layoutRect : RectF* -> Pointer<Void>
// stringFormat : GpStringFormat* -> Pointer<Void>
// brush : GpBrush* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipDrawString"
c_GdipDrawString :: Ptr () -> CWString -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- graphics : GpGraphics* in/out -> Ptr ()
-- string : LPCWSTR -> CWString
-- length : INT -> Int32
-- font : GpFont* -> Ptr ()
-- layoutRect : RectF* -> Ptr ()
-- stringFormat : GpStringFormat* -> Ptr ()
-- brush : GpBrush* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipdrawstring =
foreign "GdipDrawString"
((ptr void) @-> (ptr uint16_t) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* graphics : GpGraphics* in/out -> (ptr void) *)
(* string : LPCWSTR -> (ptr uint16_t) *)
(* length : INT -> int32_t *)
(* font : GpFont* -> (ptr void) *)
(* layoutRect : RectF* -> (ptr void) *)
(* stringFormat : GpStringFormat* -> (ptr void) *)
(* brush : GpBrush* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipDrawString" gdip-draw-string :convention :stdcall) :int32
(graphics :pointer) ; GpGraphics* in/out
(string (:string :encoding :utf-16le)) ; LPCWSTR
(length :int32) ; INT
(font :pointer) ; GpFont*
(layout-rect :pointer) ; RectF*
(string-format :pointer) ; GpStringFormat*
(brush :pointer)) ; GpBrush*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipDrawString = Win32::API::More->new('gdiplus',
'int GdipDrawString(LPVOID graphics, LPCWSTR string, int length, LPVOID font, LPVOID layoutRect, LPVOID stringFormat, LPVOID brush)');
# my $ret = $GdipDrawString->Call($graphics, $string, $length, $font, $layoutRect, $stringFormat, $brush);
# graphics : GpGraphics* in/out -> LPVOID
# string : LPCWSTR -> LPCWSTR
# length : INT -> int
# font : GpFont* -> LPVOID
# layoutRect : RectF* -> LPVOID
# stringFormat : GpStringFormat* -> LPVOID
# brush : GpBrush* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。