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

CreatePen

関数
指定したスタイル・幅・色のペンを作成する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HPEN CreatePen(
    PEN_STYLE iStyle,
    INT cWidth,
    COLORREF color
);

パラメーター

名前方向
iStylePEN_STYLEin
cWidthINTin
colorCOLORREFin

戻り値の型: HPEN

各言語での呼び出し定義

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

HPEN CreatePen(
    PEN_STYLE iStyle,
    INT cWidth,
    COLORREF color
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr CreatePen(
    int iStyle,   // PEN_STYLE
    int cWidth,   // INT
    uint color   // COLORREF
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function CreatePen(
    iStyle As Integer,   ' PEN_STYLE
    cWidth As Integer,   ' INT
    color As UInteger   ' COLORREF
) As IntPtr
End Function
' iStyle : PEN_STYLE
' cWidth : INT
' color : COLORREF
Declare PtrSafe Function CreatePen Lib "gdi32" ( _
    ByVal iStyle As Long, _
    ByVal cWidth As Long, _
    ByVal color As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreatePen = ctypes.windll.gdi32.CreatePen
CreatePen.restype = ctypes.c_void_p
CreatePen.argtypes = [
    ctypes.c_int,  # iStyle : PEN_STYLE
    ctypes.c_int,  # cWidth : INT
    wintypes.DWORD,  # color : COLORREF
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreatePen = Fiddle::Function.new(
  lib['CreatePen'],
  [
    Fiddle::TYPE_INT,  # iStyle : PEN_STYLE
    Fiddle::TYPE_INT,  # cWidth : INT
    -Fiddle::TYPE_INT,  # color : COLORREF
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn CreatePen(
        iStyle: i32,  // PEN_STYLE
        cWidth: i32,  // INT
        color: u32  // COLORREF
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr CreatePen(int iStyle, int cWidth, uint color);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreatePen' -Namespace Win32 -PassThru
# $api::CreatePen(iStyle, cWidth, color)
#uselib "GDI32.dll"
#func global CreatePen "CreatePen" sptr, sptr, sptr
; CreatePen iStyle, cWidth, color   ; 戻り値は stat
; iStyle : PEN_STYLE -> "sptr"
; cWidth : INT -> "sptr"
; color : COLORREF -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global CreatePen "CreatePen" int, int, int
; res = CreatePen(iStyle, cWidth, color)
; iStyle : PEN_STYLE -> "int"
; cWidth : INT -> "int"
; color : COLORREF -> "int"
; HPEN CreatePen(PEN_STYLE iStyle, INT cWidth, COLORREF color)
#uselib "GDI32.dll"
#cfunc global CreatePen "CreatePen" int, int, int
; res = CreatePen(iStyle, cWidth, color)
; iStyle : PEN_STYLE -> "int"
; cWidth : INT -> "int"
; color : COLORREF -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreatePen = gdi32.NewProc("CreatePen")
)

// iStyle (PEN_STYLE), cWidth (INT), color (COLORREF)
r1, _, err := procCreatePen.Call(
	uintptr(iStyle),
	uintptr(cWidth),
	uintptr(color),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HPEN
function CreatePen(
  iStyle: Integer;   // PEN_STYLE
  cWidth: Integer;   // INT
  color: DWORD   // COLORREF
): THandle; stdcall;
  external 'GDI32.dll' name 'CreatePen';
result := DllCall("GDI32\CreatePen"
    , "Int", iStyle   ; PEN_STYLE
    , "Int", cWidth   ; INT
    , "UInt", color   ; COLORREF
    , "Ptr")   ; return: HPEN
●CreatePen(iStyle, cWidth, color) = DLL("GDI32.dll", "void* CreatePen(int, int, dword)")
# 呼び出し: CreatePen(iStyle, cWidth, color)
# iStyle : PEN_STYLE -> "int"
# cWidth : INT -> "int"
# color : COLORREF -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。