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

CombineRgn

関数
2つのリージョンを指定したモードで結合する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

GDI_REGION_TYPE CombineRgn(
    HRGN hrgnDst,   // optional
    HRGN hrgnSrc1,   // optional
    HRGN hrgnSrc2,   // optional
    RGN_COMBINE_MODE iMode
);

パラメーター

名前方向説明
hrgnDstHRGNinoptional他の 2 つのリージョンを結合することで定義される寸法を持つ、新しいリージョンへのハンドル。(このリージョンは、CombineRgn を呼び出す前に存在している必要があります。)
hrgnSrc1HRGNinoptional結合される 2 つのリージョンのうち、1 つ目のリージョンへのハンドル。
hrgnSrc2HRGNinoptional結合される 2 つのリージョンのうち、2 つ目のリージョンへのハンドル。
iModeRGN_COMBINE_MODEin

2 つのリージョンをどのように結合するかを示すモード。このパラメーターには、次のいずれかの値を指定できます。

意味
RGN_AND
結合される 2 つのリージョンの積(共通部分)を作成します。
RGN_COPY
hrgnSrc1 で識別されるリージョンのコピーを作成します。
RGN_DIFF
hrgnSrc1 のうち、hrgnSrc2 に含まれない部分を結合します。
RGN_OR
結合される 2 つのリージョンの和(合併)を作成します。
RGN_XOR
結合される 2 つのリージョンの和を作成しますが、重なり合う領域は除外します。

戻り値の型: GDI_REGION_TYPE

公式ドキュメント

CombineRgn 関数は、2 つのリージョンを結合し、その結果を 3 つ目のリージョンに格納します。2 つのリージョンは、指定されたモードに従って結合されます。

戻り値

戻り値は、結果として得られるリージョンの種類を示します。次のいずれかの値になります。

戻り値 説明
NULLREGION
リージョンが空です。
SIMPLEREGION
リージョンが単一の四角形です。
COMPLEXREGION
リージョンが単一の四角形ではありません。
ERROR
リージョンが作成されませんでした。

解説(Remarks)

3 つのリージョンは、それぞれ異なっている必要はありません。たとえば、hrgnSrc1 パラメーターを hrgnDest パラメーターと同一にすることができます。

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

各言語での呼び出し定義

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

GDI_REGION_TYPE CombineRgn(
    HRGN hrgnDst,   // optional
    HRGN hrgnSrc1,   // optional
    HRGN hrgnSrc2,   // optional
    RGN_COMBINE_MODE iMode
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int CombineRgn(
    IntPtr hrgnDst,   // HRGN optional
    IntPtr hrgnSrc1,   // HRGN optional
    IntPtr hrgnSrc2,   // HRGN optional
    int iMode   // RGN_COMBINE_MODE
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function CombineRgn(
    hrgnDst As IntPtr,   ' HRGN optional
    hrgnSrc1 As IntPtr,   ' HRGN optional
    hrgnSrc2 As IntPtr,   ' HRGN optional
    iMode As Integer   ' RGN_COMBINE_MODE
) As Integer
End Function
' hrgnDst : HRGN optional
' hrgnSrc1 : HRGN optional
' hrgnSrc2 : HRGN optional
' iMode : RGN_COMBINE_MODE
Declare PtrSafe Function CombineRgn Lib "gdi32" ( _
    ByVal hrgnDst As LongPtr, _
    ByVal hrgnSrc1 As LongPtr, _
    ByVal hrgnSrc2 As LongPtr, _
    ByVal iMode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CombineRgn = ctypes.windll.gdi32.CombineRgn
CombineRgn.restype = ctypes.c_int
CombineRgn.argtypes = [
    wintypes.HANDLE,  # hrgnDst : HRGN optional
    wintypes.HANDLE,  # hrgnSrc1 : HRGN optional
    wintypes.HANDLE,  # hrgnSrc2 : HRGN optional
    ctypes.c_int,  # iMode : RGN_COMBINE_MODE
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCombineRgn = gdi32.NewProc("CombineRgn")
)

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

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

typedef CombineRgnNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32);
typedef CombineRgnDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int);
final CombineRgn = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<CombineRgnNative, CombineRgnDart>('CombineRgn');
// hrgnDst : HRGN optional -> Pointer<Void>
// hrgnSrc1 : HRGN optional -> Pointer<Void>
// hrgnSrc2 : HRGN optional -> Pointer<Void>
// iMode : RGN_COMBINE_MODE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CombineRgn(
  hrgnDst: THandle;   // HRGN optional
  hrgnSrc1: THandle;   // HRGN optional
  hrgnSrc2: THandle;   // HRGN optional
  iMode: Integer   // RGN_COMBINE_MODE
): Integer; stdcall;
  external 'GDI32.dll' name 'CombineRgn';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CombineRgn"
  c_CombineRgn :: Ptr () -> Ptr () -> Ptr () -> Int32 -> IO Int32
-- hrgnDst : HRGN optional -> Ptr ()
-- hrgnSrc1 : HRGN optional -> Ptr ()
-- hrgnSrc2 : HRGN optional -> Ptr ()
-- iMode : RGN_COMBINE_MODE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let combinergn =
  foreign "CombineRgn"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> returning int32_t)
(* hrgnDst : HRGN optional -> (ptr void) *)
(* hrgnSrc1 : HRGN optional -> (ptr void) *)
(* hrgnSrc2 : HRGN optional -> (ptr void) *)
(* iMode : RGN_COMBINE_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 ("CombineRgn" combine-rgn :convention :stdcall) :int32
  (hrgn-dst :pointer)   ; HRGN optional
  (hrgn-src1 :pointer)   ; HRGN optional
  (hrgn-src2 :pointer)   ; HRGN optional
  (i-mode :int32))   ; RGN_COMBINE_MODE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CombineRgn = Win32::API::More->new('GDI32',
    'int CombineRgn(HANDLE hrgnDst, HANDLE hrgnSrc1, HANDLE hrgnSrc2, int iMode)');
# my $ret = $CombineRgn->Call($hrgnDst, $hrgnSrc1, $hrgnSrc2, $iMode);
# hrgnDst : HRGN optional -> HANDLE
# hrgnSrc1 : HRGN optional -> HANDLE
# hrgnSrc2 : HRGN optional -> HANDLE
# iMode : RGN_COMBINE_MODE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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