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

MaskBlt

関数
マスクを用いてビットマップを合成転送する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL MaskBlt(
    HDC hdcDest,
    INT xDest,
    INT yDest,
    INT width,
    INT height,
    HDC hdcSrc,
    INT xSrc,
    INT ySrc,
    HBITMAP hbmMask,
    INT xMask,
    INT yMask,
    DWORD rop
);

パラメーター

名前方向
hdcDestHDCin
xDestINTin
yDestINTin
widthINTin
heightINTin
hdcSrcHDCin
xSrcINTin
ySrcINTin
hbmMaskHBITMAPin
xMaskINTin
yMaskINTin
ropDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL MaskBlt(
    HDC hdcDest,
    INT xDest,
    INT yDest,
    INT width,
    INT height,
    HDC hdcSrc,
    INT xSrc,
    INT ySrc,
    HBITMAP hbmMask,
    INT xMask,
    INT yMask,
    DWORD rop
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool MaskBlt(
    IntPtr hdcDest,   // HDC
    int xDest,   // INT
    int yDest,   // INT
    int width,   // INT
    int height,   // INT
    IntPtr hdcSrc,   // HDC
    int xSrc,   // INT
    int ySrc,   // INT
    IntPtr hbmMask,   // HBITMAP
    int xMask,   // INT
    int yMask,   // INT
    uint rop   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function MaskBlt(
    hdcDest As IntPtr,   ' HDC
    xDest As Integer,   ' INT
    yDest As Integer,   ' INT
    width As Integer,   ' INT
    height As Integer,   ' INT
    hdcSrc As IntPtr,   ' HDC
    xSrc As Integer,   ' INT
    ySrc As Integer,   ' INT
    hbmMask As IntPtr,   ' HBITMAP
    xMask As Integer,   ' INT
    yMask As Integer,   ' INT
    rop As UInteger   ' DWORD
) As Boolean
End Function
' hdcDest : HDC
' xDest : INT
' yDest : INT
' width : INT
' height : INT
' hdcSrc : HDC
' xSrc : INT
' ySrc : INT
' hbmMask : HBITMAP
' xMask : INT
' yMask : INT
' rop : DWORD
Declare PtrSafe Function MaskBlt Lib "gdi32" ( _
    ByVal hdcDest As LongPtr, _
    ByVal xDest As Long, _
    ByVal yDest As Long, _
    ByVal width As Long, _
    ByVal height As Long, _
    ByVal hdcSrc As LongPtr, _
    ByVal xSrc As Long, _
    ByVal ySrc As Long, _
    ByVal hbmMask As LongPtr, _
    ByVal xMask As Long, _
    ByVal yMask 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

MaskBlt = ctypes.windll.gdi32.MaskBlt
MaskBlt.restype = wintypes.BOOL
MaskBlt.argtypes = [
    wintypes.HANDLE,  # hdcDest : HDC
    ctypes.c_int,  # xDest : INT
    ctypes.c_int,  # yDest : INT
    ctypes.c_int,  # width : INT
    ctypes.c_int,  # height : INT
    wintypes.HANDLE,  # hdcSrc : HDC
    ctypes.c_int,  # xSrc : INT
    ctypes.c_int,  # ySrc : INT
    wintypes.HANDLE,  # hbmMask : HBITMAP
    ctypes.c_int,  # xMask : INT
    ctypes.c_int,  # yMask : INT
    wintypes.DWORD,  # rop : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
MaskBlt = Fiddle::Function.new(
  lib['MaskBlt'],
  [
    Fiddle::TYPE_VOIDP,  # hdcDest : HDC
    Fiddle::TYPE_INT,  # xDest : INT
    Fiddle::TYPE_INT,  # yDest : INT
    Fiddle::TYPE_INT,  # width : INT
    Fiddle::TYPE_INT,  # height : INT
    Fiddle::TYPE_VOIDP,  # hdcSrc : HDC
    Fiddle::TYPE_INT,  # xSrc : INT
    Fiddle::TYPE_INT,  # ySrc : INT
    Fiddle::TYPE_VOIDP,  # hbmMask : HBITMAP
    Fiddle::TYPE_INT,  # xMask : INT
    Fiddle::TYPE_INT,  # yMask : INT
    -Fiddle::TYPE_INT,  # rop : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn MaskBlt(
        hdcDest: *mut core::ffi::c_void,  // HDC
        xDest: i32,  // INT
        yDest: i32,  // INT
        width: i32,  // INT
        height: i32,  // INT
        hdcSrc: *mut core::ffi::c_void,  // HDC
        xSrc: i32,  // INT
        ySrc: i32,  // INT
        hbmMask: *mut core::ffi::c_void,  // HBITMAP
        xMask: i32,  // INT
        yMask: i32,  // INT
        rop: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool MaskBlt(IntPtr hdcDest, int xDest, int yDest, int width, int height, IntPtr hdcSrc, int xSrc, int ySrc, IntPtr hbmMask, int xMask, int yMask, uint rop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_MaskBlt' -Namespace Win32 -PassThru
# $api::MaskBlt(hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop)
#uselib "GDI32.dll"
#func global MaskBlt "MaskBlt" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MaskBlt hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop   ; 戻り値は stat
; hdcDest : HDC -> "sptr"
; xDest : INT -> "sptr"
; yDest : INT -> "sptr"
; width : INT -> "sptr"
; height : INT -> "sptr"
; hdcSrc : HDC -> "sptr"
; xSrc : INT -> "sptr"
; ySrc : INT -> "sptr"
; hbmMask : HBITMAP -> "sptr"
; xMask : INT -> "sptr"
; yMask : INT -> "sptr"
; rop : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global MaskBlt "MaskBlt" sptr, int, int, int, int, sptr, int, int, sptr, int, int, int
; res = MaskBlt(hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop)
; hdcDest : HDC -> "sptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; width : INT -> "int"
; height : INT -> "int"
; hdcSrc : HDC -> "sptr"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; hbmMask : HBITMAP -> "sptr"
; xMask : INT -> "int"
; yMask : INT -> "int"
; rop : DWORD -> "int"
; BOOL MaskBlt(HDC hdcDest, INT xDest, INT yDest, INT width, INT height, HDC hdcSrc, INT xSrc, INT ySrc, HBITMAP hbmMask, INT xMask, INT yMask, DWORD rop)
#uselib "GDI32.dll"
#cfunc global MaskBlt "MaskBlt" intptr, int, int, int, int, intptr, int, int, intptr, int, int, int
; res = MaskBlt(hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop)
; hdcDest : HDC -> "intptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; width : INT -> "int"
; height : INT -> "int"
; hdcSrc : HDC -> "intptr"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; hbmMask : HBITMAP -> "intptr"
; xMask : INT -> "int"
; yMask : INT -> "int"
; rop : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procMaskBlt = gdi32.NewProc("MaskBlt")
)

// hdcDest (HDC), xDest (INT), yDest (INT), width (INT), height (INT), hdcSrc (HDC), xSrc (INT), ySrc (INT), hbmMask (HBITMAP), xMask (INT), yMask (INT), rop (DWORD)
r1, _, err := procMaskBlt.Call(
	uintptr(hdcDest),
	uintptr(xDest),
	uintptr(yDest),
	uintptr(width),
	uintptr(height),
	uintptr(hdcSrc),
	uintptr(xSrc),
	uintptr(ySrc),
	uintptr(hbmMask),
	uintptr(xMask),
	uintptr(yMask),
	uintptr(rop),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function MaskBlt(
  hdcDest: THandle;   // HDC
  xDest: Integer;   // INT
  yDest: Integer;   // INT
  width: Integer;   // INT
  height: Integer;   // INT
  hdcSrc: THandle;   // HDC
  xSrc: Integer;   // INT
  ySrc: Integer;   // INT
  hbmMask: THandle;   // HBITMAP
  xMask: Integer;   // INT
  yMask: Integer;   // INT
  rop: DWORD   // DWORD
): BOOL; stdcall;
  external 'GDI32.dll' name 'MaskBlt';
result := DllCall("GDI32\MaskBlt"
    , "Ptr", hdcDest   ; HDC
    , "Int", xDest   ; INT
    , "Int", yDest   ; INT
    , "Int", width   ; INT
    , "Int", height   ; INT
    , "Ptr", hdcSrc   ; HDC
    , "Int", xSrc   ; INT
    , "Int", ySrc   ; INT
    , "Ptr", hbmMask   ; HBITMAP
    , "Int", xMask   ; INT
    , "Int", yMask   ; INT
    , "UInt", rop   ; DWORD
    , "Int")   ; return: BOOL
●MaskBlt(hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop) = DLL("GDI32.dll", "bool MaskBlt(void*, int, int, int, int, void*, int, int, void*, int, int, dword)")
# 呼び出し: MaskBlt(hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, hbmMask, xMask, yMask, rop)
# hdcDest : HDC -> "void*"
# xDest : INT -> "int"
# yDest : INT -> "int"
# width : INT -> "int"
# height : INT -> "int"
# hdcSrc : HDC -> "void*"
# xSrc : INT -> "int"
# ySrc : INT -> "int"
# hbmMask : HBITMAP -> "void*"
# xMask : INT -> "int"
# yMask : INT -> "int"
# rop : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。