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

CreateBitmap

関数
指定した幅・高さ・色深度のビットマップを作成する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HBITMAP CreateBitmap(
    INT nWidth,
    INT nHeight,
    DWORD nPlanes,
    DWORD nBitCount,
    const void* lpBits   // optional
);

パラメーター

名前方向
nWidthINTin
nHeightINTin
nPlanesDWORDin
nBitCountDWORDin
lpBitsvoid*inoptional

戻り値の型: HBITMAP

各言語での呼び出し定義

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

HBITMAP CreateBitmap(
    INT nWidth,
    INT nHeight,
    DWORD nPlanes,
    DWORD nBitCount,
    const void* lpBits   // optional
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr CreateBitmap(
    int nWidth,   // INT
    int nHeight,   // INT
    uint nPlanes,   // DWORD
    uint nBitCount,   // DWORD
    IntPtr lpBits   // void* optional
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function CreateBitmap(
    nWidth As Integer,   ' INT
    nHeight As Integer,   ' INT
    nPlanes As UInteger,   ' DWORD
    nBitCount As UInteger,   ' DWORD
    lpBits As IntPtr   ' void* optional
) As IntPtr
End Function
' nWidth : INT
' nHeight : INT
' nPlanes : DWORD
' nBitCount : DWORD
' lpBits : void* optional
Declare PtrSafe Function CreateBitmap Lib "gdi32" ( _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal nPlanes As Long, _
    ByVal nBitCount As Long, _
    ByVal lpBits As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateBitmap = ctypes.windll.gdi32.CreateBitmap
CreateBitmap.restype = ctypes.c_void_p
CreateBitmap.argtypes = [
    ctypes.c_int,  # nWidth : INT
    ctypes.c_int,  # nHeight : INT
    wintypes.DWORD,  # nPlanes : DWORD
    wintypes.DWORD,  # nBitCount : DWORD
    ctypes.POINTER(None),  # lpBits : void* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateBitmap = gdi32.NewProc("CreateBitmap")
)

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