Win32 API 日本語リファレンス
ホームUI.ColorSystem › ColorMatchToTarget

ColorMatchToTarget

関数
ターゲットDCに合わせて色を整合させる。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL ColorMatchToTarget(
    HDC hdc,
    HDC hdcTarget,
    COLOR_MATCH_TO_TARGET_ACTION action
);

パラメーター

名前方向説明
hdcHDCin色補正を適用する出力先のデバイスコンテキストハンドル。
hdcTargetHDCinプレビュー対象となるターゲットデバイスのデバイスコンテキストハンドル。
actionCOLOR_MATCH_TO_TARGET_ACTIONin色マッチングの動作を指定する列挙値。有効化・無効化・プレビュー・復元などを指定する。

戻り値の型: BOOL

各言語での呼び出し定義

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

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

ColorMatchToTarget = ctypes.windll.gdi32.ColorMatchToTarget
ColorMatchToTarget.restype = wintypes.BOOL
ColorMatchToTarget.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.HANDLE,  # hdcTarget : HDC
    wintypes.DWORD,  # action : COLOR_MATCH_TO_TARGET_ACTION
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procColorMatchToTarget = gdi32.NewProc("ColorMatchToTarget")
)

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

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

typedef ColorMatchToTargetNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef ColorMatchToTargetDart = int Function(Pointer<Void>, Pointer<Void>, int);
final ColorMatchToTarget = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<ColorMatchToTargetNative, ColorMatchToTargetDart>('ColorMatchToTarget');
// hdc : HDC -> Pointer<Void>
// hdcTarget : HDC -> Pointer<Void>
// action : COLOR_MATCH_TO_TARGET_ACTION -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ColorMatchToTarget(
  hdc: THandle;   // HDC
  hdcTarget: THandle;   // HDC
  action: DWORD   // COLOR_MATCH_TO_TARGET_ACTION
): BOOL; stdcall;
  external 'GDI32.dll' name 'ColorMatchToTarget';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ColorMatchToTarget"
  c_ColorMatchToTarget :: Ptr () -> Ptr () -> Word32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- hdcTarget : HDC -> Ptr ()
-- action : COLOR_MATCH_TO_TARGET_ACTION -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let colormatchtotarget =
  foreign "ColorMatchToTarget"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* hdcTarget : HDC -> (ptr void) *)
(* action : COLOR_MATCH_TO_TARGET_ACTION -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("ColorMatchToTarget" color-match-to-target :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (hdc-target :pointer)   ; HDC
  (action :uint32))   ; COLOR_MATCH_TO_TARGET_ACTION
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ColorMatchToTarget = Win32::API::More->new('GDI32',
    'BOOL ColorMatchToTarget(HANDLE hdc, HANDLE hdcTarget, DWORD action)');
# my $ret = $ColorMatchToTarget->Call($hdc, $hdcTarget, $action);
# hdc : HDC -> HANDLE
# hdcTarget : HDC -> HANDLE
# action : COLOR_MATCH_TO_TARGET_ACTION -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型