ホーム › UI.WindowsAndMessaging › CreateIcon
CreateIcon
関数ANDマスクとXORマスクのビットからアイコンを作成する。
シグネチャ
// USER32.dll
#include <windows.h>
HICON CreateIcon(
HINSTANCE hInstance, // optional
INT nWidth,
INT nHeight,
BYTE cPlanes,
BYTE cBitsPixel,
const BYTE* lpbANDbits,
const BYTE* lpbXORbits
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hInstance | HINSTANCE | inoptional |
| nWidth | INT | in |
| nHeight | INT | in |
| cPlanes | BYTE | in |
| cBitsPixel | BYTE | in |
| lpbANDbits | BYTE* | in |
| lpbXORbits | BYTE* | in |
戻り値の型: HICON
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
HICON CreateIcon(
HINSTANCE hInstance, // optional
INT nWidth,
INT nHeight,
BYTE cPlanes,
BYTE cBitsPixel,
const BYTE* lpbANDbits,
const BYTE* lpbXORbits
);[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateIcon(
IntPtr hInstance, // HINSTANCE optional
int nWidth, // INT
int nHeight, // INT
byte cPlanes, // BYTE
byte cBitsPixel, // BYTE
IntPtr lpbANDbits, // BYTE*
IntPtr lpbXORbits // BYTE*
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateIcon(
hInstance As IntPtr, ' HINSTANCE optional
nWidth As Integer, ' INT
nHeight As Integer, ' INT
cPlanes As Byte, ' BYTE
cBitsPixel As Byte, ' BYTE
lpbANDbits As IntPtr, ' BYTE*
lpbXORbits As IntPtr ' BYTE*
) As IntPtr
End Function' hInstance : HINSTANCE optional
' nWidth : INT
' nHeight : INT
' cPlanes : BYTE
' cBitsPixel : BYTE
' lpbANDbits : BYTE*
' lpbXORbits : BYTE*
Declare PtrSafe Function CreateIcon Lib "user32" ( _
ByVal hInstance As LongPtr, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal cPlanes As Byte, _
ByVal cBitsPixel As Byte, _
ByVal lpbANDbits As LongPtr, _
ByVal lpbXORbits As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateIcon = ctypes.windll.user32.CreateIcon
CreateIcon.restype = ctypes.c_void_p
CreateIcon.argtypes = [
wintypes.HANDLE, # hInstance : HINSTANCE optional
ctypes.c_int, # nWidth : INT
ctypes.c_int, # nHeight : INT
ctypes.c_ubyte, # cPlanes : BYTE
ctypes.c_ubyte, # cBitsPixel : BYTE
ctypes.POINTER(ctypes.c_ubyte), # lpbANDbits : BYTE*
ctypes.POINTER(ctypes.c_ubyte), # lpbXORbits : BYTE*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
CreateIcon = Fiddle::Function.new(
lib['CreateIcon'],
[
Fiddle::TYPE_VOIDP, # hInstance : HINSTANCE optional
Fiddle::TYPE_INT, # nWidth : INT
Fiddle::TYPE_INT, # nHeight : INT
-Fiddle::TYPE_CHAR, # cPlanes : BYTE
-Fiddle::TYPE_CHAR, # cBitsPixel : BYTE
Fiddle::TYPE_VOIDP, # lpbANDbits : BYTE*
Fiddle::TYPE_VOIDP, # lpbXORbits : BYTE*
],
Fiddle::TYPE_VOIDP)#[link(name = "user32")]
extern "system" {
fn CreateIcon(
hInstance: *mut core::ffi::c_void, // HINSTANCE optional
nWidth: i32, // INT
nHeight: i32, // INT
cPlanes: u8, // BYTE
cBitsPixel: u8, // BYTE
lpbANDbits: *const u8, // BYTE*
lpbXORbits: *const u8 // BYTE*
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern IntPtr CreateIcon(IntPtr hInstance, int nWidth, int nHeight, byte cPlanes, byte cBitsPixel, IntPtr lpbANDbits, IntPtr lpbXORbits);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_CreateIcon' -Namespace Win32 -PassThru
# $api::CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits)#uselib "USER32.dll"
#func global CreateIcon "CreateIcon" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateIcon hInstance, nWidth, nHeight, cPlanes, cBitsPixel, varptr(lpbANDbits), varptr(lpbXORbits) ; 戻り値は stat
; hInstance : HINSTANCE optional -> "sptr"
; nWidth : INT -> "sptr"
; nHeight : INT -> "sptr"
; cPlanes : BYTE -> "sptr"
; cBitsPixel : BYTE -> "sptr"
; lpbANDbits : BYTE* -> "sptr"
; lpbXORbits : BYTE* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global CreateIcon "CreateIcon" sptr, int, int, int, int, var, var ; res = CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits) ; hInstance : HINSTANCE optional -> "sptr" ; nWidth : INT -> "int" ; nHeight : INT -> "int" ; cPlanes : BYTE -> "int" ; cBitsPixel : BYTE -> "int" ; lpbANDbits : BYTE* -> "var" ; lpbXORbits : BYTE* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global CreateIcon "CreateIcon" sptr, int, int, int, int, sptr, sptr ; res = CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, varptr(lpbANDbits), varptr(lpbXORbits)) ; hInstance : HINSTANCE optional -> "sptr" ; nWidth : INT -> "int" ; nHeight : INT -> "int" ; cPlanes : BYTE -> "int" ; cBitsPixel : BYTE -> "int" ; lpbANDbits : BYTE* -> "sptr" ; lpbXORbits : BYTE* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HICON CreateIcon(HINSTANCE hInstance, INT nWidth, INT nHeight, BYTE cPlanes, BYTE cBitsPixel, BYTE* lpbANDbits, BYTE* lpbXORbits) #uselib "USER32.dll" #cfunc global CreateIcon "CreateIcon" intptr, int, int, int, int, var, var ; res = CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits) ; hInstance : HINSTANCE optional -> "intptr" ; nWidth : INT -> "int" ; nHeight : INT -> "int" ; cPlanes : BYTE -> "int" ; cBitsPixel : BYTE -> "int" ; lpbANDbits : BYTE* -> "var" ; lpbXORbits : BYTE* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HICON CreateIcon(HINSTANCE hInstance, INT nWidth, INT nHeight, BYTE cPlanes, BYTE cBitsPixel, BYTE* lpbANDbits, BYTE* lpbXORbits) #uselib "USER32.dll" #cfunc global CreateIcon "CreateIcon" intptr, int, int, int, int, intptr, intptr ; res = CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, varptr(lpbANDbits), varptr(lpbXORbits)) ; hInstance : HINSTANCE optional -> "intptr" ; nWidth : INT -> "int" ; nHeight : INT -> "int" ; cPlanes : BYTE -> "int" ; cBitsPixel : BYTE -> "int" ; lpbANDbits : BYTE* -> "intptr" ; lpbXORbits : BYTE* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procCreateIcon = user32.NewProc("CreateIcon")
)
// hInstance (HINSTANCE optional), nWidth (INT), nHeight (INT), cPlanes (BYTE), cBitsPixel (BYTE), lpbANDbits (BYTE*), lpbXORbits (BYTE*)
r1, _, err := procCreateIcon.Call(
uintptr(hInstance),
uintptr(nWidth),
uintptr(nHeight),
uintptr(cPlanes),
uintptr(cBitsPixel),
uintptr(lpbANDbits),
uintptr(lpbXORbits),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HICONfunction CreateIcon(
hInstance: THandle; // HINSTANCE optional
nWidth: Integer; // INT
nHeight: Integer; // INT
cPlanes: Byte; // BYTE
cBitsPixel: Byte; // BYTE
lpbANDbits: Pointer; // BYTE*
lpbXORbits: Pointer // BYTE*
): THandle; stdcall;
external 'USER32.dll' name 'CreateIcon';result := DllCall("USER32\CreateIcon"
, "Ptr", hInstance ; HINSTANCE optional
, "Int", nWidth ; INT
, "Int", nHeight ; INT
, "UChar", cPlanes ; BYTE
, "UChar", cBitsPixel ; BYTE
, "Ptr", lpbANDbits ; BYTE*
, "Ptr", lpbXORbits ; BYTE*
, "Ptr") ; return: HICON●CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits) = DLL("USER32.dll", "void* CreateIcon(void*, int, int, byte, byte, void*, void*)")
# 呼び出し: CreateIcon(hInstance, nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits)
# hInstance : HINSTANCE optional -> "void*"
# nWidth : INT -> "int"
# nHeight : INT -> "int"
# cPlanes : BYTE -> "byte"
# cBitsPixel : BYTE -> "byte"
# lpbANDbits : BYTE* -> "void*"
# lpbXORbits : BYTE* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。