ホーム › Graphics.Gdi › FillRect
FillRect
関数指定矩形を指定ブラシで塗りつぶす。
シグネチャ
// USER32.dll
#include <windows.h>
INT FillRect(
HDC hDC,
const RECT* lprc,
HBRUSH hbr
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hDC | HDC | in | デバイスコンテキストへのハンドル。 |
| lprc | RECT* | in | 塗りつぶす矩形の論理座標を格納した RECT 構造体へのポインター。 |
| hbr | HBRUSH | in | 矩形の塗りつぶしに使用するブラシへのハンドル。 |
戻り値の型: INT
公式ドキュメント
FillRect 関数は、指定したブラシを使用して矩形を塗りつぶします。この関数は矩形の左辺と上辺を含みますが、右辺と下辺は含みません。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
hbr パラメーターで指定するブラシは、論理ブラシへのハンドルまたは色値のいずれかです。論理ブラシへのハンドルを指定する場合は、次のいずれかの関数を呼び出してハンドルを取得します: CreateHatchBrush、CreatePatternBrush、または CreateSolidBrush。また、GetStockObject 関数を使用して、ストックブラシのハンドルを取得することもできます。hbr パラメーターに色値を指定する場合、それは標準のシステムカラーのいずれかでなければなりません(選択した色に値 1 を加算する必要があります)。例:
FillRect(hdc, &rect, (HBRUSH) (COLOR_WINDOW+1));
標準のシステムカラーの一覧については、GetSysColor を参照してください。
指定した矩形を塗りつぶす際、FillRect は矩形の右辺と下辺を含みません。GDI は、現在のマッピングモードに関係なく、右端の列と下端の行を含まない手前まで矩形を塗りつぶします。
例
例については、Using Rectangles を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 FillRect(
HDC hDC,
const RECT* lprc,
HBRUSH hbr
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern int FillRect(
IntPtr hDC, // HDC
IntPtr lprc, // RECT*
IntPtr hbr // HBRUSH
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function FillRect(
hDC As IntPtr, ' HDC
lprc As IntPtr, ' RECT*
hbr As IntPtr ' HBRUSH
) As Integer
End Function' hDC : HDC
' lprc : RECT*
' hbr : HBRUSH
Declare PtrSafe Function FillRect Lib "user32" ( _
ByVal hDC As LongPtr, _
ByVal lprc As LongPtr, _
ByVal hbr As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FillRect = ctypes.windll.user32.FillRect
FillRect.restype = ctypes.c_int
FillRect.argtypes = [
wintypes.HANDLE, # hDC : HDC
ctypes.c_void_p, # lprc : RECT*
wintypes.HANDLE, # hbr : HBRUSH
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
FillRect = Fiddle::Function.new(
lib['FillRect'],
[
Fiddle::TYPE_VOIDP, # hDC : HDC
Fiddle::TYPE_VOIDP, # lprc : RECT*
Fiddle::TYPE_VOIDP, # hbr : HBRUSH
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn FillRect(
hDC: *mut core::ffi::c_void, // HDC
lprc: *const RECT, // RECT*
hbr: *mut core::ffi::c_void // HBRUSH
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern int FillRect(IntPtr hDC, IntPtr lprc, IntPtr hbr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_FillRect' -Namespace Win32 -PassThru
# $api::FillRect(hDC, lprc, hbr)#uselib "USER32.dll"
#func global FillRect "FillRect" sptr, sptr, sptr
; FillRect hDC, varptr(lprc), hbr ; 戻り値は stat
; hDC : HDC -> "sptr"
; lprc : RECT* -> "sptr"
; hbr : HBRUSH -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global FillRect "FillRect" sptr, var, sptr ; res = FillRect(hDC, lprc, hbr) ; hDC : HDC -> "sptr" ; lprc : RECT* -> "var" ; hbr : HBRUSH -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global FillRect "FillRect" sptr, sptr, sptr ; res = FillRect(hDC, varptr(lprc), hbr) ; hDC : HDC -> "sptr" ; lprc : RECT* -> "sptr" ; hbr : HBRUSH -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT FillRect(HDC hDC, RECT* lprc, HBRUSH hbr) #uselib "USER32.dll" #cfunc global FillRect "FillRect" intptr, var, intptr ; res = FillRect(hDC, lprc, hbr) ; hDC : HDC -> "intptr" ; lprc : RECT* -> "var" ; hbr : HBRUSH -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT FillRect(HDC hDC, RECT* lprc, HBRUSH hbr) #uselib "USER32.dll" #cfunc global FillRect "FillRect" intptr, intptr, intptr ; res = FillRect(hDC, varptr(lprc), hbr) ; hDC : HDC -> "intptr" ; lprc : RECT* -> "intptr" ; hbr : HBRUSH -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procFillRect = user32.NewProc("FillRect")
)
// hDC (HDC), lprc (RECT*), hbr (HBRUSH)
r1, _, err := procFillRect.Call(
uintptr(hDC),
uintptr(lprc),
uintptr(hbr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction FillRect(
hDC: THandle; // HDC
lprc: Pointer; // RECT*
hbr: THandle // HBRUSH
): Integer; stdcall;
external 'USER32.dll' name 'FillRect';result := DllCall("USER32\FillRect"
, "Ptr", hDC ; HDC
, "Ptr", lprc ; RECT*
, "Ptr", hbr ; HBRUSH
, "Int") ; return: INT●FillRect(hDC, lprc, hbr) = DLL("USER32.dll", "int FillRect(void*, void*, void*)")
# 呼び出し: FillRect(hDC, lprc, hbr)
# hDC : HDC -> "void*"
# lprc : RECT* -> "void*"
# hbr : HBRUSH -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn FillRect(
hDC: ?*anyopaque, // HDC
lprc: [*c]RECT, // RECT*
hbr: ?*anyopaque // HBRUSH
) callconv(std.os.windows.WINAPI) i32;proc FillRect(
hDC: pointer, # HDC
lprc: ptr RECT, # RECT*
hbr: pointer # HBRUSH
): int32 {.importc: "FillRect", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int FillRect(
void* hDC, // HDC
RECT* lprc, // RECT*
void* hbr // HBRUSH
);ccall((:FillRect, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{RECT}, Ptr{Cvoid}),
hDC, lprc, hbr)
# hDC : HDC -> Ptr{Cvoid}
# lprc : RECT* -> Ptr{RECT}
# hbr : HBRUSH -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t FillRect(
void* hDC,
void* lprc,
void* hbr);
]]
local user32 = ffi.load("user32")
-- user32.FillRect(hDC, lprc, hbr)
-- hDC : HDC
-- lprc : RECT*
-- hbr : HBRUSH
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const FillRect = lib.func('__stdcall', 'FillRect', 'int32_t', ['void *', 'void *', 'void *']);
// FillRect(hDC, lprc, hbr)
// hDC : HDC -> 'void *'
// lprc : RECT* -> 'void *'
// hbr : HBRUSH -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
FillRect: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.FillRect(hDC, lprc, hbr)
// hDC : HDC -> "pointer"
// lprc : RECT* -> "pointer"
// hbr : HBRUSH -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t FillRect(
void* hDC,
void* lprc,
void* hbr);
C, "USER32.dll");
// $ffi->FillRect(hDC, lprc, hbr);
// hDC : HDC
// lprc : RECT*
// hbr : HBRUSH
// 構造体/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 FillRect(
Pointer hDC, // HDC
Pointer lprc, // RECT*
Pointer hbr // HBRUSH
);
}@[Link("user32")]
lib LibUSER32
fun FillRect = FillRect(
hDC : Void*, # HDC
lprc : RECT*, # RECT*
hbr : Void* # HBRUSH
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef FillRectNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef FillRectDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final FillRect = DynamicLibrary.open('USER32.dll')
.lookupFunction<FillRectNative, FillRectDart>('FillRect');
// hDC : HDC -> Pointer<Void>
// lprc : RECT* -> Pointer<Void>
// hbr : HBRUSH -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function FillRect(
hDC: THandle; // HDC
lprc: Pointer; // RECT*
hbr: THandle // HBRUSH
): Integer; stdcall;
external 'USER32.dll' name 'FillRect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FillRect"
c_FillRect :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hDC : HDC -> Ptr ()
-- lprc : RECT* -> Ptr ()
-- hbr : HBRUSH -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let fillrect =
foreign "FillRect"
((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hDC : HDC -> (ptr void) *)
(* lprc : RECT* -> (ptr void) *)
(* hbr : HBRUSH -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("FillRect" fill-rect :convention :stdcall) :int32
(h-dc :pointer) ; HDC
(lprc :pointer) ; RECT*
(hbr :pointer)) ; HBRUSH
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FillRect = Win32::API::More->new('USER32',
'int FillRect(HANDLE hDC, LPVOID lprc, HANDLE hbr)');
# my $ret = $FillRect->Call($hDC, $lprc, $hbr);
# hDC : HDC -> HANDLE
# lprc : RECT* -> LPVOID
# hbr : HBRUSH -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CreateHatchBrush — 指定したハッチパターンと色のブラシを作成する。
- f CreatePatternBrush — 指定ビットマップをパターンとするブラシを作成する。
- f CreateSolidBrush — 指定した色の塗りつぶし用ソリッドブラシを作成する。
- f GetStockObject — システム標準のストックGDIオブジェクトを取得する。
使用する型