Win32 API 日本語リファレンス
ホームDevices.Display › EngCreatePalette

EngCreatePalette

関数
GDIパレットを作成する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HPALETTE EngCreatePalette(
    DWORD iMode,
    DWORD cColors,
    DWORD* pulColors,
    DWORD flRed,
    DWORD flGreen,
    DWORD flBlue
);

パラメーター

名前方向説明
iModeDWORDin

パレットの定義方法を指定します。このパラメーターには次のいずれかの値を指定できます。

意味
PAL_BITFIELDS パレットは flRedflGreenflBlue パラメーターによって定義されます。
PAL_BGR デバイスは RGB カラーを直接受け取り、B(青)が最下位バイトになります。
PAL_CMYK デバイスは CMYK カラーを直接受け取り、C(シアン)が最下位バイトになります。
PAL_INDEXED RGB カラーの配列が cColorspulColors によって指定されます。
PAL_RGB デバイスは RGB カラーを直接受け取り、R(赤)が最下位バイトになります。
cColorsDWORDiniMode パラメーターが PAL_INDEXED の場合、cColorspulColors が指す配列に格納されているカラーの数を指定します。それ以外の場合、このパラメーターは 0 にする必要があります。
pulColorsDWORD*inoutiModePAL_INDEXED の場合、ULONG 値の配列の先頭へのポインターです。各 ULONG の下位 3 バイトがパレット内の RGB カラーを定義します。
flRedDWORDiniMode パラメーターが PAL_BITFIELDS の場合、flRedflGreenflBlue パラメーターは、どのビットが赤、緑、青に対応するかを示すマスクです。各マスクは連続したビットで構成され、他のマスクと重なってはなりません。ビットフィールドのすべての組み合わせが GDI でサポートされます。
flGreenDWORDiniMode パラメーターが PAL_BITFIELDS の場合、flRedflGreenflBlue パラメーターは、どのビットが赤、緑、青に対応するかを示すマスクです。各マスクは連続したビットで構成され、他のマスクと重なってはなりません。ビットフィールドのすべての組み合わせが GDI でサポートされます。
flBlueDWORDiniMode パラメーターが PAL_BITFIELDS の場合、flRedflGreenflBlue パラメーターは、どのビットが赤、緑、青に対応するかを示すマスクです。各マスクは連続したビットで構成され、他のマスクと重なってはなりません。ビットフィールドのすべての組み合わせが GDI でサポートされます。

戻り値の型: HPALETTE

公式ドキュメント

EngCreatePalette 関数は、RGB パレットを作成するための要求を GDI に送信します。

戻り値

関数が成功した場合、戻り値は新しいパレットへのハンドルです。それ以外の場合は 0 となり、エラーコードがログに記録されます。

解説(Remarks)

ドライバーは、DEVINFO 構造体にパレットへのポインターを返すことで、新しいパレットをデバイスに関連付けることができます。

