ホーム › UI.WindowsAndMessaging › AppendMenuW
AppendMenuW
関数メニューの末尾に新しい項目を追加する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL AppendMenuW(
HMENU hMenu,
MENU_ITEM_FLAGS uFlags,
UINT_PTR uIDNewItem,
LPCWSTR lpNewItem // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hMenu | HMENU | in |
| uFlags | MENU_ITEM_FLAGS | in |
| uIDNewItem | UINT_PTR | in |
| lpNewItem | LPCWSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL AppendMenuW(
HMENU hMenu,
MENU_ITEM_FLAGS uFlags,
UINT_PTR uIDNewItem,
LPCWSTR lpNewItem // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool AppendMenuW(
IntPtr hMenu, // HMENU
uint uFlags, // MENU_ITEM_FLAGS
UIntPtr uIDNewItem, // UINT_PTR
[MarshalAs(UnmanagedType.LPWStr)] string lpNewItem // LPCWSTR optional
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AppendMenuW(
hMenu As IntPtr, ' HMENU
uFlags As UInteger, ' MENU_ITEM_FLAGS
uIDNewItem As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPWStr)> lpNewItem As String ' LPCWSTR optional
) As Boolean
End Function' hMenu : HMENU
' uFlags : MENU_ITEM_FLAGS
' uIDNewItem : UINT_PTR
' lpNewItem : LPCWSTR optional
Declare PtrSafe Function AppendMenuW Lib "user32" ( _
ByVal hMenu As LongPtr, _
ByVal uFlags As Long, _
ByVal uIDNewItem As LongPtr, _
ByVal lpNewItem 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
AppendMenuW = ctypes.windll.user32.AppendMenuW
AppendMenuW.restype = wintypes.BOOL
AppendMenuW.argtypes = [
wintypes.HANDLE, # hMenu : HMENU
wintypes.DWORD, # uFlags : MENU_ITEM_FLAGS
ctypes.c_size_t, # uIDNewItem : UINT_PTR
wintypes.LPCWSTR, # lpNewItem : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
AppendMenuW = Fiddle::Function.new(
lib['AppendMenuW'],
[
Fiddle::TYPE_VOIDP, # hMenu : HMENU
-Fiddle::TYPE_INT, # uFlags : MENU_ITEM_FLAGS
Fiddle::TYPE_UINTPTR_T, # uIDNewItem : UINT_PTR
Fiddle::TYPE_VOIDP, # lpNewItem : LPCWSTR optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn AppendMenuW(
hMenu: *mut core::ffi::c_void, // HMENU
uFlags: u32, // MENU_ITEM_FLAGS
uIDNewItem: usize, // UINT_PTR
lpNewItem: *const u16 // LPCWSTR optional
) -> 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 AppendMenuW(IntPtr hMenu, uint uFlags, UIntPtr uIDNewItem, [MarshalAs(UnmanagedType.LPWStr)] string lpNewItem);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_AppendMenuW' -Namespace Win32 -PassThru
# $api::AppendMenuW(hMenu, uFlags, uIDNewItem, lpNewItem)#uselib "USER32.dll"
#func global AppendMenuW "AppendMenuW" wptr, wptr, wptr, wptr
; AppendMenuW hMenu, uFlags, uIDNewItem, lpNewItem ; 戻り値は stat
; hMenu : HMENU -> "wptr"
; uFlags : MENU_ITEM_FLAGS -> "wptr"
; uIDNewItem : UINT_PTR -> "wptr"
; lpNewItem : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global AppendMenuW "AppendMenuW" sptr, int, sptr, wstr
; res = AppendMenuW(hMenu, uFlags, uIDNewItem, lpNewItem)
; hMenu : HMENU -> "sptr"
; uFlags : MENU_ITEM_FLAGS -> "int"
; uIDNewItem : UINT_PTR -> "sptr"
; lpNewItem : LPCWSTR optional -> "wstr"; BOOL AppendMenuW(HMENU hMenu, MENU_ITEM_FLAGS uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem)
#uselib "USER32.dll"
#cfunc global AppendMenuW "AppendMenuW" intptr, int, intptr, wstr
; res = AppendMenuW(hMenu, uFlags, uIDNewItem, lpNewItem)
; hMenu : HMENU -> "intptr"
; uFlags : MENU_ITEM_FLAGS -> "int"
; uIDNewItem : UINT_PTR -> "intptr"
; lpNewItem : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procAppendMenuW = user32.NewProc("AppendMenuW")
)
// hMenu (HMENU), uFlags (MENU_ITEM_FLAGS), uIDNewItem (UINT_PTR), lpNewItem (LPCWSTR optional)
r1, _, err := procAppendMenuW.Call(
uintptr(hMenu),
uintptr(uFlags),
uintptr(uIDNewItem),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpNewItem))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction AppendMenuW(
hMenu: THandle; // HMENU
uFlags: DWORD; // MENU_ITEM_FLAGS
uIDNewItem: NativeUInt; // UINT_PTR
lpNewItem: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'USER32.dll' name 'AppendMenuW';result := DllCall("USER32\AppendMenuW"
, "Ptr", hMenu ; HMENU
, "UInt", uFlags ; MENU_ITEM_FLAGS
, "UPtr", uIDNewItem ; UINT_PTR
, "WStr", lpNewItem ; LPCWSTR optional
, "Int") ; return: BOOL●AppendMenuW(hMenu, uFlags, uIDNewItem, lpNewItem) = DLL("USER32.dll", "bool AppendMenuW(void*, dword, int, char*)")
# 呼び出し: AppendMenuW(hMenu, uFlags, uIDNewItem, lpNewItem)
# hMenu : HMENU -> "void*"
# uFlags : MENU_ITEM_FLAGS -> "dword"
# uIDNewItem : UINT_PTR -> "int"
# lpNewItem : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。