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

SetROP2

関数
前景描画のラスタ演算モード(描画モード)を設定する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT SetROP2(
    HDC hdc,
    R2_MODE rop2
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。
rop2R2_MODEin

ミックスモード。このパラメーターには、次のいずれかの値を指定できます。

ミックスモード 意味
R2_BLACK
ピクセルは常に 0 になります。
R2_COPYPEN
ピクセルはペンの色になります。
R2_MASKNOTPEN
ピクセルは、画面とペンの反転色の両方に共通する色の組み合わせになります。
R2_MASKPEN
ピクセルは、ペンと画面の両方に共通する色の組み合わせになります。
R2_MASKPENNOT
ピクセルは、ペンと画面の反転色の両方に共通する色の組み合わせになります。
R2_MERGENOTPEN
ピクセルは、画面の色とペンの反転色の組み合わせになります。
R2_MERGEPEN
ピクセルは、ペンの色と画面の色の組み合わせになります。
R2_MERGEPENNOT
ピクセルは、ペンの色と画面の反転色の組み合わせになります。
R2_NOP
ピクセルは変更されません。
R2_NOT
ピクセルは画面の色の反転になります。
R2_NOTCOPYPEN
ピクセルはペンの色の反転になります。
R2_NOTMASKPEN
ピクセルは R2_MASKPEN の色の反転になります。
R2_NOTMERGEPEN
ピクセルは R2_MERGEPEN の色の反転になります。
R2_NOTXORPEN
ピクセルは R2_XORPEN の色の反転になります。
R2_WHITE
ピクセルは常に 1 になります。
R2_XORPEN
ピクセルは、ペンと画面の色の組み合わせになりますが、両方に共通する色は除かれます。

戻り値の型: INT

公式ドキュメント

SetROP2 関数は、現在の前景ミックスモードを設定します。

戻り値

関数が成功した場合、戻り値は以前のミックスモードを示します。

関数が失敗した場合、戻り値は 0 です。

解説(Remarks)

ミックスモードは、現在のペンで描画する際に GDI がソースの色と転送先の色をどのように組み合わせるかを定義します。ミックスモードはバイナリラスターオペレーションコードであり、AND、OR、XOR(排他的論理和)の各バイナリ演算と NOT の単項演算を使用して、2 変数の可能なすべてのブール関数を表します。ミックスモードはラスターデバイス専用であり、ベクターデバイスでは使用できません。

例については、四角形の使用を参照してください。

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

各言語での呼び出し定義

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

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

SetROP2 = ctypes.windll.gdi32.SetROP2
SetROP2.restype = ctypes.c_int
SetROP2.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # rop2 : R2_MODE
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetROP2 = gdi32.NewProc("SetROP2")
)

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

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

typedef SetROP2Native = Int32 Function(Pointer<Void>, Int32);
typedef SetROP2Dart = int Function(Pointer<Void>, int);
final SetROP2 = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<SetROP2Native, SetROP2Dart>('SetROP2');
// hdc : HDC -> Pointer<Void>
// rop2 : R2_MODE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetROP2(
  hdc: THandle;   // HDC
  rop2: Integer   // R2_MODE
): Integer; stdcall;
  external 'GDI32.dll' name 'SetROP2';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetROP2"
  c_SetROP2 :: Ptr () -> Int32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- rop2 : R2_MODE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

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

関連項目

公式の関連項目
使用する型