ホーム › Graphics.Gdi › SetWindowRgn
SetWindowRgn
関数ウィンドウの表示領域を指定リージョンに設定する。
シグネチャ
// USER32.dll
#include <windows.h>
INT SetWindowRgn(
HWND hWnd,
HRGN hRgn, // optional
BOOL bRedraw
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | ウィンドウ領域を設定する対象のウィンドウへのハンドル。 |
| hRgn | HRGN | inoptional | 領域へのハンドル。この関数は、ウィンドウのウィンドウ領域をこの領域に設定します。 hRgn が NULL の場合、この関数はウィンドウ領域を NULL に設定します。 |
| bRedraw | BOOL | in | ウィンドウ領域を設定した後、システムがウィンドウを再描画するかどうかを指定します。bRedraw が TRUE の場合、システムは再描画します。それ以外の場合は再描画しません。 通常、ウィンドウが表示されている場合は bRedraw を TRUE に設定します。 |
戻り値の型: INT
公式ドキュメント
SetWindowRgn 関数は、ウィンドウのウィンドウ領域 (window region) を設定します。
戻り値
関数が成功すると、戻り値は 0 以外になります。
関数が失敗すると、戻り値は 0 になります。
解説(Remarks)
この関数が呼び出されると、システムはウィンドウに WM_WINDOWPOSCHANGING メッセージと WM_WINDOWPOSCHANGED メッセージを送信します。
ウィンドウのウィンドウ領域の座標は、ウィンドウのクライアント領域ではなく、ウィンドウの左上隅を基準とした相対座標です。
注意 ウィンドウのレイアウトが右から左 (RTL) の場合、座標はウィンドウの右上隅を基準とした相対座標になります。Window Layout and Mirroring を参照してください。
ウィンドウのウィンドウ領域を取得するには、GetWindowRgn 関数を呼び出します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
INT SetWindowRgn(
HWND hWnd,
HRGN hRgn, // optional
BOOL bRedraw
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern int SetWindowRgn(
IntPtr hWnd, // HWND
IntPtr hRgn, // HRGN optional
bool bRedraw // BOOL
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function SetWindowRgn(
hWnd As IntPtr, ' HWND
hRgn As IntPtr, ' HRGN optional
bRedraw As Boolean ' BOOL
) As Integer
End Function' hWnd : HWND
' hRgn : HRGN optional
' bRedraw : BOOL
Declare PtrSafe Function SetWindowRgn Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal hRgn As LongPtr, _
ByVal bRedraw As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetWindowRgn = ctypes.windll.user32.SetWindowRgn
SetWindowRgn.restype = ctypes.c_int
SetWindowRgn.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.HANDLE, # hRgn : HRGN optional
wintypes.BOOL, # bRedraw : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SetWindowRgn = Fiddle::Function.new(
lib['SetWindowRgn'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # hRgn : HRGN optional
Fiddle::TYPE_INT, # bRedraw : BOOL
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn SetWindowRgn(
hWnd: *mut core::ffi::c_void, // HWND
hRgn: *mut core::ffi::c_void, // HRGN optional
bRedraw: i32 // BOOL
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetWindowRgn' -Namespace Win32 -PassThru
# $api::SetWindowRgn(hWnd, hRgn, bRedraw)#uselib "USER32.dll"
#func global SetWindowRgn "SetWindowRgn" sptr, sptr, sptr
; SetWindowRgn hWnd, hRgn, bRedraw ; 戻り値は stat
; hWnd : HWND -> "sptr"
; hRgn : HRGN optional -> "sptr"
; bRedraw : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SetWindowRgn "SetWindowRgn" sptr, sptr, int
; res = SetWindowRgn(hWnd, hRgn, bRedraw)
; hWnd : HWND -> "sptr"
; hRgn : HRGN optional -> "sptr"
; bRedraw : BOOL -> "int"; INT SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
#uselib "USER32.dll"
#cfunc global SetWindowRgn "SetWindowRgn" intptr, intptr, int
; res = SetWindowRgn(hWnd, hRgn, bRedraw)
; hWnd : HWND -> "intptr"
; hRgn : HRGN optional -> "intptr"
; bRedraw : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procSetWindowRgn = user32.NewProc("SetWindowRgn")
)
// hWnd (HWND), hRgn (HRGN optional), bRedraw (BOOL)
r1, _, err := procSetWindowRgn.Call(
uintptr(hWnd),
uintptr(hRgn),
uintptr(bRedraw),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SetWindowRgn(
hWnd: THandle; // HWND
hRgn: THandle; // HRGN optional
bRedraw: BOOL // BOOL
): Integer; stdcall;
external 'USER32.dll' name 'SetWindowRgn';result := DllCall("USER32\SetWindowRgn"
, "Ptr", hWnd ; HWND
, "Ptr", hRgn ; HRGN optional
, "Int", bRedraw ; BOOL
, "Int") ; return: INT●SetWindowRgn(hWnd, hRgn, bRedraw) = DLL("USER32.dll", "int SetWindowRgn(void*, void*, bool)")
# 呼び出し: SetWindowRgn(hWnd, hRgn, bRedraw)
# hWnd : HWND -> "void*"
# hRgn : HRGN optional -> "void*"
# bRedraw : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn SetWindowRgn(
hWnd: ?*anyopaque, // HWND
hRgn: ?*anyopaque, // HRGN optional
bRedraw: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc SetWindowRgn(
hWnd: pointer, # HWND
hRgn: pointer, # HRGN optional
bRedraw: int32 # BOOL
): int32 {.importc: "SetWindowRgn", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int SetWindowRgn(
void* hWnd, // HWND
void* hRgn, // HRGN optional
int bRedraw // BOOL
);ccall((:SetWindowRgn, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Int32),
hWnd, hRgn, bRedraw)
# hWnd : HWND -> Ptr{Cvoid}
# hRgn : HRGN optional -> Ptr{Cvoid}
# bRedraw : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetWindowRgn(
void* hWnd,
void* hRgn,
int32_t bRedraw);
]]
local user32 = ffi.load("user32")
-- user32.SetWindowRgn(hWnd, hRgn, bRedraw)
-- hWnd : HWND
-- hRgn : HRGN optional
-- bRedraw : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const SetWindowRgn = lib.func('__stdcall', 'SetWindowRgn', 'int32_t', ['void *', 'void *', 'int32_t']);
// SetWindowRgn(hWnd, hRgn, bRedraw)
// hWnd : HWND -> 'void *'
// hRgn : HRGN optional -> 'void *'
// bRedraw : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SetWindowRgn: { parameters: ["pointer", "pointer", "i32"], result: "i32" },
});
// lib.symbols.SetWindowRgn(hWnd, hRgn, bRedraw)
// hWnd : HWND -> "pointer"
// hRgn : HRGN optional -> "pointer"
// bRedraw : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetWindowRgn(
void* hWnd,
void* hRgn,
int32_t bRedraw);
C, "USER32.dll");
// $ffi->SetWindowRgn(hWnd, hRgn, bRedraw);
// hWnd : HWND
// hRgn : HRGN optional
// bRedraw : BOOL
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
int SetWindowRgn(
Pointer hWnd, // HWND
Pointer hRgn, // HRGN optional
boolean bRedraw // BOOL
);
}@[Link("user32")]
lib LibUSER32
fun SetWindowRgn = SetWindowRgn(
hWnd : Void*, # HWND
hRgn : Void*, # HRGN optional
bRedraw : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetWindowRgnNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32);
typedef SetWindowRgnDart = int Function(Pointer<Void>, Pointer<Void>, int);
final SetWindowRgn = DynamicLibrary.open('USER32.dll')
.lookupFunction<SetWindowRgnNative, SetWindowRgnDart>('SetWindowRgn');
// hWnd : HWND -> Pointer<Void>
// hRgn : HRGN optional -> Pointer<Void>
// bRedraw : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetWindowRgn(
hWnd: THandle; // HWND
hRgn: THandle; // HRGN optional
bRedraw: BOOL // BOOL
): Integer; stdcall;
external 'USER32.dll' name 'SetWindowRgn';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetWindowRgn"
c_SetWindowRgn :: Ptr () -> Ptr () -> CInt -> IO Int32
-- hWnd : HWND -> Ptr ()
-- hRgn : HRGN optional -> Ptr ()
-- bRedraw : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setwindowrgn =
foreign "SetWindowRgn"
((ptr void) @-> (ptr void) @-> int32_t @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* hRgn : HRGN optional -> (ptr void) *)
(* bRedraw : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("SetWindowRgn" set-window-rgn :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(h-rgn :pointer) ; HRGN optional
(b-redraw :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetWindowRgn = Win32::API::More->new('USER32',
'int SetWindowRgn(HANDLE hWnd, HANDLE hRgn, BOOL bRedraw)');
# my $ret = $SetWindowRgn->Call($hWnd, $hRgn, $bRedraw);
# hWnd : HWND -> HANDLE
# hRgn : HRGN optional -> HANDLE
# bRedraw : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetWindowRgn — ウィンドウの表示領域リージョンを取得する。