ホーム › UI.WindowsAndMessaging › InsertMenuItemW
InsertMenuItemW
関数情報構造体を用いてメニュー項目を挿入する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL InsertMenuItemW(
HMENU hmenu,
DWORD item,
BOOL fByPosition,
MENUITEMINFOW* lpmi
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hmenu | HMENU | in |
| item | DWORD | in |
| fByPosition | BOOL | in |
| lpmi | MENUITEMINFOW* | in |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL InsertMenuItemW(
HMENU hmenu,
DWORD item,
BOOL fByPosition,
MENUITEMINFOW* lpmi
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool InsertMenuItemW(
IntPtr hmenu, // HMENU
uint item, // DWORD
bool fByPosition, // BOOL
IntPtr lpmi // MENUITEMINFOW*
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InsertMenuItemW(
hmenu As IntPtr, ' HMENU
item As UInteger, ' DWORD
fByPosition As Boolean, ' BOOL
lpmi As IntPtr ' MENUITEMINFOW*
) As Boolean
End Function' hmenu : HMENU
' item : DWORD
' fByPosition : BOOL
' lpmi : MENUITEMINFOW*
Declare PtrSafe Function InsertMenuItemW Lib "user32" ( _
ByVal hmenu As LongPtr, _
ByVal item As Long, _
ByVal fByPosition As Long, _
ByVal lpmi 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
InsertMenuItemW = ctypes.windll.user32.InsertMenuItemW
InsertMenuItemW.restype = wintypes.BOOL
InsertMenuItemW.argtypes = [
wintypes.HANDLE, # hmenu : HMENU
wintypes.DWORD, # item : DWORD
wintypes.BOOL, # fByPosition : BOOL
ctypes.c_void_p, # lpmi : MENUITEMINFOW*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
InsertMenuItemW = Fiddle::Function.new(
lib['InsertMenuItemW'],
[
Fiddle::TYPE_VOIDP, # hmenu : HMENU
-Fiddle::TYPE_INT, # item : DWORD
Fiddle::TYPE_INT, # fByPosition : BOOL
Fiddle::TYPE_VOIDP, # lpmi : MENUITEMINFOW*
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn InsertMenuItemW(
hmenu: *mut core::ffi::c_void, // HMENU
item: u32, // DWORD
fByPosition: i32, // BOOL
lpmi: *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 InsertMenuItemW(IntPtr hmenu, uint item, bool fByPosition, IntPtr lpmi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_InsertMenuItemW' -Namespace Win32 -PassThru
# $api::InsertMenuItemW(hmenu, item, fByPosition, lpmi)#uselib "USER32.dll"
#func global InsertMenuItemW "InsertMenuItemW" wptr, wptr, wptr, wptr
; InsertMenuItemW hmenu, item, fByPosition, varptr(lpmi) ; 戻り値は stat
; hmenu : HMENU -> "wptr"
; item : DWORD -> "wptr"
; fByPosition : BOOL -> "wptr"
; lpmi : MENUITEMINFOW* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global InsertMenuItemW "InsertMenuItemW" sptr, int, int, var ; res = InsertMenuItemW(hmenu, item, fByPosition, lpmi) ; hmenu : HMENU -> "sptr" ; item : DWORD -> "int" ; fByPosition : BOOL -> "int" ; lpmi : MENUITEMINFOW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global InsertMenuItemW "InsertMenuItemW" sptr, int, int, sptr ; res = InsertMenuItemW(hmenu, item, fByPosition, varptr(lpmi)) ; hmenu : HMENU -> "sptr" ; item : DWORD -> "int" ; fByPosition : BOOL -> "int" ; lpmi : MENUITEMINFOW* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL InsertMenuItemW(HMENU hmenu, DWORD item, BOOL fByPosition, MENUITEMINFOW* lpmi) #uselib "USER32.dll" #cfunc global InsertMenuItemW "InsertMenuItemW" intptr, int, int, var ; res = InsertMenuItemW(hmenu, item, fByPosition, lpmi) ; hmenu : HMENU -> "intptr" ; item : DWORD -> "int" ; fByPosition : BOOL -> "int" ; lpmi : MENUITEMINFOW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL InsertMenuItemW(HMENU hmenu, DWORD item, BOOL fByPosition, MENUITEMINFOW* lpmi) #uselib "USER32.dll" #cfunc global InsertMenuItemW "InsertMenuItemW" intptr, int, int, intptr ; res = InsertMenuItemW(hmenu, item, fByPosition, varptr(lpmi)) ; hmenu : HMENU -> "intptr" ; item : DWORD -> "int" ; fByPosition : BOOL -> "int" ; lpmi : MENUITEMINFOW* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procInsertMenuItemW = user32.NewProc("InsertMenuItemW")
)
// hmenu (HMENU), item (DWORD), fByPosition (BOOL), lpmi (MENUITEMINFOW*)
r1, _, err := procInsertMenuItemW.Call(
uintptr(hmenu),
uintptr(item),
uintptr(fByPosition),
uintptr(lpmi),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction InsertMenuItemW(
hmenu: THandle; // HMENU
item: DWORD; // DWORD
fByPosition: BOOL; // BOOL
lpmi: Pointer // MENUITEMINFOW*
): BOOL; stdcall;
external 'USER32.dll' name 'InsertMenuItemW';result := DllCall("USER32\InsertMenuItemW"
, "Ptr", hmenu ; HMENU
, "UInt", item ; DWORD
, "Int", fByPosition ; BOOL
, "Ptr", lpmi ; MENUITEMINFOW*
, "Int") ; return: BOOL●InsertMenuItemW(hmenu, item, fByPosition, lpmi) = DLL("USER32.dll", "bool InsertMenuItemW(void*, dword, bool, void*)")
# 呼び出し: InsertMenuItemW(hmenu, item, fByPosition, lpmi)
# hmenu : HMENU -> "void*"
# item : DWORD -> "dword"
# fByPosition : BOOL -> "bool"
# lpmi : MENUITEMINFOW* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。