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

GdipDrawLine

関数
指定ペンで2点間に直線を描画する。
DLLgdiplus.dll呼出規約winapi

シグネチャ

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

Status GdipDrawLine(
    GpGraphics* graphics,
    GpPen* pen,
    FLOAT x1,
    FLOAT y1,
    FLOAT x2,
    FLOAT y2
);

パラメーター

名前方向
graphicsGpGraphics*inout
penGpPen*inout
x1FLOATin
y1FLOATin
x2FLOATin
y2FLOATin

戻り値の型: Status

各言語での呼び出し定義

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

Status GdipDrawLine(
    GpGraphics* graphics,
    GpPen* pen,
    FLOAT x1,
    FLOAT y1,
    FLOAT x2,
    FLOAT y2
);
[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipDrawLine(
    IntPtr graphics,   // GpGraphics* in/out
    IntPtr pen,   // GpPen* in/out
    float x1,   // FLOAT
    float y1,   // FLOAT
    float x2,   // FLOAT
    float y2   // FLOAT
);
<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipDrawLine(
    graphics As IntPtr,   ' GpGraphics* in/out
    pen As IntPtr,   ' GpPen* in/out
    x1 As Single,   ' FLOAT
    y1 As Single,   ' FLOAT
    x2 As Single,   ' FLOAT
    y2 As Single   ' FLOAT
) As Integer
End Function
' graphics : GpGraphics* in/out
' pen : GpPen* in/out
' x1 : FLOAT
' y1 : FLOAT
' x2 : FLOAT
' y2 : FLOAT
Declare PtrSafe Function GdipDrawLine Lib "gdiplus" ( _
    ByVal graphics As LongPtr, _
    ByVal pen As LongPtr, _
    ByVal x1 As Single, _
    ByVal y1 As Single, _
    ByVal x2 As Single, _
    ByVal y2 As Single) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GdipDrawLine = ctypes.windll.gdiplus.GdipDrawLine
GdipDrawLine.restype = ctypes.c_int
GdipDrawLine.argtypes = [
    ctypes.c_void_p,  # graphics : GpGraphics* in/out
    ctypes.c_void_p,  # pen : GpPen* in/out
    ctypes.c_float,  # x1 : FLOAT
    ctypes.c_float,  # y1 : FLOAT
    ctypes.c_float,  # x2 : FLOAT
    ctypes.c_float,  # y2 : FLOAT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('gdiplus.dll')
GdipDrawLine = Fiddle::Function.new(
  lib['GdipDrawLine'],
  [
    Fiddle::TYPE_VOIDP,  # graphics : GpGraphics* in/out
    Fiddle::TYPE_VOIDP,  # pen : GpPen* in/out
    Fiddle::TYPE_FLOAT,  # x1 : FLOAT
    Fiddle::TYPE_FLOAT,  # y1 : FLOAT
    Fiddle::TYPE_FLOAT,  # x2 : FLOAT
    Fiddle::TYPE_FLOAT,  # y2 : FLOAT
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdiplus")]
extern "system" {
    fn GdipDrawLine(
        graphics: *mut GpGraphics,  // GpGraphics* in/out
        pen: *mut GpPen,  // GpPen* in/out
        x1: f32,  // FLOAT
        y1: f32,  // FLOAT
        x2: f32,  // FLOAT
        y2: f32  // FLOAT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipDrawLine(IntPtr graphics, IntPtr pen, float x1, float y1, float x2, float y2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipDrawLine' -Namespace Win32 -PassThru
# $api::GdipDrawLine(graphics, pen, x1, y1, x2, y2)
#uselib "gdiplus.dll"
#func global GdipDrawLine "GdipDrawLine" sptr, sptr, float, float, float, float
; GdipDrawLine varptr(graphics), varptr(pen), x1, y1, x2, y2   ; 戻り値は stat
; graphics : GpGraphics* in/out -> "sptr"
; pen : GpPen* in/out -> "sptr"
; x1 : FLOAT -> "float"
; y1 : FLOAT -> "float"
; x2 : FLOAT -> "float"
; y2 : FLOAT -> "float"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "gdiplus.dll"
#cfunc global GdipDrawLine "GdipDrawLine" var, var, float, float, float, float
; res = GdipDrawLine(graphics, pen, x1, y1, x2, y2)
; graphics : GpGraphics* in/out -> "var"
; pen : GpPen* in/out -> "var"
; x1 : FLOAT -> "float"
; y1 : FLOAT -> "float"
; x2 : FLOAT -> "float"
; y2 : FLOAT -> "float"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; Status GdipDrawLine(GpGraphics* graphics, GpPen* pen, FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2)
#uselib "gdiplus.dll"
#cfunc global GdipDrawLine "GdipDrawLine" var, var, float, float, float, float
; res = GdipDrawLine(graphics, pen, x1, y1, x2, y2)
; graphics : GpGraphics* in/out -> "var"
; pen : GpPen* in/out -> "var"
; x1 : FLOAT -> "float"
; y1 : FLOAT -> "float"
; x2 : FLOAT -> "float"
; y2 : FLOAT -> "float"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"math"
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
	procGdipDrawLine = gdiplus.NewProc("GdipDrawLine")
)

// graphics (GpGraphics* in/out), pen (GpPen* in/out), x1 (FLOAT), y1 (FLOAT), x2 (FLOAT), y2 (FLOAT)
r1, _, err := procGdipDrawLine.Call(
	uintptr(graphics),
	uintptr(pen),
	uintptr(math.Float32bits(x1)),
	uintptr(math.Float32bits(y1)),
	uintptr(math.Float32bits(x2)),
	uintptr(math.Float32bits(y2)),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // Status
// 注意: float/double 引数は proc.Call では XMM レジスタに渡せません。
// windows.SyscallN(proc.Addr(), math.Float64bits(x), ...) もしくは cgo を使用してください。
function GdipDrawLine(
  graphics: Pointer;   // GpGraphics* in/out
  pen: Pointer;   // GpPen* in/out
  x1: Single;   // FLOAT
  y1: Single;   // FLOAT
  x2: Single;   // FLOAT
  y2: Single   // FLOAT
): Integer; stdcall;
  external 'gdiplus.dll' name 'GdipDrawLine';
result := DllCall("gdiplus\GdipDrawLine"
    , "Ptr", graphics   ; GpGraphics* in/out
    , "Ptr", pen   ; GpPen* in/out
    , "Float", x1   ; FLOAT
    , "Float", y1   ; FLOAT
    , "Float", x2   ; FLOAT
    , "Float", y2   ; FLOAT
    , "Int")   ; return: Status
●GdipDrawLine(graphics, pen, x1, y1, x2, y2) = DLL("gdiplus.dll", "int GdipDrawLine(void*, void*, float, float, float, float)")
# 呼び出し: GdipDrawLine(graphics, pen, x1, y1, x2, y2)
# graphics : GpGraphics* in/out -> "void*"
# pen : GpPen* in/out -> "void*"
# x1 : FLOAT -> "float"
# y1 : FLOAT -> "float"
# x2 : FLOAT -> "float"
# y2 : FLOAT -> "float"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。