ホーム › Graphics.Gdi › SetDCPenColor
SetDCPenColor
関数DCのストックペンに使う現在のペン色を設定する。
シグネチャ
// GDI32.dll
#include <windows.h>
COLORREF SetDCPenColor(
HDC hdc,
COLORREF color
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | DC のハンドル。 |
| color | COLORREF | in | 新しいペンの色。 |
戻り値の型: COLORREF
公式ドキュメント
SetDCPenColor 関数は、指定したカラー値に現在のデバイスコンテキスト (DC) のペンの色を設定します。デバイスが指定したカラー値を表現できない場合、最も近い物理的な色に設定されます。
戻り値
関数が成功した場合、戻り値は以前の DC のペンの色を COLORREF 値として返します。関数が失敗した場合、戻り値は CLR_INVALID です。
解説(Remarks)
この関数は、ストックペン DC_PEN が DC に選択されていない場合でも、以前の DC_PEN の色を返します。ただし、この色は DC にストック DC_PEN が選択されるまで描画操作で使用されません。
引数に DC_BRUSH または DC_PEN を指定した GetStockObject 関数は、SetDCPenColor 関数および SetDCBrushColor 関数と置き換えて使用できます。
ICM: ICM が有効な場合、カラーマネジメントが実行されます。
例
色を設定する例については、Setting the Pen or Brush Color を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // COLORREFfunction 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)。const std = @import("std");
extern "gdi32" fn SetDCPenColor(
hdc: ?*anyopaque, // HDC
color: u32 // COLORREF
) callconv(std.os.windows.WINAPI) u32;proc SetDCPenColor(
hdc: pointer, # HDC
color: uint32 # COLORREF
): uint32 {.importc: "SetDCPenColor", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
uint SetDCPenColor(
void* hdc, // HDC
uint color // COLORREF
);ccall((:SetDCPenColor, "GDI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32),
hdc, color)
# hdc : HDC -> Ptr{Cvoid}
# color : COLORREF -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t SetDCPenColor(
void* hdc,
uint32_t color);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetDCPenColor(hdc, color)
-- hdc : HDC
-- color : COLORREF
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetDCPenColor = lib.func('__stdcall', 'SetDCPenColor', 'uint32_t', ['void *', 'uint32_t']);
// SetDCPenColor(hdc, color)
// hdc : HDC -> 'void *'
// color : COLORREF -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
SetDCPenColor: { parameters: ["pointer", "u32"], result: "u32" },
});
// lib.symbols.SetDCPenColor(hdc, color)
// hdc : HDC -> "pointer"
// color : COLORREF -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SetDCPenColor(
void* hdc,
uint32_t color);
C, "GDI32.dll");
// $ffi->SetDCPenColor(hdc, color);
// hdc : HDC
// color : COLORREF
// 構造体/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 Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
int SetDCPenColor(
Pointer hdc, // HDC
int color // COLORREF
);
}@[Link("gdi32")]
lib LibGDI32
fun SetDCPenColor = SetDCPenColor(
hdc : Void*, # HDC
color : UInt32 # COLORREF
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetDCPenColorNative = Uint32 Function(Pointer<Void>, Uint32);
typedef SetDCPenColorDart = int Function(Pointer<Void>, int);
final SetDCPenColor = DynamicLibrary.open('GDI32.dll')
.lookupFunction<SetDCPenColorNative, SetDCPenColorDart>('SetDCPenColor');
// hdc : HDC -> Pointer<Void>
// color : COLORREF -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetDCPenColor(
hdc: THandle; // HDC
color: DWORD // COLORREF
): DWORD; stdcall;
external 'GDI32.dll' name 'SetDCPenColor';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetDCPenColor"
c_SetDCPenColor :: Ptr () -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- color : COLORREF -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setdcpencolor =
foreign "SetDCPenColor"
((ptr void) @-> uint32_t @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* color : COLORREF -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("SetDCPenColor" set-dcpen-color :convention :stdcall) :uint32
(hdc :pointer) ; HDC
(color :uint32)) ; COLORREF
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetDCPenColor = Win32::API::More->new('GDI32',
'DWORD SetDCPenColor(HANDLE hdc, DWORD color)');
# my $ret = $SetDCPenColor->Call($hdc, $color);
# hdc : HDC -> HANDLE
# color : COLORREF -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetDCPenColor — DCの現在のペン色を取得する。