Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › DrawIconEx

DrawIconEx

関数
指定位置にアイコンまたはカーソルを描画する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL DrawIconEx(
    HDC hdc,
    INT xLeft,
    INT yTop,
    HICON hIcon,
    INT cxWidth,
    INT cyWidth,
    DWORD istepIfAniCur,
    HBRUSH hbrFlickerFreeDraw,   // optional
    DI_FLAGS diFlags
);

パラメーター

名前方向
hdcHDCin
xLeftINTin
yTopINTin
hIconHICONin
cxWidthINTin
cyWidthINTin
istepIfAniCurDWORDin
hbrFlickerFreeDrawHBRUSHinoptional
diFlagsDI_FLAGSin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL DrawIconEx(
    HDC hdc,
    INT xLeft,
    INT yTop,
    HICON hIcon,
    INT cxWidth,
    INT cyWidth,
    DWORD istepIfAniCur,
    HBRUSH hbrFlickerFreeDraw,   // optional
    DI_FLAGS diFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool DrawIconEx(
    IntPtr hdc,   // HDC
    int xLeft,   // INT
    int yTop,   // INT
    IntPtr hIcon,   // HICON
    int cxWidth,   // INT
    int cyWidth,   // INT
    uint istepIfAniCur,   // DWORD
    IntPtr hbrFlickerFreeDraw,   // HBRUSH optional
    uint diFlags   // DI_FLAGS
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DrawIconEx(
    hdc As IntPtr,   ' HDC
    xLeft As Integer,   ' INT
    yTop As Integer,   ' INT
    hIcon As IntPtr,   ' HICON
    cxWidth As Integer,   ' INT
    cyWidth As Integer,   ' INT
    istepIfAniCur As UInteger,   ' DWORD
    hbrFlickerFreeDraw As IntPtr,   ' HBRUSH optional
    diFlags As UInteger   ' DI_FLAGS
) As Boolean
End Function
' hdc : HDC
' xLeft : INT
' yTop : INT
' hIcon : HICON
' cxWidth : INT
' cyWidth : INT
' istepIfAniCur : DWORD
' hbrFlickerFreeDraw : HBRUSH optional
' diFlags : DI_FLAGS
Declare PtrSafe Function DrawIconEx Lib "user32" ( _
    ByVal hdc As LongPtr, _
    ByVal xLeft As Long, _
    ByVal yTop As Long, _
    ByVal hIcon As LongPtr, _
    ByVal cxWidth As Long, _
    ByVal cyWidth As Long, _
    ByVal istepIfAniCur As Long, _
    ByVal hbrFlickerFreeDraw As LongPtr, _
    ByVal diFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrawIconEx = ctypes.windll.user32.DrawIconEx
DrawIconEx.restype = wintypes.BOOL
DrawIconEx.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # xLeft : INT
    ctypes.c_int,  # yTop : INT
    wintypes.HANDLE,  # hIcon : HICON
    ctypes.c_int,  # cxWidth : INT
    ctypes.c_int,  # cyWidth : INT
    wintypes.DWORD,  # istepIfAniCur : DWORD
    wintypes.HANDLE,  # hbrFlickerFreeDraw : HBRUSH optional
    wintypes.DWORD,  # diFlags : DI_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DrawIconEx = Fiddle::Function.new(
  lib['DrawIconEx'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # xLeft : INT
    Fiddle::TYPE_INT,  # yTop : INT
    Fiddle::TYPE_VOIDP,  # hIcon : HICON
    Fiddle::TYPE_INT,  # cxWidth : INT
    Fiddle::TYPE_INT,  # cyWidth : INT
    -Fiddle::TYPE_INT,  # istepIfAniCur : DWORD
    Fiddle::TYPE_VOIDP,  # hbrFlickerFreeDraw : HBRUSH optional
    -Fiddle::TYPE_INT,  # diFlags : DI_FLAGS
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn DrawIconEx(
        hdc: *mut core::ffi::c_void,  // HDC
        xLeft: i32,  // INT
        yTop: i32,  // INT
        hIcon: *mut core::ffi::c_void,  // HICON
        cxWidth: i32,  // INT
        cyWidth: i32,  // INT
        istepIfAniCur: u32,  // DWORD
        hbrFlickerFreeDraw: *mut core::ffi::c_void,  // HBRUSH optional
        diFlags: u32  // DI_FLAGS
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyWidth, uint istepIfAniCur, IntPtr hbrFlickerFreeDraw, uint diFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DrawIconEx' -Namespace Win32 -PassThru
# $api::DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags)
#uselib "USER32.dll"
#func global DrawIconEx "DrawIconEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DrawIconEx hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags   ; 戻り値は stat
; hdc : HDC -> "sptr"
; xLeft : INT -> "sptr"
; yTop : INT -> "sptr"
; hIcon : HICON -> "sptr"
; cxWidth : INT -> "sptr"
; cyWidth : INT -> "sptr"
; istepIfAniCur : DWORD -> "sptr"
; hbrFlickerFreeDraw : HBRUSH optional -> "sptr"
; diFlags : DI_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global DrawIconEx "DrawIconEx" sptr, int, int, sptr, int, int, int, sptr, int
; res = DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags)
; hdc : HDC -> "sptr"
; xLeft : INT -> "int"
; yTop : INT -> "int"
; hIcon : HICON -> "sptr"
; cxWidth : INT -> "int"
; cyWidth : INT -> "int"
; istepIfAniCur : DWORD -> "int"
; hbrFlickerFreeDraw : HBRUSH optional -> "sptr"
; diFlags : DI_FLAGS -> "int"
; BOOL DrawIconEx(HDC hdc, INT xLeft, INT yTop, HICON hIcon, INT cxWidth, INT cyWidth, DWORD istepIfAniCur, HBRUSH hbrFlickerFreeDraw, DI_FLAGS diFlags)
#uselib "USER32.dll"
#cfunc global DrawIconEx "DrawIconEx" intptr, int, int, intptr, int, int, int, intptr, int
; res = DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags)
; hdc : HDC -> "intptr"
; xLeft : INT -> "int"
; yTop : INT -> "int"
; hIcon : HICON -> "intptr"
; cxWidth : INT -> "int"
; cyWidth : INT -> "int"
; istepIfAniCur : DWORD -> "int"
; hbrFlickerFreeDraw : HBRUSH optional -> "intptr"
; diFlags : DI_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDrawIconEx = user32.NewProc("DrawIconEx")
)

// hdc (HDC), xLeft (INT), yTop (INT), hIcon (HICON), cxWidth (INT), cyWidth (INT), istepIfAniCur (DWORD), hbrFlickerFreeDraw (HBRUSH optional), diFlags (DI_FLAGS)
r1, _, err := procDrawIconEx.Call(
	uintptr(hdc),
	uintptr(xLeft),
	uintptr(yTop),
	uintptr(hIcon),
	uintptr(cxWidth),
	uintptr(cyWidth),
	uintptr(istepIfAniCur),
	uintptr(hbrFlickerFreeDraw),
	uintptr(diFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function DrawIconEx(
  hdc: THandle;   // HDC
  xLeft: Integer;   // INT
  yTop: Integer;   // INT
  hIcon: THandle;   // HICON
  cxWidth: Integer;   // INT
  cyWidth: Integer;   // INT
  istepIfAniCur: DWORD;   // DWORD
  hbrFlickerFreeDraw: THandle;   // HBRUSH optional
  diFlags: DWORD   // DI_FLAGS
): BOOL; stdcall;
  external 'USER32.dll' name 'DrawIconEx';
result := DllCall("USER32\DrawIconEx"
    , "Ptr", hdc   ; HDC
    , "Int", xLeft   ; INT
    , "Int", yTop   ; INT
    , "Ptr", hIcon   ; HICON
    , "Int", cxWidth   ; INT
    , "Int", cyWidth   ; INT
    , "UInt", istepIfAniCur   ; DWORD
    , "Ptr", hbrFlickerFreeDraw   ; HBRUSH optional
    , "UInt", diFlags   ; DI_FLAGS
    , "Int")   ; return: BOOL
●DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags) = DLL("USER32.dll", "bool DrawIconEx(void*, int, int, void*, int, int, dword, void*, dword)")
# 呼び出し: DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags)
# hdc : HDC -> "void*"
# xLeft : INT -> "int"
# yTop : INT -> "int"
# hIcon : HICON -> "void*"
# cxWidth : INT -> "int"
# cyWidth : INT -> "int"
# istepIfAniCur : DWORD -> "dword"
# hbrFlickerFreeDraw : HBRUSH optional -> "void*"
# diFlags : DI_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。