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

SetDCPenColor

関数
DCのストックペンに使う現在のペン色を設定する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

COLORREF SetDCPenColor(
    HDC hdc,
    COLORREF color
);

パラメーター

名前方向
hdcHDCin
colorCOLORREFin

戻り値の型: COLORREF

各言語での呼び出し定義

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

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

SetDCPenColor = ctypes.windll.gdi32.SetDCPenColor
SetDCPenColor.restype = wintypes.DWORD
SetDCPenColor.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # color : COLORREF
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetDCPenColor = gdi32.NewProc("SetDCPenColor")
)

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