デバイスに関連付けられた PAL_INDEXED パレットは、最初のインデックスエントリを黒(赤 = 0、緑 = 0、青 = 0)に、最後のエントリを白(255、255、255)に設定する必要があります。その他のすべてのエントリは、インデックスが互いに 1 の補数になっているエントリ同士の色のコントラストが大きくなるように設定する必要があります。たとえば、16 エントリのパレットのエントリ 0x9 が純緑(0,255,0)に設定されている場合、エントリ 0x6(=~0x9)は、暗い紫(128,0,128)のように緑とよくコントラストする色に設定する必要があります。このようにエントリを設定すると、XOR ラスター操作が適切に動作します。パレットが不要になったら、EngDeletePalette を使用して削除してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HPALETTE EngCreatePalette(
    DWORD iMode,
    DWORD cColors,
    DWORD* pulColors,
    DWORD flRed,
    DWORD flGreen,
    DWORD flBlue
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr EngCreatePalette(
    uint iMode,   // DWORD
    uint cColors,   // DWORD
    ref uint pulColors,   // DWORD* in/out
    uint flRed,   // DWORD
    uint flGreen,   // DWORD
    uint flBlue   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function EngCreatePalette(
    iMode As UInteger,   ' DWORD
    cColors As UInteger,   ' DWORD
    ByRef pulColors As UInteger,   ' DWORD* in/out
    flRed As UInteger,   ' DWORD
    flGreen As UInteger,   ' DWORD
    flBlue As UInteger   ' DWORD
) As IntPtr
End Function
' iMode : DWORD
' cColors : DWORD
' pulColors : DWORD* in/out
' flRed : DWORD
' flGreen : DWORD
' flBlue : DWORD
Declare PtrSafe Function EngCreatePalette Lib "gdi32" ( _
    ByVal iMode As Long, _
    ByVal cColors As Long, _
    ByRef pulColors As Long, _
    ByVal flRed As Long, _
    ByVal flGreen As Long, _
    ByVal flBlue As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EngCreatePalette = ctypes.windll.gdi32.EngCreatePalette
EngCreatePalette.restype = ctypes.c_void_p
EngCreatePalette.argtypes = [
    wintypes.DWORD,  # iMode : DWORD
    wintypes.DWORD,  # cColors : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pulColors : DWORD* in/out
    wintypes.DWORD,  # flRed : DWORD
    wintypes.DWORD,  # flGreen : DWORD
    wintypes.DWORD,  # flBlue : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
EngCreatePalette = Fiddle::Function.new(
  lib['EngCreatePalette'],
  [
    -Fiddle::TYPE_INT,  # iMode : DWORD
    -Fiddle::TYPE_INT,  # cColors : DWORD
    Fiddle::TYPE_VOIDP,  # pulColors : DWORD* in/out
    -Fiddle::TYPE_INT,  # flRed : DWORD
    -Fiddle::TYPE_INT,  # flGreen : DWORD
    -Fiddle::TYPE_INT,  # flBlue : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn EngCreatePalette(
        iMode: u32,  // DWORD
        cColors: u32,  // DWORD
        pulColors: *mut u32,  // DWORD* in/out
        flRed: u32,  // DWORD
        flGreen: u32,  // DWORD
        flBlue: u32  // DWORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr EngCreatePalette(uint iMode, uint cColors, ref uint pulColors, uint flRed, uint flGreen, uint flBlue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_EngCreatePalette' -Namespace Win32 -PassThru
# $api::EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
#uselib "GDI32.dll"
#func global EngCreatePalette "EngCreatePalette" sptr, sptr, sptr, sptr, sptr, sptr
; EngCreatePalette iMode, cColors, varptr(pulColors), flRed, flGreen, flBlue   ; 戻り値は stat
; iMode : DWORD -> "sptr"
; cColors : DWORD -> "sptr"
; pulColors : DWORD* in/out -> "sptr"
; flRed : DWORD -> "sptr"
; flGreen : DWORD -> "sptr"
; flBlue : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global EngCreatePalette "EngCreatePalette" int, int, var, int, int, int
; res = EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
; iMode : DWORD -> "int"
; cColors : DWORD -> "int"
; pulColors : DWORD* in/out -> "var"
; flRed : DWORD -> "int"
; flGreen : DWORD -> "int"
; flBlue : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HPALETTE EngCreatePalette(DWORD iMode, DWORD cColors, DWORD* pulColors, DWORD flRed, DWORD flGreen, DWORD flBlue)
#uselib "GDI32.dll"
#cfunc global EngCreatePalette "EngCreatePalette" int, int, var, int, int, int
; res = EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
; iMode : DWORD -> "int"
; cColors : DWORD -> "int"
; pulColors : DWORD* in/out -> "var"
; flRed : DWORD -> "int"
; flGreen : DWORD -> "int"
; flBlue : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procEngCreatePalette = gdi32.NewProc("EngCreatePalette")
)

// iMode (DWORD), cColors (DWORD), pulColors (DWORD* in/out), flRed (DWORD), flGreen (DWORD), flBlue (DWORD)
r1, _, err := procEngCreatePalette.Call(
	uintptr(iMode),
	uintptr(cColors),
	uintptr(pulColors),
	uintptr(flRed),
	uintptr(flGreen),
	uintptr(flBlue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HPALETTE
function EngCreatePalette(
  iMode: DWORD;   // DWORD
  cColors: DWORD;   // DWORD
  pulColors: Pointer;   // DWORD* in/out
  flRed: DWORD;   // DWORD
  flGreen: DWORD;   // DWORD
  flBlue: DWORD   // DWORD
): THandle; stdcall;
  external 'GDI32.dll' name 'EngCreatePalette';
result := DllCall("GDI32\EngCreatePalette"
    , "UInt", iMode   ; DWORD
    , "UInt", cColors   ; DWORD
    , "Ptr", pulColors   ; DWORD* in/out
    , "UInt", flRed   ; DWORD
    , "UInt", flGreen   ; DWORD
    , "UInt", flBlue   ; DWORD
    , "Ptr")   ; return: HPALETTE
●EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue) = DLL("GDI32.dll", "void* EngCreatePalette(dword, dword, void*, dword, dword, dword)")
# 呼び出し: EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
# iMode : DWORD -> "dword"
# cColors : DWORD -> "dword"
# pulColors : DWORD* in/out -> "void*"
# flRed : DWORD -> "dword"
# flGreen : DWORD -> "dword"
# flBlue : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn EngCreatePalette(
    iMode: u32, // DWORD
    cColors: u32, // DWORD
    pulColors: [*c]u32, // DWORD* in/out
    flRed: u32, // DWORD
    flGreen: u32, // DWORD
    flBlue: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc EngCreatePalette(
    iMode: uint32,  # DWORD
    cColors: uint32,  # DWORD
    pulColors: ptr uint32,  # DWORD* in/out
    flRed: uint32,  # DWORD
    flGreen: uint32,  # DWORD
    flBlue: uint32  # DWORD
): pointer {.importc: "EngCreatePalette", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
void* EngCreatePalette(
    uint iMode,   // DWORD
    uint cColors,   // DWORD
    uint* pulColors,   // DWORD* in/out
    uint flRed,   // DWORD
    uint flGreen,   // DWORD
    uint flBlue   // DWORD
);
ccall((:EngCreatePalette, "GDI32.dll"), stdcall, Ptr{Cvoid},
      (UInt32, UInt32, Ptr{UInt32}, UInt32, UInt32, UInt32),
      iMode, cColors, pulColors, flRed, flGreen, flBlue)
# iMode : DWORD -> UInt32
# cColors : DWORD -> UInt32
# pulColors : DWORD* in/out -> Ptr{UInt32}
# flRed : DWORD -> UInt32
# flGreen : DWORD -> UInt32
# flBlue : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* EngCreatePalette(
    uint32_t iMode,
    uint32_t cColors,
    uint32_t* pulColors,
    uint32_t flRed,
    uint32_t flGreen,
    uint32_t flBlue);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
-- iMode : DWORD
-- cColors : DWORD
-- pulColors : DWORD* in/out
-- flRed : DWORD
-- flGreen : DWORD
-- flBlue : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const EngCreatePalette = lib.func('__stdcall', 'EngCreatePalette', 'void *', ['uint32_t', 'uint32_t', 'uint32_t *', 'uint32_t', 'uint32_t', 'uint32_t']);
// EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
// iMode : DWORD -> 'uint32_t'
// cColors : DWORD -> 'uint32_t'
// pulColors : DWORD* in/out -> 'uint32_t *'
// flRed : DWORD -> 'uint32_t'
// flGreen : DWORD -> 'uint32_t'
// flBlue : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  EngCreatePalette: { parameters: ["u32", "u32", "pointer", "u32", "u32", "u32"], result: "pointer" },
});
// lib.symbols.EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue)
// iMode : DWORD -> "u32"
// cColors : DWORD -> "u32"
// pulColors : DWORD* in/out -> "pointer"
// flRed : DWORD -> "u32"
// flGreen : DWORD -> "u32"
// flBlue : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* EngCreatePalette(
    uint32_t iMode,
    uint32_t cColors,
    uint32_t* pulColors,
    uint32_t flRed,
    uint32_t flGreen,
    uint32_t flBlue);
C, "GDI32.dll");
// $ffi->EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue);
// iMode : DWORD
// cColors : DWORD
// pulColors : DWORD* in/out
// flRed : DWORD
// flGreen : DWORD
// flBlue : DWORD
// 構造体/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);
    Pointer EngCreatePalette(
        int iMode,   // DWORD
        int cColors,   // DWORD
        IntByReference pulColors,   // DWORD* in/out
        int flRed,   // DWORD
        int flGreen,   // DWORD
        int flBlue   // DWORD
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun EngCreatePalette = EngCreatePalette(
    iMode : UInt32,   # DWORD
    cColors : UInt32,   # DWORD
    pulColors : UInt32*,   # DWORD* in/out
    flRed : UInt32,   # DWORD
    flGreen : UInt32,   # DWORD
    flBlue : UInt32   # DWORD
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef EngCreatePaletteNative = Pointer<Void> Function(Uint32, Uint32, Pointer<Uint32>, Uint32, Uint32, Uint32);
typedef EngCreatePaletteDart = Pointer<Void> Function(int, int, Pointer<Uint32>, int, int, int);
final EngCreatePalette = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<EngCreatePaletteNative, EngCreatePaletteDart>('EngCreatePalette');
// iMode : DWORD -> Uint32
// cColors : DWORD -> Uint32
// pulColors : DWORD* in/out -> Pointer<Uint32>
// flRed : DWORD -> Uint32
// flGreen : DWORD -> Uint32
// flBlue : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function EngCreatePalette(
  iMode: DWORD;   // DWORD
  cColors: DWORD;   // DWORD
  pulColors: Pointer;   // DWORD* in/out
  flRed: DWORD;   // DWORD
  flGreen: DWORD;   // DWORD
  flBlue: DWORD   // DWORD
): THandle; stdcall;
  external 'GDI32.dll' name 'EngCreatePalette';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "EngCreatePalette"
  c_EngCreatePalette :: Word32 -> Word32 -> Ptr Word32 -> Word32 -> Word32 -> Word32 -> IO (Ptr ())
-- iMode : DWORD -> Word32
-- cColors : DWORD -> Word32
-- pulColors : DWORD* in/out -> Ptr Word32
-- flRed : DWORD -> Word32
-- flGreen : DWORD -> Word32
-- flBlue : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let engcreatepalette =
  foreign "EngCreatePalette"
    (uint32_t @-> uint32_t @-> (ptr uint32_t) @-> uint32_t @-> uint32_t @-> uint32_t @-> returning (ptr void))
(* iMode : DWORD -> uint32_t *)
(* cColors : DWORD -> uint32_t *)
(* pulColors : DWORD* in/out -> (ptr uint32_t) *)
(* flRed : DWORD -> uint32_t *)
(* flGreen : DWORD -> uint32_t *)
(* flBlue : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("EngCreatePalette" eng-create-palette :convention :stdcall) :pointer
  (i-mode :uint32)   ; DWORD
  (c-colors :uint32)   ; DWORD
  (pul-colors :pointer)   ; DWORD* in/out
  (fl-red :uint32)   ; DWORD
  (fl-green :uint32)   ; DWORD
  (fl-blue :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $EngCreatePalette = Win32::API::More->new('GDI32',
    'HANDLE EngCreatePalette(DWORD iMode, DWORD cColors, LPVOID pulColors, DWORD flRed, DWORD flGreen, DWORD flBlue)');
# my $ret = $EngCreatePalette->Call($iMode, $cColors, $pulColors, $flRed, $flGreen, $flBlue);
# iMode : DWORD -> DWORD
# cColors : DWORD -> DWORD
# pulColors : DWORD* in/out -> LPVOID
# flRed : DWORD -> DWORD
# flGreen : DWORD -> DWORD
# flBlue : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目