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

CreateCompatibleBitmap

関数
指定デバイスコンテキストと互換のビットマップを作成する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HBITMAP CreateCompatibleBitmap(
    HDC hdc,
    INT cx,
    INT cy
);

パラメーター

名前方向
hdcHDCin
cxINTin
cyINTin

戻り値の型: HBITMAP

各言語での呼び出し定義

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

HBITMAP CreateCompatibleBitmap(
    HDC hdc,
    INT cx,
    INT cy
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr CreateCompatibleBitmap(
    IntPtr hdc,   // HDC
    int cx,   // INT
    int cy   // INT
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function CreateCompatibleBitmap(
    hdc As IntPtr,   ' HDC
    cx As Integer,   ' INT
    cy As Integer   ' INT
) As IntPtr
End Function
' hdc : HDC
' cx : INT
' cy : INT
Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal cx As Long, _
    ByVal cy As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateCompatibleBitmap = ctypes.windll.gdi32.CreateCompatibleBitmap
CreateCompatibleBitmap.restype = ctypes.c_void_p
CreateCompatibleBitmap.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # cx : INT
    ctypes.c_int,  # cy : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateCompatibleBitmap = Fiddle::Function.new(
  lib['CreateCompatibleBitmap'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # cx : INT
    Fiddle::TYPE_INT,  # cy : INT
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn CreateCompatibleBitmap(
        hdc: *mut core::ffi::c_void,  // HDC
        cx: i32,  // INT
        cy: i32  // INT
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int cx, int cy);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateCompatibleBitmap' -Namespace Win32 -PassThru
# $api::CreateCompatibleBitmap(hdc, cx, cy)
#uselib "GDI32.dll"
#func global CreateCompatibleBitmap "CreateCompatibleBitmap" sptr, sptr, sptr
; CreateCompatibleBitmap hdc, cx, cy   ; 戻り値は stat
; hdc : HDC -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global CreateCompatibleBitmap "CreateCompatibleBitmap" sptr, int, int
; res = CreateCompatibleBitmap(hdc, cx, cy)
; hdc : HDC -> "sptr"
; cx : INT -> "int"
; cy : INT -> "int"
; HBITMAP CreateCompatibleBitmap(HDC hdc, INT cx, INT cy)
#uselib "GDI32.dll"
#cfunc global CreateCompatibleBitmap "CreateCompatibleBitmap" intptr, int, int
; res = CreateCompatibleBitmap(hdc, cx, cy)
; hdc : HDC -> "intptr"
; cx : INT -> "int"
; cy : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateCompatibleBitmap = gdi32.NewProc("CreateCompatibleBitmap")
)

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