ホーム › UI.WindowsAndMessaging › ModifyMenuA
ModifyMenuA
関数既存のメニュー項目を変更する(ANSI版)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
BOOL ModifyMenuA(
HMENU hMnu,
DWORD uPosition,
MENU_ITEM_FLAGS uFlags,
UINT_PTR uIDNewItem,
LPCSTR lpNewItem // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hMnu | HMENU | in |
| uPosition | DWORD | in |
| uFlags | MENU_ITEM_FLAGS | in |
| uIDNewItem | UINT_PTR | in |
| lpNewItem | LPCSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
BOOL ModifyMenuA(
HMENU hMnu,
DWORD uPosition,
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 ModifyMenuA(
IntPtr hMnu, // HMENU
uint uPosition, // DWORD
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 ModifyMenuA(
hMnu As IntPtr, ' HMENU
uPosition As UInteger, ' DWORD
uFlags As UInteger, ' MENU_ITEM_FLAGS
uIDNewItem As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPStr)> lpNewItem As String ' LPCSTR optional
) As Boolean
End Function' hMnu : HMENU
' uPosition : DWORD
' uFlags : MENU_ITEM_FLAGS
' uIDNewItem : UINT_PTR
' lpNewItem : LPCSTR optional
Declare PtrSafe Function ModifyMenuA Lib "user32" ( _
ByVal hMnu As LongPtr, _
ByVal uPosition As Long, _
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
ModifyMenuA = ctypes.windll.user32.ModifyMenuA
ModifyMenuA.restype = wintypes.BOOL
ModifyMenuA.argtypes = [
wintypes.HANDLE, # hMnu : HMENU
wintypes.DWORD, # uPosition : DWORD
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')
ModifyMenuA = Fiddle::Function.new(
lib['ModifyMenuA'],
[
Fiddle::TYPE_VOIDP, # hMnu : HMENU
-Fiddle::TYPE_INT, # uPosition : DWORD
-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 ModifyMenuA(
hMnu: *mut core::ffi::c_void, // HMENU
uPosition: u32, // DWORD
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 ModifyMenuA(IntPtr hMnu, uint uPosition, uint uFlags, UIntPtr uIDNewItem, [MarshalAs(UnmanagedType.LPStr)] string lpNewItem);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ModifyMenuA' -Namespace Win32 -PassThru
# $api::ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem)#uselib "USER32.dll"
#func global ModifyMenuA "ModifyMenuA" sptr, sptr, sptr, sptr, sptr
; ModifyMenuA hMnu, uPosition, uFlags, uIDNewItem, lpNewItem ; 戻り値は stat
; hMnu : HMENU -> "sptr"
; uPosition : DWORD -> "sptr"
; uFlags : MENU_ITEM_FLAGS -> "sptr"
; uIDNewItem : UINT_PTR -> "sptr"
; lpNewItem : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global ModifyMenuA "ModifyMenuA" sptr, int, int, sptr, str
; res = ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem)
; hMnu : HMENU -> "sptr"
; uPosition : DWORD -> "int"
; uFlags : MENU_ITEM_FLAGS -> "int"
; uIDNewItem : UINT_PTR -> "sptr"
; lpNewItem : LPCSTR optional -> "str"; BOOL ModifyMenuA(HMENU hMnu, DWORD uPosition, MENU_ITEM_FLAGS uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem)
#uselib "USER32.dll"
#cfunc global ModifyMenuA "ModifyMenuA" intptr, int, int, intptr, str
; res = ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem)
; hMnu : HMENU -> "intptr"
; uPosition : DWORD -> "int"
; 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")
procModifyMenuA = user32.NewProc("ModifyMenuA")
)
// hMnu (HMENU), uPosition (DWORD), uFlags (MENU_ITEM_FLAGS), uIDNewItem (UINT_PTR), lpNewItem (LPCSTR optional)
r1, _, err := procModifyMenuA.Call(
uintptr(hMnu),
uintptr(uPosition),
uintptr(uFlags),
uintptr(uIDNewItem),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpNewItem))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ModifyMenuA(
hMnu: THandle; // HMENU
uPosition: DWORD; // DWORD
uFlags: DWORD; // MENU_ITEM_FLAGS
uIDNewItem: NativeUInt; // UINT_PTR
lpNewItem: PAnsiChar // LPCSTR optional
): BOOL; stdcall;
external 'USER32.dll' name 'ModifyMenuA';result := DllCall("USER32\ModifyMenuA"
, "Ptr", hMnu ; HMENU
, "UInt", uPosition ; DWORD
, "UInt", uFlags ; MENU_ITEM_FLAGS
, "UPtr", uIDNewItem ; UINT_PTR
, "AStr", lpNewItem ; LPCSTR optional
, "Int") ; return: BOOL●ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem) = DLL("USER32.dll", "bool ModifyMenuA(void*, dword, dword, int, char*)")
# 呼び出し: ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem)
# hMnu : HMENU -> "void*"
# uPosition : DWORD -> "dword"
# uFlags : MENU_ITEM_FLAGS -> "dword"
# uIDNewItem : UINT_PTR -> "int"
# lpNewItem : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。