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

DrawThemeIcon

関数
イメージリスト内のアイコンをテーマに従って描画する。
DLLUxTheme.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT DrawThemeIcon(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    RECT* pRect,
    HIMAGELIST himl,
    INT iImageIndex
);

パラメーター

名前方向
hThemeHTHEMEin
hdcHDCin
iPartIdINTin
iStateIdINTin
pRectRECT*in
himlHIMAGELISTin
iImageIndexINTin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DrawThemeIcon(
    HTHEME hTheme,
    HDC hdc,
    INT iPartId,
    INT iStateId,
    RECT* pRect,
    HIMAGELIST himl,
    INT iImageIndex
);
[DllImport("UxTheme.dll", ExactSpelling = true)]
static extern int DrawThemeIcon(
    IntPtr hTheme,   // HTHEME
    IntPtr hdc,   // HDC
    int iPartId,   // INT
    int iStateId,   // INT
    IntPtr pRect,   // RECT*
    IntPtr himl,   // HIMAGELIST
    int iImageIndex   // INT
);
<DllImport("UxTheme.dll", ExactSpelling:=True)>
Public Shared Function DrawThemeIcon(
    hTheme As IntPtr,   ' HTHEME
    hdc As IntPtr,   ' HDC
    iPartId As Integer,   ' INT
    iStateId As Integer,   ' INT
    pRect As IntPtr,   ' RECT*
    himl As IntPtr,   ' HIMAGELIST
    iImageIndex As Integer   ' INT
) As Integer
End Function
' hTheme : HTHEME
' hdc : HDC
' iPartId : INT
' iStateId : INT
' pRect : RECT*
' himl : HIMAGELIST
' iImageIndex : INT
Declare PtrSafe Function DrawThemeIcon Lib "uxtheme" ( _
    ByVal hTheme As LongPtr, _
    ByVal hdc As LongPtr, _
    ByVal iPartId As Long, _
    ByVal iStateId As Long, _
    ByVal pRect As LongPtr, _
    ByVal himl As LongPtr, _
    ByVal iImageIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrawThemeIcon = ctypes.windll.uxtheme.DrawThemeIcon
DrawThemeIcon.restype = ctypes.c_int
DrawThemeIcon.argtypes = [
    ctypes.c_ssize_t,  # hTheme : HTHEME
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iPartId : INT
    ctypes.c_int,  # iStateId : INT
    ctypes.c_void_p,  # pRect : RECT*
    ctypes.c_ssize_t,  # himl : HIMAGELIST
    ctypes.c_int,  # iImageIndex : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UxTheme.dll')
DrawThemeIcon = Fiddle::Function.new(
  lib['DrawThemeIcon'],
  [
    Fiddle::TYPE_INTPTR_T,  # hTheme : HTHEME
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # iPartId : INT
    Fiddle::TYPE_INT,  # iStateId : INT
    Fiddle::TYPE_VOIDP,  # pRect : RECT*
    Fiddle::TYPE_INTPTR_T,  # himl : HIMAGELIST
    Fiddle::TYPE_INT,  # iImageIndex : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "uxtheme")]
extern "system" {
    fn DrawThemeIcon(
        hTheme: isize,  // HTHEME
        hdc: *mut core::ffi::c_void,  // HDC
        iPartId: i32,  // INT
        iStateId: i32,  // INT
        pRect: *mut RECT,  // RECT*
        himl: isize,  // HIMAGELIST
        iImageIndex: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UxTheme.dll")]
public static extern int DrawThemeIcon(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, IntPtr pRect, IntPtr himl, int iImageIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UxTheme_DrawThemeIcon' -Namespace Win32 -PassThru
# $api::DrawThemeIcon(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex)
#uselib "UxTheme.dll"
#func global DrawThemeIcon "DrawThemeIcon" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DrawThemeIcon hTheme, hdc, iPartId, iStateId, varptr(pRect), himl, iImageIndex   ; 戻り値は stat
; hTheme : HTHEME -> "sptr"
; hdc : HDC -> "sptr"
; iPartId : INT -> "sptr"
; iStateId : INT -> "sptr"
; pRect : RECT* -> "sptr"
; himl : HIMAGELIST -> "sptr"
; iImageIndex : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UxTheme.dll"
#cfunc global DrawThemeIcon "DrawThemeIcon" sptr, sptr, int, int, var, sptr, int
; res = DrawThemeIcon(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex)
; hTheme : HTHEME -> "sptr"
; hdc : HDC -> "sptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; pRect : RECT* -> "var"
; himl : HIMAGELIST -> "sptr"
; iImageIndex : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DrawThemeIcon(HTHEME hTheme, HDC hdc, INT iPartId, INT iStateId, RECT* pRect, HIMAGELIST himl, INT iImageIndex)
#uselib "UxTheme.dll"
#cfunc global DrawThemeIcon "DrawThemeIcon" intptr, intptr, int, int, var, intptr, int
; res = DrawThemeIcon(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex)
; hTheme : HTHEME -> "intptr"
; hdc : HDC -> "intptr"
; iPartId : INT -> "int"
; iStateId : INT -> "int"
; pRect : RECT* -> "var"
; himl : HIMAGELIST -> "intptr"
; iImageIndex : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uxtheme = windows.NewLazySystemDLL("UxTheme.dll")
	procDrawThemeIcon = uxtheme.NewProc("DrawThemeIcon")
)

// hTheme (HTHEME), hdc (HDC), iPartId (INT), iStateId (INT), pRect (RECT*), himl (HIMAGELIST), iImageIndex (INT)
r1, _, err := procDrawThemeIcon.Call(
	uintptr(hTheme),
	uintptr(hdc),
	uintptr(iPartId),
	uintptr(iStateId),
	uintptr(pRect),
	uintptr(himl),
	uintptr(iImageIndex),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DrawThemeIcon(
  hTheme: NativeInt;   // HTHEME
  hdc: THandle;   // HDC
  iPartId: Integer;   // INT
  iStateId: Integer;   // INT
  pRect: Pointer;   // RECT*
  himl: NativeInt;   // HIMAGELIST
  iImageIndex: Integer   // INT
): Integer; stdcall;
  external 'UxTheme.dll' name 'DrawThemeIcon';
result := DllCall("UxTheme\DrawThemeIcon"
    , "Ptr", hTheme   ; HTHEME
    , "Ptr", hdc   ; HDC
    , "Int", iPartId   ; INT
    , "Int", iStateId   ; INT
    , "Ptr", pRect   ; RECT*
    , "Ptr", himl   ; HIMAGELIST
    , "Int", iImageIndex   ; INT
    , "Int")   ; return: HRESULT
●DrawThemeIcon(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex) = DLL("UxTheme.dll", "int DrawThemeIcon(int, void*, int, int, void*, int, int)")
# 呼び出し: DrawThemeIcon(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex)
# hTheme : HTHEME -> "int"
# hdc : HDC -> "void*"
# iPartId : INT -> "int"
# iStateId : INT -> "int"
# pRect : RECT* -> "void*"
# himl : HIMAGELIST -> "int"
# iImageIndex : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。