ホーム › Graphics.Gdi › ValidateRect
ValidateRect
関数指定矩形を有効化して更新領域から除外する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL ValidateRect(
HWND hWnd, // optional
const RECT* lpRect // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | inoptional | 更新領域を変更するウィンドウへのハンドル。このパラメーターが NULL の場合、システムはすべてのウィンドウを無効化して再描画し、関数が戻る前にウィンドウプロシージャへ WM_ERASEBKGND および WM_NCPAINT メッセージを送信します。 |
| lpRect | RECT* | inoptional | 更新領域から取り除く矩形のクライアント座標を格納した RECT 構造体へのポインター。このパラメーターが NULL の場合、クライアント領域全体が取り除かれます。 |
戻り値の型: BOOL
公式ドキュメント
ValidateRect 関数は、指定した矩形を対象ウィンドウの更新領域から取り除くことで、その矩形内のクライアント領域を有効化します。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
BeginPaint 関数は、クライアント領域全体を自動的に有効化します。次の WM_PAINT メッセージが生成される前に更新領域の一部を有効化する必要がある場合は、ValidateRect 関数も ValidateRgn 関数も呼び出さないでください。
システムは、現在の更新領域が有効化されるまで WM_PAINT メッセージを生成し続けます。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
BOOL ValidateRect(
HWND hWnd, // optional
const RECT* lpRect // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", ExactSpelling = true)]
static extern bool ValidateRect(
IntPtr hWnd, // HWND optional
IntPtr lpRect // RECT* optional
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function ValidateRect(
hWnd As IntPtr, ' HWND optional
lpRect As IntPtr ' RECT* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hWnd : HWND optional
' lpRect : RECT* optional
Declare PtrSafe Function ValidateRect Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal lpRect As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ValidateRect = ctypes.windll.user32.ValidateRect
ValidateRect.restype = wintypes.BOOL
ValidateRect.argtypes = [
wintypes.HANDLE, # hWnd : HWND optional
ctypes.c_void_p, # lpRect : RECT* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
ValidateRect = Fiddle::Function.new(
lib['ValidateRect'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND optional
Fiddle::TYPE_VOIDP, # lpRect : RECT* optional
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn ValidateRect(
hWnd: *mut core::ffi::c_void, // HWND optional
lpRect: *const RECT // RECT* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll")]
public static extern bool ValidateRect(IntPtr hWnd, IntPtr lpRect);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ValidateRect' -Namespace Win32 -PassThru
# $api::ValidateRect(hWnd, lpRect)#uselib "USER32.dll"
#func global ValidateRect "ValidateRect" sptr, sptr
; ValidateRect hWnd, varptr(lpRect) ; 戻り値は stat
; hWnd : HWND optional -> "sptr"
; lpRect : RECT* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global ValidateRect "ValidateRect" sptr, var ; res = ValidateRect(hWnd, lpRect) ; hWnd : HWND optional -> "sptr" ; lpRect : RECT* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global ValidateRect "ValidateRect" sptr, sptr ; res = ValidateRect(hWnd, varptr(lpRect)) ; hWnd : HWND optional -> "sptr" ; lpRect : RECT* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ValidateRect(HWND hWnd, RECT* lpRect) #uselib "USER32.dll" #cfunc global ValidateRect "ValidateRect" intptr, var ; res = ValidateRect(hWnd, lpRect) ; hWnd : HWND optional -> "intptr" ; lpRect : RECT* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ValidateRect(HWND hWnd, RECT* lpRect) #uselib "USER32.dll" #cfunc global ValidateRect "ValidateRect" intptr, intptr ; res = ValidateRect(hWnd, varptr(lpRect)) ; hWnd : HWND optional -> "intptr" ; lpRect : RECT* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procValidateRect = user32.NewProc("ValidateRect")
)
// hWnd (HWND optional), lpRect (RECT* optional)
r1, _, err := procValidateRect.Call(
uintptr(hWnd),
uintptr(lpRect),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ValidateRect(
hWnd: THandle; // HWND optional
lpRect: Pointer // RECT* optional
): BOOL; stdcall;
external 'USER32.dll' name 'ValidateRect';result := DllCall("USER32\ValidateRect"
, "Ptr", hWnd ; HWND optional
, "Ptr", lpRect ; RECT* optional
, "Int") ; return: BOOL●ValidateRect(hWnd, lpRect) = DLL("USER32.dll", "bool ValidateRect(void*, void*)")
# 呼び出し: ValidateRect(hWnd, lpRect)
# hWnd : HWND optional -> "void*"
# lpRect : RECT* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn ValidateRect(
hWnd: ?*anyopaque, // HWND optional
lpRect: [*c]RECT // RECT* optional
) callconv(std.os.windows.WINAPI) i32;proc ValidateRect(
hWnd: pointer, # HWND optional
lpRect: ptr RECT # RECT* optional
): int32 {.importc: "ValidateRect", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int ValidateRect(
void* hWnd, // HWND optional
RECT* lpRect // RECT* optional
);ccall((:ValidateRect, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{RECT}),
hWnd, lpRect)
# hWnd : HWND optional -> Ptr{Cvoid}
# lpRect : RECT* optional -> Ptr{RECT}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ValidateRect(
void* hWnd,
void* lpRect);
]]
local user32 = ffi.load("user32")
-- user32.ValidateRect(hWnd, lpRect)
-- hWnd : HWND optional
-- lpRect : RECT* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const ValidateRect = lib.func('__stdcall', 'ValidateRect', 'int32_t', ['void *', 'void *']);
// ValidateRect(hWnd, lpRect)
// hWnd : HWND optional -> 'void *'
// lpRect : RECT* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
ValidateRect: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.ValidateRect(hWnd, lpRect)
// hWnd : HWND optional -> "pointer"
// lpRect : RECT* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ValidateRect(
void* hWnd,
void* lpRect);
C, "USER32.dll");
// $ffi->ValidateRect(hWnd, lpRect);
// hWnd : HWND optional
// lpRect : RECT* optional
// 構造体/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 ValidateRect(
Pointer hWnd, // HWND optional
Pointer lpRect // RECT* optional
);
}@[Link("user32")]
lib LibUSER32
fun ValidateRect = ValidateRect(
hWnd : Void*, # HWND optional
lpRect : RECT* # RECT* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ValidateRectNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef ValidateRectDart = int Function(Pointer<Void>, Pointer<Void>);
final ValidateRect = DynamicLibrary.open('USER32.dll')
.lookupFunction<ValidateRectNative, ValidateRectDart>('ValidateRect');
// hWnd : HWND optional -> Pointer<Void>
// lpRect : RECT* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ValidateRect(
hWnd: THandle; // HWND optional
lpRect: Pointer // RECT* optional
): BOOL; stdcall;
external 'USER32.dll' name 'ValidateRect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ValidateRect"
c_ValidateRect :: Ptr () -> Ptr () -> IO CInt
-- hWnd : HWND optional -> Ptr ()
-- lpRect : RECT* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let validaterect =
foreign "ValidateRect"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hWnd : HWND optional -> (ptr void) *)
(* lpRect : RECT* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("ValidateRect" validate-rect :convention :stdcall) :int32
(h-wnd :pointer) ; HWND optional
(lp-rect :pointer)) ; RECT* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ValidateRect = Win32::API::More->new('USER32',
'BOOL ValidateRect(HANDLE hWnd, LPVOID lpRect)');
# my $ret = $ValidateRect->Call($hWnd, $lpRect);
# hWnd : HWND optional -> HANDLE
# lpRect : RECT* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f BeginPaint — ウィンドウの描画を開始し描画用デバイスコンテキストを取得する。
- f InvalidateRect — 指定矩形を無効化して再描画対象に追加する。
- f InvalidateRgn — 指定リージョンを無効化して再描画対象に追加する。
- f ValidateRgn — 指定リージョンを有効化して更新領域から除外する。
使用する型