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

CreateRoundRectRgn

関数
角丸の矩形領域を作成する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRGN CreateRoundRectRgn(
    INT x1,
    INT y1,
    INT x2,
    INT y2,
    INT w,
    INT h
);

パラメーター

名前方向説明
x1INTinリージョンの左上隅の x 座標をデバイス単位で指定します。
y1INTinリージョンの左上隅の y 座標をデバイス単位で指定します。
x2INTinリージョンの右下隅の x 座標をデバイス単位で指定します。
y2INTinリージョンの右下隅の y 座標をデバイス単位で指定します。
wINTin丸い角を作成するために使用する楕円の幅をデバイス単位で指定します。
hINTin丸い角を作成するために使用する楕円の高さをデバイス単位で指定します。

戻り値の型: HRGN

公式ドキュメント

CreateRoundRectRgn 関数は、角が丸い四角形のリージョンを作成します。

戻り値

関数が成功した場合、戻り値はリージョンのハンドルです。

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

解説(Remarks)

HRGN オブジェクトが不要になったら、DeleteObject 関数を呼び出して削除してください。

リージョンの座標は 27 ビットの符号付き整数として表されます。

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

各言語での呼び出し定義

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

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

CreateRoundRectRgn = ctypes.windll.gdi32.CreateRoundRectRgn
CreateRoundRectRgn.restype = ctypes.c_void_p
CreateRoundRectRgn.argtypes = [
    ctypes.c_int,  # x1 : INT
    ctypes.c_int,  # y1 : INT
    ctypes.c_int,  # x2 : INT
    ctypes.c_int,  # y2 : INT
    ctypes.c_int,  # w : INT
    ctypes.c_int,  # h : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateRoundRectRgn = Fiddle::Function.new(
  lib['CreateRoundRectRgn'],
  [
    Fiddle::TYPE_INT,  # x1 : INT
    Fiddle::TYPE_INT,  # y1 : INT
    Fiddle::TYPE_INT,  # x2 : INT
    Fiddle::TYPE_INT,  # y2 : INT
    Fiddle::TYPE_INT,  # w : INT
    Fiddle::TYPE_INT,  # h : INT
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn CreateRoundRectRgn(
        x1: i32,  // INT
        y1: i32,  // INT
        x2: i32,  // INT
        y2: i32,  // INT
        w: i32,  // INT
        h: 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 CreateRoundRectRgn(int x1, int y1, int x2, int y2, int w, int h);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateRoundRectRgn' -Namespace Win32 -PassThru
# $api::CreateRoundRectRgn(x1, y1, x2, y2, w, h)
#uselib "GDI32.dll"
#func global CreateRoundRectRgn "CreateRoundRectRgn" sptr, sptr, sptr, sptr, sptr, sptr
; CreateRoundRectRgn x1, y1, x2, y2, w, h   ; 戻り値は stat
; x1 : INT -> "sptr"
; y1 : INT -> "sptr"
; x2 : INT -> "sptr"
; y2 : INT -> "sptr"
; w : INT -> "sptr"
; h : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global CreateRoundRectRgn "CreateRoundRectRgn" int, int, int, int, int, int
; res = CreateRoundRectRgn(x1, y1, x2, y2, w, h)
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"
; w : INT -> "int"
; h : INT -> "int"
; HRGN CreateRoundRectRgn(INT x1, INT y1, INT x2, INT y2, INT w, INT h)
#uselib "GDI32.dll"
#cfunc global CreateRoundRectRgn "CreateRoundRectRgn" int, int, int, int, int, int
; res = CreateRoundRectRgn(x1, y1, x2, y2, w, h)
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"
; w : INT -> "int"
; h : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateRoundRectRgn = gdi32.NewProc("CreateRoundRectRgn")
)

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

extern "gdi32" fn CreateRoundRectRgn(
    x1: i32, // INT
    y1: i32, // INT
    x2: i32, // INT
    y2: i32, // INT
    w: i32, // INT
    h: i32 // INT
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc CreateRoundRectRgn(
    x1: int32,  # INT
    y1: int32,  # INT
    x2: int32,  # INT
    y2: int32,  # INT
    w: int32,  # INT
    h: int32  # INT
): pointer {.importc: "CreateRoundRectRgn", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
void* CreateRoundRectRgn(
    int x1,   // INT
    int y1,   // INT
    int x2,   // INT
    int y2,   // INT
    int w,   // INT
    int h   // INT
);
ccall((:CreateRoundRectRgn, "GDI32.dll"), stdcall, Ptr{Cvoid},
      (Int32, Int32, Int32, Int32, Int32, Int32),
      x1, y1, x2, y2, w, h)
# x1 : INT -> Int32
# y1 : INT -> Int32
# x2 : INT -> Int32
# y2 : INT -> Int32
# w : INT -> Int32
# h : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* CreateRoundRectRgn(
    int32_t x1,
    int32_t y1,
    int32_t x2,
    int32_t y2,
    int32_t w,
    int32_t h);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.CreateRoundRectRgn(x1, y1, x2, y2, w, h)
-- x1 : INT
-- y1 : INT
-- x2 : INT
-- y2 : INT
-- w : INT
-- h : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const CreateRoundRectRgn = lib.func('__stdcall', 'CreateRoundRectRgn', 'void *', ['int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t']);
// CreateRoundRectRgn(x1, y1, x2, y2, w, h)
// x1 : INT -> 'int32_t'
// y1 : INT -> 'int32_t'
// x2 : INT -> 'int32_t'
// y2 : INT -> 'int32_t'
// w : INT -> 'int32_t'
// h : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  CreateRoundRectRgn: { parameters: ["i32", "i32", "i32", "i32", "i32", "i32"], result: "pointer" },
});
// lib.symbols.CreateRoundRectRgn(x1, y1, x2, y2, w, h)
// x1 : INT -> "i32"
// y1 : INT -> "i32"
// x2 : INT -> "i32"
// y2 : INT -> "i32"
// w : INT -> "i32"
// h : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* CreateRoundRectRgn(
    int32_t x1,
    int32_t y1,
    int32_t x2,
    int32_t y2,
    int32_t w,
    int32_t h);
