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

GetWindowRgn

関数
ウィンドウの表示領域リージョンを取得する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

GDI_REGION_TYPE GetWindowRgn(
    HWND hWnd,
    HRGN hRgn
);

パラメーター

名前方向
hWndHWNDin
hRgnHRGNin

戻り値の型: GDI_REGION_TYPE

各言語での呼び出し定義

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

GDI_REGION_TYPE GetWindowRgn(
    HWND hWnd,
    HRGN hRgn
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern int GetWindowRgn(
    IntPtr hWnd,   // HWND
    IntPtr hRgn   // HRGN
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetWindowRgn(
    hWnd As IntPtr,   ' HWND
    hRgn As IntPtr   ' HRGN
) As Integer
End Function
' hWnd : HWND
' hRgn : HRGN
Declare PtrSafe Function GetWindowRgn Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal hRgn As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetWindowRgn = ctypes.windll.user32.GetWindowRgn
GetWindowRgn.restype = ctypes.c_int
GetWindowRgn.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.HANDLE,  # hRgn : HRGN
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetWindowRgn = user32.NewProc("GetWindowRgn")
)

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