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

SetMenuItemInfoW

関数
メニュー項目の詳細情報を設定する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetMenuItemInfoW(
    HMENU hmenu,
    DWORD item,
    BOOL fByPositon,
    MENUITEMINFOW* lpmii
);

パラメーター

名前方向
hmenuHMENUin
itemDWORDin
fByPositonBOOLin
lpmiiMENUITEMINFOW*in

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetMenuItemInfoW(
    HMENU hmenu,
    DWORD item,
    BOOL fByPositon,
    MENUITEMINFOW* lpmii
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetMenuItemInfoW(
    IntPtr hmenu,   // HMENU
    uint item,   // DWORD
    bool fByPositon,   // BOOL
    IntPtr lpmii   // MENUITEMINFOW*
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMenuItemInfoW(
    hmenu As IntPtr,   ' HMENU
    item As UInteger,   ' DWORD
    fByPositon As Boolean,   ' BOOL
    lpmii As IntPtr   ' MENUITEMINFOW*
) As Boolean
End Function
' hmenu : HMENU
' item : DWORD
' fByPositon : BOOL
' lpmii : MENUITEMINFOW*
Declare PtrSafe Function SetMenuItemInfoW Lib "user32" ( _
    ByVal hmenu As LongPtr, _
    ByVal item As Long, _
    ByVal fByPositon As Long, _
    ByVal lpmii As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetMenuItemInfoW = ctypes.windll.user32.SetMenuItemInfoW
SetMenuItemInfoW.restype = wintypes.BOOL
SetMenuItemInfoW.argtypes = [
    wintypes.HANDLE,  # hmenu : HMENU
    wintypes.DWORD,  # item : DWORD
    wintypes.BOOL,  # fByPositon : BOOL
    ctypes.c_void_p,  # lpmii : MENUITEMINFOW*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetMenuItemInfoW = Fiddle::Function.new(
  lib['SetMenuItemInfoW'],
  [
    Fiddle::TYPE_VOIDP,  # hmenu : HMENU
    -Fiddle::TYPE_INT,  # item : DWORD
    Fiddle::TYPE_INT,  # fByPositon : BOOL
    Fiddle::TYPE_VOIDP,  # lpmii : MENUITEMINFOW*
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn SetMenuItemInfoW(
        hmenu: *mut core::ffi::c_void,  // HMENU
        item: u32,  // DWORD
        fByPositon: i32,  // BOOL
        lpmii: *mut MENUITEMINFOW  // MENUITEMINFOW*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetMenuItemInfoW(IntPtr hmenu, uint item, bool fByPositon, IntPtr lpmii);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetMenuItemInfoW' -Namespace Win32 -PassThru
# $api::SetMenuItemInfoW(hmenu, item, fByPositon, lpmii)
#uselib "USER32.dll"
#func global SetMenuItemInfoW "SetMenuItemInfoW" wptr, wptr, wptr, wptr
; SetMenuItemInfoW hmenu, item, fByPositon, varptr(lpmii)   ; 戻り値は stat
; hmenu : HMENU -> "wptr"
; item : DWORD -> "wptr"
; fByPositon : BOOL -> "wptr"
; lpmii : MENUITEMINFOW* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global SetMenuItemInfoW "SetMenuItemInfoW" sptr, int, int, var
; res = SetMenuItemInfoW(hmenu, item, fByPositon, lpmii)
; hmenu : HMENU -> "sptr"
; item : DWORD -> "int"
; fByPositon : BOOL -> "int"
; lpmii : MENUITEMINFOW* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetMenuItemInfoW(HMENU hmenu, DWORD item, BOOL fByPositon, MENUITEMINFOW* lpmii)
#uselib "USER32.dll"
#cfunc global SetMenuItemInfoW "SetMenuItemInfoW" intptr, int, int, var
; res = SetMenuItemInfoW(hmenu, item, fByPositon, lpmii)
; hmenu : HMENU -> "intptr"
; item : DWORD -> "int"
; fByPositon : BOOL -> "int"
; lpmii : MENUITEMINFOW* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetMenuItemInfoW = user32.NewProc("SetMenuItemInfoW")
)

// hmenu (HMENU), item (DWORD), fByPositon (BOOL), lpmii (MENUITEMINFOW*)
r1, _, err := procSetMenuItemInfoW.Call(
	uintptr(hmenu),
	uintptr(item),
	uintptr(fByPositon),
	uintptr(lpmii),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetMenuItemInfoW(
  hmenu: THandle;   // HMENU
  item: DWORD;   // DWORD
  fByPositon: BOOL;   // BOOL
  lpmii: Pointer   // MENUITEMINFOW*
): BOOL; stdcall;
  external 'USER32.dll' name 'SetMenuItemInfoW';
result := DllCall("USER32\SetMenuItemInfoW"
    , "Ptr", hmenu   ; HMENU
    , "UInt", item   ; DWORD
    , "Int", fByPositon   ; BOOL
    , "Ptr", lpmii   ; MENUITEMINFOW*
    , "Int")   ; return: BOOL
●SetMenuItemInfoW(hmenu, item, fByPositon, lpmii) = DLL("USER32.dll", "bool SetMenuItemInfoW(void*, dword, bool, void*)")
# 呼び出し: SetMenuItemInfoW(hmenu, item, fByPositon, lpmii)
# hmenu : HMENU -> "void*"
# item : DWORD -> "dword"
# fByPositon : BOOL -> "bool"
# lpmii : MENUITEMINFOW* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。