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