C, "GDI32.dll");
// $ffi->CreateRoundRectRgn(x1, y1, x2, y2, w, h);
// x1 : INT
// y1 : INT
// x2 : INT
// y2 : INT
// w : INT
// h : 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 CreateRoundRectRgn(
        int x1,   // INT
        int y1,   // INT
        int x2,   // INT
        int y2,   // INT
        int w,   // INT
        int h   // INT
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun CreateRoundRectRgn = CreateRoundRectRgn(
    x1 : Int32,   # INT
    y1 : Int32,   # INT
    x2 : Int32,   # INT
    y2 : Int32,   # INT
    w : Int32,   # INT
    h : 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 CreateRoundRectRgnNative = Pointer<Void> Function(Int32, Int32, Int32, Int32, Int32, Int32);
typedef CreateRoundRectRgnDart = Pointer<Void> Function(int, int, int, int, int, int);
final CreateRoundRectRgn = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<CreateRoundRectRgnNative, CreateRoundRectRgnDart>('CreateRoundRectRgn');
// x1 : INT -> Int32
// y1 : INT -> Int32
// x2 : INT -> Int32
// y2 : INT -> Int32
// w : INT -> Int32
// h : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateRoundRectRgn(
  x1: Integer;   // INT
  y1: Integer;   // INT
  x2: Integer;   // INT
  y2: Integer;   // INT
  w: Integer;   // INT
  h: Integer   // INT
): THandle; stdcall;
  external 'GDI32.dll' name 'CreateRoundRectRgn';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateRoundRectRgn"
  c_CreateRoundRectRgn :: Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO (Ptr ())
-- x1 : INT -> Int32
-- y1 : INT -> Int32
-- x2 : INT -> Int32
-- y2 : INT -> Int32
-- w : INT -> Int32
-- h : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createroundrectrgn =
  foreign "CreateRoundRectRgn"
    (int32_t @-> int32_t @-> 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 *)
(* w : INT -> int32_t *)
(* h : 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 ("CreateRoundRectRgn" create-round-rect-rgn :convention :stdcall) :pointer
  (x1 :int32)   ; INT
  (y1 :int32)   ; INT
  (x2 :int32)   ; INT
  (y2 :int32)   ; INT
  (w :int32)   ; INT
  (h :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateRoundRectRgn = Win32::API::More->new('GDI32',
    'HANDLE CreateRoundRectRgn(int x1, int y1, int x2, int y2, int w, int h)');
# my $ret = $CreateRoundRectRgn->Call($x1, $y1, $x2, $y2, $w, $h);
# x1 : INT -> int
# y1 : INT -> int
# x2 : INT -> int
# y2 : INT -> int
# w : INT -> int
# h : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目