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