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

BitBlt

関数
デバイスコンテキスト間でビットマップのブロック転送を行う。
DLLGDI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL BitBlt(
    HDC hdc,
    INT x,
    INT y,
    INT cx,
    INT cy,
    HDC hdcSrc,   // optional
    INT x1,
    INT y1,
    ROP_CODE rop
);

パラメーター

名前方向
hdcHDCin
xINTin
yINTin
cxINTin
cyINTin
hdcSrcHDCinoptional
x1INTin
y1INTin
ropROP_CODEin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL BitBlt(
    HDC hdc,
    INT x,
    INT y,
    INT cx,
    INT cy,
    HDC hdcSrc,   // optional
    INT x1,
    INT y1,
    ROP_CODE rop
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool BitBlt(
    IntPtr hdc,   // HDC
    int x,   // INT
    int y,   // INT
    int cx,   // INT
    int cy,   // INT
    IntPtr hdcSrc,   // HDC optional
    int x1,   // INT
    int y1,   // INT
    uint rop   // ROP_CODE
);
<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BitBlt(
    hdc As IntPtr,   ' HDC
    x As Integer,   ' INT
    y As Integer,   ' INT
    cx As Integer,   ' INT
    cy As Integer,   ' INT
    hdcSrc As IntPtr,   ' HDC optional
    x1 As Integer,   ' INT
    y1 As Integer,   ' INT
    rop As UInteger   ' ROP_CODE
) As Boolean
End Function
' hdc : HDC
' x : INT
' y : INT
' cx : INT
' cy : INT
' hdcSrc : HDC optional
' x1 : INT
' y1 : INT
' rop : ROP_CODE
Declare PtrSafe Function BitBlt Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal hdcSrc As LongPtr, _
    ByVal x1 As Long, _
    ByVal y1 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

BitBlt = ctypes.windll.gdi32.BitBlt
BitBlt.restype = wintypes.BOOL
BitBlt.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # x : INT
    ctypes.c_int,  # y : INT
    ctypes.c_int,  # cx : INT
    ctypes.c_int,  # cy : INT
    wintypes.HANDLE,  # hdcSrc : HDC optional
    ctypes.c_int,  # x1 : INT
    ctypes.c_int,  # y1 : INT
    wintypes.DWORD,  # rop : ROP_CODE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
BitBlt = Fiddle::Function.new(
  lib['BitBlt'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # x : INT
    Fiddle::TYPE_INT,  # y : INT
    Fiddle::TYPE_INT,  # cx : INT
    Fiddle::TYPE_INT,  # cy : INT
    Fiddle::TYPE_VOIDP,  # hdcSrc : HDC optional
    Fiddle::TYPE_INT,  # x1 : INT
    Fiddle::TYPE_INT,  # y1 : INT
    -Fiddle::TYPE_INT,  # rop : ROP_CODE
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn BitBlt(
        hdc: *mut core::ffi::c_void,  // HDC
        x: i32,  // INT
        y: i32,  // INT
        cx: i32,  // INT
        cy: i32,  // INT
        hdcSrc: *mut core::ffi::c_void,  // HDC optional
        x1: i32,  // INT
        y1: 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", SetLastError = true)]
public static extern bool BitBlt(IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, uint rop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_BitBlt' -Namespace Win32 -PassThru
# $api::BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
#uselib "GDI32.dll"
#func global BitBlt "BitBlt" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BitBlt hdc, x, y, cx, cy, hdcSrc, x1, y1, rop   ; 戻り値は stat
; hdc : HDC -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; hdcSrc : HDC optional -> "sptr"
; x1 : INT -> "sptr"
; y1 : INT -> "sptr"
; rop : ROP_CODE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global BitBlt "BitBlt" sptr, int, int, int, int, sptr, int, int, int
; res = BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; hdcSrc : HDC optional -> "sptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; rop : ROP_CODE -> "int"
; BOOL BitBlt(HDC hdc, INT x, INT y, INT cx, INT cy, HDC hdcSrc, INT x1, INT y1, ROP_CODE rop)
#uselib "GDI32.dll"
#cfunc global BitBlt "BitBlt" intptr, int, int, int, int, intptr, int, int, int
; res = BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; hdcSrc : HDC optional -> "intptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; rop : ROP_CODE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procBitBlt = gdi32.NewProc("BitBlt")
)

// hdc (HDC), x (INT), y (INT), cx (INT), cy (INT), hdcSrc (HDC optional), x1 (INT), y1 (INT), rop (ROP_CODE)
r1, _, err := procBitBlt.Call(
	uintptr(hdc),
	uintptr(x),
	uintptr(y),
	uintptr(cx),
	uintptr(cy),
	uintptr(hdcSrc),
	uintptr(x1),
	uintptr(y1),
	uintptr(rop),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function BitBlt(
  hdc: THandle;   // HDC
  x: Integer;   // INT
  y: Integer;   // INT
  cx: Integer;   // INT
  cy: Integer;   // INT
  hdcSrc: THandle;   // HDC optional
  x1: Integer;   // INT
  y1: Integer;   // INT
  rop: DWORD   // ROP_CODE
): BOOL; stdcall;
  external 'GDI32.dll' name 'BitBlt';
result := DllCall("GDI32\BitBlt"
    , "Ptr", hdc   ; HDC
    , "Int", x   ; INT
    , "Int", y   ; INT
    , "Int", cx   ; INT
    , "Int", cy   ; INT
    , "Ptr", hdcSrc   ; HDC optional
    , "Int", x1   ; INT
    , "Int", y1   ; INT
    , "UInt", rop   ; ROP_CODE
    , "Int")   ; return: BOOL
●BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop) = DLL("GDI32.dll", "bool BitBlt(void*, int, int, int, int, void*, int, int, dword)")
# 呼び出し: BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# cx : INT -> "int"
# cy : INT -> "int"
# hdcSrc : HDC optional -> "void*"
# x1 : INT -> "int"
# y1 : INT -> "int"
# rop : ROP_CODE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。