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

GetUpdateRect

関数
ウィンドウの更新が必要な領域の外接矩形を取得する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL GetUpdateRect(
    HWND hWnd,
    RECT* lpRect,   // optional
    BOOL bErase
);

パラメーター

名前方向説明
hWndHWNDin更新領域を取得する対象のウィンドウへのハンドル。
lpRectRECT*outoptional

囲む矩形の座標をデバイス単位で受け取る RECT 構造体へのポインター。

アプリケーションは、このパラメーターに NULL を設定することで、ウィンドウに更新領域が存在するかどうかを判定できます。このパラメーターが NULL の場合、GetUpdateRect は更新領域が存在すれば 0 以外を返し、存在しなければ 0 を返します。これにより、WM_PAINT メッセージが無効領域に起因するものかどうかを簡単かつ効率的に判定できます。

bEraseBOOLin更新領域の背景を消去するかどうかを指定します。このパラメーターが TRUE で、かつ更新領域が空でない場合、GetUpdateRect は背景を消去するために指定したウィンドウへ WM_ERASEBKGND メッセージを送信します。

戻り値の型: BOOL

公式ドキュメント

GetUpdateRect 関数は、指定したウィンドウの更新領域を完全に囲む最小の矩形の座標を取得します。

戻り値

更新領域が空でない場合、戻り値は 0 以外です。

更新領域が存在しない場合、戻り値は 0 です。

解説(Remarks)

BeginPaint 関数によって取得される更新矩形は、GetUpdateRect によって取得されるものと同一です。

BeginPaint は更新領域を自動的に検証するため、BeginPaint の呼び出し直後に GetUpdateRect を呼び出すと、空の更新領域が取得されます。

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

各言語での呼び出し定義

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

BOOL GetUpdateRect(
    HWND hWnd,
    RECT* lpRect,   // optional
    BOOL bErase
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", ExactSpelling = true)]
static extern bool GetUpdateRect(
    IntPtr hWnd,   // HWND
    IntPtr lpRect,   // RECT* optional, out
    bool bErase   // BOOL
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetUpdateRect(
    hWnd As IntPtr,   ' HWND
    lpRect As IntPtr,   ' RECT* optional, out
    bErase As Boolean   ' BOOL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hWnd : HWND
' lpRect : RECT* optional, out
' bErase : BOOL
Declare PtrSafe Function GetUpdateRect Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal lpRect As LongPtr, _
    ByVal bErase As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetUpdateRect = ctypes.windll.user32.GetUpdateRect
GetUpdateRect.restype = wintypes.BOOL
GetUpdateRect.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_void_p,  # lpRect : RECT* optional, out
    wintypes.BOOL,  # bErase : BOOL
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetUpdateRect = user32.NewProc("GetUpdateRect")
)

// hWnd (HWND), lpRect (RECT* optional, out), bErase (BOOL)
r1, _, err := procGetUpdateRect.Call(
	uintptr(hWnd),
	uintptr(lpRect),
	uintptr(bErase),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetUpdateRect(
  hWnd: THandle;   // HWND
  lpRect: Pointer;   // RECT* optional, out
  bErase: BOOL   // BOOL
): BOOL; stdcall;
  external 'USER32.dll' name 'GetUpdateRect';
result := DllCall("USER32\GetUpdateRect"
    , "Ptr", hWnd   ; HWND
    , "Ptr", lpRect   ; RECT* optional, out
    , "Int", bErase   ; BOOL
    , "Int")   ; return: BOOL
●GetUpdateRect(hWnd, lpRect, bErase) = DLL("USER32.dll", "bool GetUpdateRect(void*, void*, bool)")
# 呼び出し: GetUpdateRect(hWnd, lpRect, bErase)
# hWnd : HWND -> "void*"
# lpRect : RECT* optional, out -> "void*"
# bErase : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

foreign import stdcall safe "GetUpdateRect"
  c_GetUpdateRect :: Ptr () -> Ptr () -> CInt -> IO CInt
-- hWnd : HWND -> Ptr ()
-- lpRect : RECT* optional, out -> Ptr ()
-- bErase : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getupdaterect =
  foreign "GetUpdateRect"
    ((ptr void) @-> (ptr void) @-> int32_t @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* lpRect : RECT* optional, out -> (ptr void) *)
(* bErase : 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 ("GetUpdateRect" get-update-rect :convention :stdcall) :int32
  (h-wnd :pointer)   ; HWND
  (lp-rect :pointer)   ; RECT* optional, out
  (b-erase :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetUpdateRect = Win32::API::More->new('USER32',
    'BOOL GetUpdateRect(HANDLE hWnd, LPVOID lpRect, BOOL bErase)');
# my $ret = $GetUpdateRect->Call($hWnd, $lpRect, $bErase);
# hWnd : HWND -> HANDLE
# lpRect : RECT* optional, out -> LPVOID
# bErase : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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