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