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

SetMenuItemBitmaps

関数
メニュー項目に表示するチェック用ビットマップを設定する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetMenuItemBitmaps(
    HMENU hMenu,
    DWORD uPosition,
    MENU_ITEM_FLAGS uFlags,
    HBITMAP hBitmapUnchecked,   // optional
    HBITMAP hBitmapChecked   // optional
);

パラメーター

名前方向
hMenuHMENUin
uPositionDWORDin
uFlagsMENU_ITEM_FLAGSin
hBitmapUncheckedHBITMAPinoptional
hBitmapCheckedHBITMAPinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetMenuItemBitmaps(
    HMENU hMenu,
    DWORD uPosition,
    MENU_ITEM_FLAGS uFlags,
    HBITMAP hBitmapUnchecked,   // optional
    HBITMAP hBitmapChecked   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetMenuItemBitmaps(
    IntPtr hMenu,   // HMENU
    uint uPosition,   // DWORD
    uint uFlags,   // MENU_ITEM_FLAGS
    IntPtr hBitmapUnchecked,   // HBITMAP optional
    IntPtr hBitmapChecked   // HBITMAP optional
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMenuItemBitmaps(
    hMenu As IntPtr,   ' HMENU
    uPosition As UInteger,   ' DWORD
    uFlags As UInteger,   ' MENU_ITEM_FLAGS
    hBitmapUnchecked As IntPtr,   ' HBITMAP optional
    hBitmapChecked As IntPtr   ' HBITMAP optional
) As Boolean
End Function
' hMenu : HMENU
' uPosition : DWORD
' uFlags : MENU_ITEM_FLAGS
' hBitmapUnchecked : HBITMAP optional
' hBitmapChecked : HBITMAP optional
Declare PtrSafe Function SetMenuItemBitmaps Lib "user32" ( _
    ByVal hMenu As LongPtr, _
    ByVal uPosition As Long, _
    ByVal uFlags As Long, _
    ByVal hBitmapUnchecked As LongPtr, _
    ByVal hBitmapChecked As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetMenuItemBitmaps = ctypes.windll.user32.SetMenuItemBitmaps
SetMenuItemBitmaps.restype = wintypes.BOOL
SetMenuItemBitmaps.argtypes = [
    wintypes.HANDLE,  # hMenu : HMENU
    wintypes.DWORD,  # uPosition : DWORD
    wintypes.DWORD,  # uFlags : MENU_ITEM_FLAGS
    wintypes.HANDLE,  # hBitmapUnchecked : HBITMAP optional
    wintypes.HANDLE,  # hBitmapChecked : HBITMAP optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetMenuItemBitmaps = Fiddle::Function.new(
  lib['SetMenuItemBitmaps'],
  [
    Fiddle::TYPE_VOIDP,  # hMenu : HMENU
    -Fiddle::TYPE_INT,  # uPosition : DWORD
    -Fiddle::TYPE_INT,  # uFlags : MENU_ITEM_FLAGS
    Fiddle::TYPE_VOIDP,  # hBitmapUnchecked : HBITMAP optional
    Fiddle::TYPE_VOIDP,  # hBitmapChecked : HBITMAP optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn SetMenuItemBitmaps(
        hMenu: *mut core::ffi::c_void,  // HMENU
        uPosition: u32,  // DWORD
        uFlags: u32,  // MENU_ITEM_FLAGS
        hBitmapUnchecked: *mut core::ffi::c_void,  // HBITMAP optional
        hBitmapChecked: *mut core::ffi::c_void  // HBITMAP optional
    ) -> 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 SetMenuItemBitmaps(IntPtr hMenu, uint uPosition, uint uFlags, IntPtr hBitmapUnchecked, IntPtr hBitmapChecked);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetMenuItemBitmaps' -Namespace Win32 -PassThru
# $api::SetMenuItemBitmaps(hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked)
#uselib "USER32.dll"
#func global SetMenuItemBitmaps "SetMenuItemBitmaps" sptr, sptr, sptr, sptr, sptr
; SetMenuItemBitmaps hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked   ; 戻り値は stat
; hMenu : HMENU -> "sptr"
; uPosition : DWORD -> "sptr"
; uFlags : MENU_ITEM_FLAGS -> "sptr"
; hBitmapUnchecked : HBITMAP optional -> "sptr"
; hBitmapChecked : HBITMAP optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global SetMenuItemBitmaps "SetMenuItemBitmaps" sptr, int, int, sptr, sptr
; res = SetMenuItemBitmaps(hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked)
; hMenu : HMENU -> "sptr"
; uPosition : DWORD -> "int"
; uFlags : MENU_ITEM_FLAGS -> "int"
; hBitmapUnchecked : HBITMAP optional -> "sptr"
; hBitmapChecked : HBITMAP optional -> "sptr"
; BOOL SetMenuItemBitmaps(HMENU hMenu, DWORD uPosition, MENU_ITEM_FLAGS uFlags, HBITMAP hBitmapUnchecked, HBITMAP hBitmapChecked)
#uselib "USER32.dll"
#cfunc global SetMenuItemBitmaps "SetMenuItemBitmaps" intptr, int, int, intptr, intptr
; res = SetMenuItemBitmaps(hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked)
; hMenu : HMENU -> "intptr"
; uPosition : DWORD -> "int"
; uFlags : MENU_ITEM_FLAGS -> "int"
; hBitmapUnchecked : HBITMAP optional -> "intptr"
; hBitmapChecked : HBITMAP optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetMenuItemBitmaps = user32.NewProc("SetMenuItemBitmaps")
)

// hMenu (HMENU), uPosition (DWORD), uFlags (MENU_ITEM_FLAGS), hBitmapUnchecked (HBITMAP optional), hBitmapChecked (HBITMAP optional)
r1, _, err := procSetMenuItemBitmaps.Call(
	uintptr(hMenu),
	uintptr(uPosition),
	uintptr(uFlags),
	uintptr(hBitmapUnchecked),
	uintptr(hBitmapChecked),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetMenuItemBitmaps(
  hMenu: THandle;   // HMENU
  uPosition: DWORD;   // DWORD
  uFlags: DWORD;   // MENU_ITEM_FLAGS
  hBitmapUnchecked: THandle;   // HBITMAP optional
  hBitmapChecked: THandle   // HBITMAP optional
): BOOL; stdcall;
  external 'USER32.dll' name 'SetMenuItemBitmaps';
result := DllCall("USER32\SetMenuItemBitmaps"
    , "Ptr", hMenu   ; HMENU
    , "UInt", uPosition   ; DWORD
    , "UInt", uFlags   ; MENU_ITEM_FLAGS
    , "Ptr", hBitmapUnchecked   ; HBITMAP optional
    , "Ptr", hBitmapChecked   ; HBITMAP optional
    , "Int")   ; return: BOOL
●SetMenuItemBitmaps(hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked) = DLL("USER32.dll", "bool SetMenuItemBitmaps(void*, dword, dword, void*, void*)")
# 呼び出し: SetMenuItemBitmaps(hMenu, uPosition, uFlags, hBitmapUnchecked, hBitmapChecked)
# hMenu : HMENU -> "void*"
# uPosition : DWORD -> "dword"
# uFlags : MENU_ITEM_FLAGS -> "dword"
# hBitmapUnchecked : HBITMAP optional -> "void*"
# hBitmapChecked : HBITMAP optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。