ホーム › Graphics.Gdi › PatBlt
PatBlt
関数現在のブラシで矩形をパターン描画する。
シグネチャ
// GDI32.dll
#include <windows.h>
BOOL PatBlt(
HDC hdc,
INT x,
INT y,
INT w,
INT h,
ROP_CODE rop
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドル。 |
| x | INT | in | 塗りつぶす四角形の左上隅の x 座標 (論理単位)。 |
| y | INT | in | 塗りつぶす四角形の左上隅の y 座標 (論理単位)。 |
| w | INT | in | 四角形の幅 (論理単位)。 |
| h | INT | in | 四角形の高さ (論理単位)。 |
| rop | ROP_CODE | in | ラスター演算コード。このコードには、次のいずれかの値を指定できます。 |
戻り値の型: BOOL
公式ドキュメント
PatBlt 関数は、指定したデバイスコンテキストに現在選択されているブラシを使用して、指定した四角形を塗りつぶします。ブラシの色とサーフェスの色は、指定したラスター演算によって組み合わされます。
戻り値
関数が成功すると、戻り値は 0 以外の値になります。
関数が失敗すると、戻り値は 0 になります。
解説(Remarks)
この関数の dwRop パラメーターに指定できる値は、完全な 256 個の 3 項ラスター演算コードのうちの限られたサブセットです。特に、転送元四角形を参照する演算コードは使用できません。
すべてのデバイスが PatBlt 関数をサポートしているわけではありません。詳細については、GetDeviceCaps 関数の RC_BITBLT 機能の説明を参照してください。
例
例については、メニューの使用の「メニュー項目ビットマップの例」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
BOOL PatBlt(
HDC hdc,
INT x,
INT y,
INT w,
INT h,
ROP_CODE rop
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool PatBlt(
IntPtr hdc, // HDC
int x, // INT
int y, // INT
int w, // INT
int h, // INT
uint rop // ROP_CODE
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function PatBlt(
hdc As IntPtr, ' HDC
x As Integer, ' INT
y As Integer, ' INT
w As Integer, ' INT
h As Integer, ' INT
rop As UInteger ' ROP_CODE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' x : INT
' y : INT
' w : INT
' h : INT
' rop : ROP_CODE
Declare PtrSafe Function PatBlt Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal w As Long, _
ByVal h As Long, _
ByVal rop As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PatBlt = ctypes.windll.gdi32.PatBlt
PatBlt.restype = wintypes.BOOL
PatBlt.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # x : INT
ctypes.c_int, # y : INT
ctypes.c_int, # w : INT
ctypes.c_int, # h : INT
wintypes.DWORD, # rop : ROP_CODE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
PatBlt = Fiddle::Function.new(
lib['PatBlt'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # x : INT
Fiddle::TYPE_INT, # y : INT
Fiddle::TYPE_INT, # w : INT
Fiddle::TYPE_INT, # h : INT
-Fiddle::TYPE_INT, # rop : ROP_CODE
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn PatBlt(
hdc: *mut core::ffi::c_void, // HDC
x: i32, // INT
y: i32, // INT
w: i32, // INT
h: i32, // INT
rop: u32 // ROP_CODE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool PatBlt(IntPtr hdc, int x, int y, int w, int h, uint rop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_PatBlt' -Namespace Win32 -PassThru
# $api::PatBlt(hdc, x, y, w, h, rop)#uselib "GDI32.dll"
#func global PatBlt "PatBlt" sptr, sptr, sptr, sptr, sptr, sptr
; PatBlt hdc, x, y, w, h, rop ; 戻り値は stat
; hdc : HDC -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; w : INT -> "sptr"
; h : INT -> "sptr"
; rop : ROP_CODE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global PatBlt "PatBlt" sptr, int, int, int, int, int
; res = PatBlt(hdc, x, y, w, h, rop)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; w : INT -> "int"
; h : INT -> "int"
; rop : ROP_CODE -> "int"; BOOL PatBlt(HDC hdc, INT x, INT y, INT w, INT h, ROP_CODE rop)
#uselib "GDI32.dll"
#cfunc global PatBlt "PatBlt" intptr, int, int, int, int, int
; res = PatBlt(hdc, x, y, w, h, rop)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; w : INT -> "int"
; h : INT -> "int"
; rop : ROP_CODE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procPatBlt = gdi32.NewProc("PatBlt")
)
// hdc (HDC), x (INT), y (INT), w (INT), h (INT), rop (ROP_CODE)
r1, _, err := procPatBlt.Call(
uintptr(hdc),
uintptr(x),
uintptr(y),
uintptr(w),
uintptr(h),
uintptr(rop),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PatBlt(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
w: Integer; // INT
h: Integer; // INT
rop: DWORD // ROP_CODE
): BOOL; stdcall;
external 'GDI32.dll' name 'PatBlt';result := DllCall("GDI32\PatBlt"
, "Ptr", hdc ; HDC
, "Int", x ; INT
, "Int", y ; INT
, "Int", w ; INT
, "Int", h ; INT
, "UInt", rop ; ROP_CODE
, "Int") ; return: BOOL●PatBlt(hdc, x, y, w, h, rop) = DLL("GDI32.dll", "bool PatBlt(void*, int, int, int, int, dword)")
# 呼び出し: PatBlt(hdc, x, y, w, h, rop)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# w : INT -> "int"
# h : INT -> "int"
# rop : ROP_CODE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn PatBlt(
hdc: ?*anyopaque, // HDC
x: i32, // INT
y: i32, // INT
w: i32, // INT
h: i32, // INT
rop: u32 // ROP_CODE
) callconv(std.os.windows.WINAPI) i32;proc PatBlt(
hdc: pointer, # HDC
x: int32, # INT
y: int32, # INT
w: int32, # INT
h: int32, # INT
rop: uint32 # ROP_CODE
): int32 {.importc: "PatBlt", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int PatBlt(
void* hdc, // HDC
int x, // INT
int y, // INT
int w, // INT
int h, // INT
uint rop // ROP_CODE
);ccall((:PatBlt, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Int32, Int32, UInt32),
hdc, x, y, w, h, rop)
# hdc : HDC -> Ptr{Cvoid}
# x : INT -> Int32
# y : INT -> Int32
# w : INT -> Int32
# h : INT -> Int32
# rop : ROP_CODE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PatBlt(
void* hdc,
int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t rop);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.PatBlt(hdc, x, y, w, h, rop)
-- hdc : HDC
-- x : INT
-- y : INT
-- w : INT
-- h : INT
-- rop : ROP_CODE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const PatBlt = lib.func('__stdcall', 'PatBlt', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'uint32_t']);
// PatBlt(hdc, x, y, w, h, rop)
// hdc : HDC -> 'void *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// w : INT -> 'int32_t'
// h : INT -> 'int32_t'
// rop : ROP_CODE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
PatBlt: { parameters: ["pointer", "i32", "i32", "i32", "i32", "u32"], result: "i32" },
});
// lib.symbols.PatBlt(hdc, x, y, w, h, rop)
// hdc : HDC -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// w : INT -> "i32"
// h : INT -> "i32"
// rop : ROP_CODE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PatBlt(
void* hdc,
int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t rop);
C, "GDI32.dll");
// $ffi->PatBlt(hdc, x, y, w, h, rop);
// hdc : HDC
// x : INT
// y : INT
// w : INT
// h : INT
// rop : ROP_CODE
// 構造体/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);
boolean PatBlt(
Pointer hdc, // HDC
int x, // INT
int y, // INT
int w, // INT
int h, // INT
int rop // ROP_CODE
);
}@[Link("gdi32")]
lib LibGDI32
fun PatBlt = PatBlt(
hdc : Void*, # HDC
x : Int32, # INT
y : Int32, # INT
w : Int32, # INT
h : Int32, # INT
rop : UInt32 # ROP_CODE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PatBltNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Int32, Uint32);
typedef PatBltDart = int Function(Pointer<Void>, int, int, int, int, int);
final PatBlt = DynamicLibrary.open('GDI32.dll')
.lookupFunction<PatBltNative, PatBltDart>('PatBlt');
// hdc : HDC -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// w : INT -> Int32
// h : INT -> Int32
// rop : ROP_CODE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PatBlt(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
w: Integer; // INT
h: Integer; // INT
rop: DWORD // ROP_CODE
): BOOL; stdcall;
external 'GDI32.dll' name 'PatBlt';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PatBlt"
c_PatBlt :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Word32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- w : INT -> Int32
-- h : INT -> Int32
-- rop : ROP_CODE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let patblt =
foreign "PatBlt"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* w : INT -> int32_t *)
(* h : INT -> int32_t *)
(* rop : ROP_CODE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("PatBlt" pat-blt :convention :stdcall) :int32
(hdc :pointer) ; HDC
(x :int32) ; INT
(y :int32) ; INT
(w :int32) ; INT
(h :int32) ; INT
(rop :uint32)) ; ROP_CODE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PatBlt = Win32::API::More->new('GDI32',
'BOOL PatBlt(HANDLE hdc, int x, int y, int w, int h, DWORD rop)');
# my $ret = $PatBlt->Call($hdc, $x, $y, $w, $h, $rop);
# hdc : HDC -> HANDLE
# x : INT -> int
# y : INT -> int
# w : INT -> int
# h : INT -> int
# rop : ROP_CODE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetDeviceCaps — デバイスの能力や属性情報を取得する。
使用する型