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

GetBoundsRect

関数
DCの累積描画境界矩形を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetBoundsRect(
    HDC hdc,
    RECT* lprect,
    DWORD flags
);

パラメーター

名前方向説明
hdcHDCin関数が境界矩形を返す対象となるデバイスコンテキストへのハンドル。
lprectRECT*out現在の境界矩形を受け取る RECT 構造体へのポインター。アプリケーションの矩形は論理座標で返され、境界矩形はスクリーン座標で返されます。
flagsDWORDin

GetBoundsRect 関数の動作を指定します。このパラメーターには次の値を指定できます。

意味
DCB_RESET
境界矩形を返した後にクリアします。このフラグが設定されていない場合、境界矩形はクリアされません。

戻り値の型: DWORD

公式ドキュメント

GetBoundsRect 関数は、指定したデバイスコンテキストについて、現在累積されている境界矩形を取得します。

戻り値

戻り値は、累積された境界矩形の状態を示し、次のいずれかの値になります。

意味
0 エラーが発生しました。指定したデバイスコンテキストハンドルが無効です。
DCB_DISABLE 境界の累積がオフです。
DCB_ENABLE 境界の累積がオンです。
DCB_RESET 境界矩形が空です。
DCB_SET 境界矩形が空ではありません。

解説(Remarks)

DCB_SET 値は、ビット値 DCB_ACCUMULATEDCB_RESET を組み合わせたものです。境界矩形が空かどうかを判定するために DCB_RESET ビットを調べるアプリケーションは、DCB_ACCUMULATE ビットも調べる必要があります。境界矩形が空であるのは、DCB_RESET ビットが 1 かつ DCB_ACCUMULATE ビットが 0 の場合のみです。

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

各言語での呼び出し定義

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

DWORD GetBoundsRect(
    HDC hdc,
    RECT* lprect,
    DWORD flags
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint GetBoundsRect(
    IntPtr hdc,   // HDC
    IntPtr lprect,   // RECT* out
    uint flags   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetBoundsRect(
    hdc As IntPtr,   ' HDC
    lprect As IntPtr,   ' RECT* out
    flags As UInteger   ' DWORD
) As UInteger
End Function
' hdc : HDC
' lprect : RECT* out
' flags : DWORD
Declare PtrSafe Function GetBoundsRect Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lprect As LongPtr, _
    ByVal flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetBoundsRect = ctypes.windll.gdi32.GetBoundsRect
GetBoundsRect.restype = wintypes.DWORD
GetBoundsRect.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_void_p,  # lprect : RECT* out
    wintypes.DWORD,  # flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetBoundsRect = Fiddle::Function.new(
  lib['GetBoundsRect'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lprect : RECT* out
    -Fiddle::TYPE_INT,  # flags : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetBoundsRect(
        hdc: *mut core::ffi::c_void,  // HDC
        lprect: *mut RECT,  // RECT* out
        flags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern uint GetBoundsRect(IntPtr hdc, IntPtr lprect, uint flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetBoundsRect' -Namespace Win32 -PassThru
# $api::GetBoundsRect(hdc, lprect, flags)
#uselib "GDI32.dll"
#func global GetBoundsRect "GetBoundsRect" sptr, sptr, sptr
; GetBoundsRect hdc, varptr(lprect), flags   ; 戻り値は stat
; hdc : HDC -> "sptr"
; lprect : RECT* out -> "sptr"
; flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetBoundsRect "GetBoundsRect" sptr, var, int
; res = GetBoundsRect(hdc, lprect, flags)
; hdc : HDC -> "sptr"
; lprect : RECT* out -> "var"
; flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetBoundsRect(HDC hdc, RECT* lprect, DWORD flags)
#uselib "GDI32.dll"
#cfunc global GetBoundsRect "GetBoundsRect" intptr, var, int
; res = GetBoundsRect(hdc, lprect, flags)
; hdc : HDC -> "intptr"
; lprect : RECT* out -> "var"
; flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetBoundsRect = gdi32.NewProc("GetBoundsRect")
)

// hdc (HDC), lprect (RECT* out), flags (DWORD)
r1, _, err := procGetBoundsRect.Call(
	uintptr(hdc),
	uintptr(lprect),
	uintptr(flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetBoundsRect(
  hdc: THandle;   // HDC
  lprect: Pointer;   // RECT* out
  flags: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetBoundsRect';
result := DllCall("GDI32\GetBoundsRect"
    , "Ptr", hdc   ; HDC
    , "Ptr", lprect   ; RECT* out
    , "UInt", flags   ; DWORD
    , "UInt")   ; return: DWORD
●GetBoundsRect(hdc, lprect, flags) = DLL("GDI32.dll", "dword GetBoundsRect(void*, void*, dword)")
# 呼び出し: GetBoundsRect(hdc, lprect, flags)
# hdc : HDC -> "void*"
# lprect : RECT* out -> "void*"
# flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef GetBoundsRectNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef GetBoundsRectDart = int Function(Pointer<Void>, Pointer<Void>, int);
final GetBoundsRect = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<GetBoundsRectNative, GetBoundsRectDart>('GetBoundsRect');
// hdc : HDC -> Pointer<Void>
// lprect : RECT* out -> Pointer<Void>
// flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetBoundsRect(
  hdc: THandle;   // HDC
  lprect: Pointer;   // RECT* out
  flags: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetBoundsRect';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetBoundsRect"
  c_GetBoundsRect :: Ptr () -> Ptr () -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- lprect : RECT* out -> Ptr ()
-- flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getboundsrect =
  foreign "GetBoundsRect"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* lprect : RECT* out -> (ptr void) *)
(* flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("GetBoundsRect" get-bounds-rect :convention :stdcall) :uint32
  (hdc :pointer)   ; HDC
  (lprect :pointer)   ; RECT* out
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetBoundsRect = Win32::API::More->new('GDI32',
    'DWORD GetBoundsRect(HANDLE hdc, LPVOID lprect, DWORD flags)');
# my $ret = $GetBoundsRect->Call($hdc, $lprect, $flags);
# hdc : HDC -> HANDLE
# lprect : RECT* out -> LPVOID
# flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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