ホーム › Graphics.Gdi › CreateRectRgn
CreateRectRgn
関数指定座標の矩形領域を作成する。
シグネチャ
// GDI32.dll
#include <windows.h>
HRGN CreateRectRgn(
INT x1,
INT y1,
INT x2,
INT y2
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| x1 | INT | in | リージョンの左上隅の x 座標を論理単位で指定します。 |
| y1 | INT | in | リージョンの左上隅の y 座標を論理単位で指定します。 |
| x2 | INT | in | リージョンの右下隅の x 座標を論理単位で指定します。 |
| y2 | INT | in | リージョンの右下隅の y 座標を論理単位で指定します。 |
戻り値の型: HRGN
公式ドキュメント
CreateRectRgn 関数は、四角形のリージョンを作成します。
戻り値
関数が成功した場合、戻り値はリージョンのハンドルです。
関数が失敗した場合、戻り値は NULL です。
解説(Remarks)
HRGN オブジェクトが不要になったら、DeleteObject 関数を呼び出して削除してください。
リージョンの座標は、27 ビットの符号付き整数として表現されます。
Create<shape>Rgn メソッド(CreateRectRgn や CreatePolygonRgn など)で作成されたリージョンには、図形の内部のみが含まれ、図形の輪郭はリージョンから除外されます。これは、連続する 2 つの頂点を結ぶ線上の任意の点がリージョンに含まれないことを意味します。そのような点に対して PtInRegion を呼び出すと、結果として 0 が返されます。
例
例については、Drawing Markers を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
HRGN CreateRectRgn(
INT x1,
INT y1,
INT x2,
INT y2
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr CreateRectRgn(
int x1, // INT
int y1, // INT
int x2, // INT
int y2 // INT
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function CreateRectRgn(
x1 As Integer, ' INT
y1 As Integer, ' INT
x2 As Integer, ' INT
y2 As Integer ' INT
) As IntPtr
End Function' x1 : INT
' y1 : INT
' x2 : INT
' y2 : INT
Declare PtrSafe Function CreateRectRgn Lib "gdi32" ( _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateRectRgn = ctypes.windll.gdi32.CreateRectRgn
CreateRectRgn.restype = ctypes.c_void_p
CreateRectRgn.argtypes = [
ctypes.c_int, # x1 : INT
ctypes.c_int, # y1 : INT
ctypes.c_int, # x2 : INT
ctypes.c_int, # y2 : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
CreateRectRgn = Fiddle::Function.new(
lib['CreateRectRgn'],
[
Fiddle::TYPE_INT, # x1 : INT
Fiddle::TYPE_INT, # y1 : INT
Fiddle::TYPE_INT, # x2 : INT
Fiddle::TYPE_INT, # y2 : INT
],
Fiddle::TYPE_VOIDP)#[link(name = "gdi32")]
extern "system" {
fn CreateRectRgn(
x1: i32, // INT
y1: i32, // INT
x2: i32, // INT
y2: i32 // INT
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateRectRgn' -Namespace Win32 -PassThru
# $api::CreateRectRgn(x1, y1, x2, y2)#uselib "GDI32.dll"
#func global CreateRectRgn "CreateRectRgn" sptr, sptr, sptr, sptr
; CreateRectRgn x1, y1, x2, y2 ; 戻り値は stat
; x1 : INT -> "sptr"
; y1 : INT -> "sptr"
; x2 : INT -> "sptr"
; y2 : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global CreateRectRgn "CreateRectRgn" int, int, int, int
; res = CreateRectRgn(x1, y1, x2, y2)
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"; HRGN CreateRectRgn(INT x1, INT y1, INT x2, INT y2)
#uselib "GDI32.dll"
#cfunc global CreateRectRgn "CreateRectRgn" int, int, int, int
; res = CreateRectRgn(x1, y1, x2, y2)
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procCreateRectRgn = gdi32.NewProc("CreateRectRgn")
)
// x1 (INT), y1 (INT), x2 (INT), y2 (INT)
r1, _, err := procCreateRectRgn.Call(
uintptr(x1),
uintptr(y1),
uintptr(x2),
uintptr(y2),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRGNfunction CreateRectRgn(
x1: Integer; // INT
y1: Integer; // INT
x2: Integer; // INT
y2: Integer // INT
): THandle; stdcall;
external 'GDI32.dll' name 'CreateRectRgn';result := DllCall("GDI32\CreateRectRgn"
, "Int", x1 ; INT
, "Int", y1 ; INT
, "Int", x2 ; INT
, "Int", y2 ; INT
, "Ptr") ; return: HRGN●CreateRectRgn(x1, y1, x2, y2) = DLL("GDI32.dll", "void* CreateRectRgn(int, int, int, int)")
# 呼び出し: CreateRectRgn(x1, y1, x2, y2)
# x1 : INT -> "int"
# y1 : INT -> "int"
# x2 : INT -> "int"
# y2 : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn CreateRectRgn(
x1: i32, // INT
y1: i32, // INT
x2: i32, // INT
y2: i32 // INT
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc CreateRectRgn(
x1: int32, # INT
y1: int32, # INT
x2: int32, # INT
y2: int32 # INT
): pointer {.importc: "CreateRectRgn", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
void* CreateRectRgn(
int x1, // INT
int y1, // INT
int x2, // INT
int y2 // INT
);ccall((:CreateRectRgn, "GDI32.dll"), stdcall, Ptr{Cvoid},
(Int32, Int32, Int32, Int32),
x1, y1, x2, y2)
# x1 : INT -> Int32
# y1 : INT -> Int32
# x2 : INT -> Int32
# y2 : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* CreateRectRgn(
int32_t x1,
int32_t y1,
int32_t x2,
int32_t y2);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.CreateRectRgn(x1, y1, x2, y2)
-- x1 : INT
-- y1 : INT
-- x2 : INT
-- y2 : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const CreateRectRgn = lib.func('__stdcall', 'CreateRectRgn', 'void *', ['int32_t', 'int32_t', 'int32_t', 'int32_t']);
// CreateRectRgn(x1, y1, x2, y2)
// x1 : INT -> 'int32_t'
// y1 : INT -> 'int32_t'
// x2 : INT -> 'int32_t'
// y2 : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
CreateRectRgn: { parameters: ["i32", "i32", "i32", "i32"], result: "pointer" },
});
// lib.symbols.CreateRectRgn(x1, y1, x2, y2)
// x1 : INT -> "i32"
// y1 : INT -> "i32"
// x2 : INT -> "i32"
// y2 : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* CreateRectRgn(
int32_t x1,
int32_t y1,
int32_t x2,
int32_t y2);
C, "GDI32.dll");
// $ffi->CreateRectRgn(x1, y1, x2, y2);
// x1 : INT
// y1 : INT
// x2 : INT
// y2 : INT
// 構造体/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 CreateRectRgn(
int x1, // INT
int y1, // INT
int x2, // INT
int y2 // INT
);
}@[Link("gdi32")]
lib LibGDI32
fun CreateRectRgn = CreateRectRgn(
x1 : Int32, # INT
y1 : Int32, # INT
x2 : Int32, # INT
y2 : Int32 # INT
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CreateRectRgnNative = Pointer<Void> Function(Int32, Int32, Int32, Int32);
typedef CreateRectRgnDart = Pointer<Void> Function(int, int, int, int);
final CreateRectRgn = DynamicLibrary.open('GDI32.dll')
.lookupFunction<CreateRectRgnNative, CreateRectRgnDart>('CreateRectRgn');
// x1 : INT -> Int32
// y1 : INT -> Int32
// x2 : INT -> Int32
// y2 : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CreateRectRgn(
x1: Integer; // INT
y1: Integer; // INT
x2: Integer; // INT
y2: Integer // INT
): THandle; stdcall;
external 'GDI32.dll' name 'CreateRectRgn';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateRectRgn"
c_CreateRectRgn :: Int32 -> Int32 -> Int32 -> Int32 -> IO (Ptr ())
-- x1 : INT -> Int32
-- y1 : INT -> Int32
-- x2 : INT -> Int32
-- y2 : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createrectrgn =
foreign "CreateRectRgn"
(int32_t @-> int32_t @-> int32_t @-> int32_t @-> returning (ptr void))
(* x1 : INT -> int32_t *)
(* y1 : INT -> int32_t *)
(* x2 : INT -> int32_t *)
(* y2 : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("CreateRectRgn" create-rect-rgn :convention :stdcall) :pointer
(x1 :int32) ; INT
(y1 :int32) ; INT
(x2 :int32) ; INT
(y2 :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateRectRgn = Win32::API::More->new('GDI32',
'HANDLE CreateRectRgn(int x1, int y1, int x2, int y2)');
# my $ret = $CreateRectRgn->Call($x1, $y1, $x2, $y2);
# x1 : INT -> int
# y1 : INT -> int
# x2 : INT -> int
# y2 : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CreatePolyPolygonRgn — 複数の多角形からなる領域を作成する。
- f CreatePolygonRgn — 頂点配列から多角形リージョンを作成する。
- f CreateRectRgnIndirect — RECT構造体の指定に基づいて矩形領域を作成する。
- f CreateRoundRectRgn — 角丸の矩形領域を作成する。
- f DeleteObject — 指定したGDIオブジェクトを削除しリソースを解放する。
- f ExtCreateRegion — 領域データと変換から領域を作成する。
- f GetRegionData — 領域を構成する矩形群のデータを取得する。
- f SelectObject — デバイスコンテキストにGDIオブジェクトを選択し、同種の前のオブジェクトを返す。