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

DrawIcon

関数
指定デバイスコンテキストの座標にアイコンを描画する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL DrawIcon(
    HDC hDC,
    INT X,
    INT Y,
    HICON hIcon
);

パラメーター

名前方向
hDCHDCin
XINTin
YINTin
hIconHICONin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL DrawIcon(
    HDC hDC,
    INT X,
    INT Y,
    HICON hIcon
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool DrawIcon(
    IntPtr hDC,   // HDC
    int X,   // INT
    int Y,   // INT
    IntPtr hIcon   // HICON
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DrawIcon(
    hDC As IntPtr,   ' HDC
    X As Integer,   ' INT
    Y As Integer,   ' INT
    hIcon As IntPtr   ' HICON
) As Boolean
End Function
' hDC : HDC
' X : INT
' Y : INT
' hIcon : HICON
Declare PtrSafe Function DrawIcon Lib "user32" ( _
    ByVal hDC As LongPtr, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal hIcon As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrawIcon = ctypes.windll.user32.DrawIcon
DrawIcon.restype = wintypes.BOOL
DrawIcon.argtypes = [
    wintypes.HANDLE,  # hDC : HDC
    ctypes.c_int,  # X : INT
    ctypes.c_int,  # Y : INT
    wintypes.HANDLE,  # hIcon : HICON
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DrawIcon = Fiddle::Function.new(
  lib['DrawIcon'],
  [
    Fiddle::TYPE_VOIDP,  # hDC : HDC
    Fiddle::TYPE_INT,  # X : INT
    Fiddle::TYPE_INT,  # Y : INT
    Fiddle::TYPE_VOIDP,  # hIcon : HICON
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn DrawIcon(
        hDC: *mut core::ffi::c_void,  // HDC
        X: i32,  // INT
        Y: i32,  // INT
        hIcon: *mut core::ffi::c_void  // HICON
    ) -> 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 DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DrawIcon' -Namespace Win32 -PassThru
# $api::DrawIcon(hDC, X, Y, hIcon)
#uselib "USER32.dll"
#func global DrawIcon "DrawIcon" sptr, sptr, sptr, sptr
; DrawIcon hDC, X, Y, hIcon   ; 戻り値は stat
; hDC : HDC -> "sptr"
; X : INT -> "sptr"
; Y : INT -> "sptr"
; hIcon : HICON -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global DrawIcon "DrawIcon" sptr, int, int, sptr
; res = DrawIcon(hDC, X, Y, hIcon)
; hDC : HDC -> "sptr"
; X : INT -> "int"
; Y : INT -> "int"
; hIcon : HICON -> "sptr"
; BOOL DrawIcon(HDC hDC, INT X, INT Y, HICON hIcon)
#uselib "USER32.dll"
#cfunc global DrawIcon "DrawIcon" intptr, int, int, intptr
; res = DrawIcon(hDC, X, Y, hIcon)
; hDC : HDC -> "intptr"
; X : INT -> "int"
; Y : INT -> "int"
; hIcon : HICON -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDrawIcon = user32.NewProc("DrawIcon")
)

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