ホーム › UI.WindowsAndMessaging › GetMenuItemID
GetMenuItemID
関数指定位置のメニュー項目の識別子を取得する。
シグネチャ
// USER32.dll
#include <windows.h>
DWORD GetMenuItemID(
HMENU hMenu,
INT nPos
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hMenu | HMENU | in | 識別子を取得する項目を含むメニューへのハンドル。 |
| nPos | INT | in | 識別子を取得するメニュー項目の、0 から始まる相対位置。 |
戻り値の型: DWORD
公式ドキュメント
メニュー内の指定された位置にあるメニュー項目のメニュー項目識別子を取得します。
戻り値
型: UINT
戻り値は、指定したメニュー項目の識別子です。メニュー項目識別子が NULL の場合、または指定した項目がサブメニューを開く場合、戻り値は -1 になります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
DWORD GetMenuItemID(
HMENU hMenu,
INT nPos
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern uint GetMenuItemID(
IntPtr hMenu, // HMENU
int nPos // INT
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetMenuItemID(
hMenu As IntPtr, ' HMENU
nPos As Integer ' INT
) As UInteger
End Function' hMenu : HMENU
' nPos : INT
Declare PtrSafe Function GetMenuItemID Lib "user32" ( _
ByVal hMenu As LongPtr, _
ByVal nPos As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetMenuItemID = ctypes.windll.user32.GetMenuItemID
GetMenuItemID.restype = wintypes.DWORD
GetMenuItemID.argtypes = [
wintypes.HANDLE, # hMenu : HMENU
ctypes.c_int, # nPos : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetMenuItemID = Fiddle::Function.new(
lib['GetMenuItemID'],
[
Fiddle::TYPE_VOIDP, # hMenu : HMENU
Fiddle::TYPE_INT, # nPos : INT
],
-Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn GetMenuItemID(
hMenu: *mut core::ffi::c_void, // HMENU
nPos: i32 // INT
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern uint GetMenuItemID(IntPtr hMenu, int nPos);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMenuItemID' -Namespace Win32 -PassThru
# $api::GetMenuItemID(hMenu, nPos)#uselib "USER32.dll"
#func global GetMenuItemID "GetMenuItemID" sptr, sptr
; GetMenuItemID hMenu, nPos ; 戻り値は stat
; hMenu : HMENU -> "sptr"
; nPos : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global GetMenuItemID "GetMenuItemID" sptr, int
; res = GetMenuItemID(hMenu, nPos)
; hMenu : HMENU -> "sptr"
; nPos : INT -> "int"; DWORD GetMenuItemID(HMENU hMenu, INT nPos)
#uselib "USER32.dll"
#cfunc global GetMenuItemID "GetMenuItemID" intptr, int
; res = GetMenuItemID(hMenu, nPos)
; hMenu : HMENU -> "intptr"
; nPos : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetMenuItemID = user32.NewProc("GetMenuItemID")
)
// hMenu (HMENU), nPos (INT)
r1, _, err := procGetMenuItemID.Call(
uintptr(hMenu),
uintptr(nPos),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetMenuItemID(
hMenu: THandle; // HMENU
nPos: Integer // INT
): DWORD; stdcall;
external 'USER32.dll' name 'GetMenuItemID';result := DllCall("USER32\GetMenuItemID"
, "Ptr", hMenu ; HMENU
, "Int", nPos ; INT
, "UInt") ; return: DWORD●GetMenuItemID(hMenu, nPos) = DLL("USER32.dll", "dword GetMenuItemID(void*, int)")
# 呼び出し: GetMenuItemID(hMenu, nPos)
# hMenu : HMENU -> "void*"
# nPos : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn GetMenuItemID(
hMenu: ?*anyopaque, // HMENU
nPos: i32 // INT
) callconv(std.os.windows.WINAPI) u32;proc GetMenuItemID(
hMenu: pointer, # HMENU
nPos: int32 # INT
): uint32 {.importc: "GetMenuItemID", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
uint GetMenuItemID(
void* hMenu, // HMENU
int nPos // INT
);ccall((:GetMenuItemID, "USER32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Int32),
hMenu, nPos)
# hMenu : HMENU -> Ptr{Cvoid}
# nPos : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetMenuItemID(
void* hMenu,
int32_t nPos);
]]
local user32 = ffi.load("user32")
-- user32.GetMenuItemID(hMenu, nPos)
-- hMenu : HMENU
-- nPos : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetMenuItemID = lib.func('__stdcall', 'GetMenuItemID', 'uint32_t', ['void *', 'int32_t']);
// GetMenuItemID(hMenu, nPos)
// hMenu : HMENU -> 'void *'
// nPos : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
GetMenuItemID: { parameters: ["pointer", "i32"], result: "u32" },
});
// lib.symbols.GetMenuItemID(hMenu, nPos)
// hMenu : HMENU -> "pointer"
// nPos : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetMenuItemID(
void* hMenu,
int32_t nPos);
C, "USER32.dll");
// $ffi->GetMenuItemID(hMenu, nPos);
// hMenu : HMENU
// nPos : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
int GetMenuItemID(
Pointer hMenu, // HMENU
int nPos // INT
);
}@[Link("user32")]
lib LibUSER32
fun GetMenuItemID = GetMenuItemID(
hMenu : Void*, # HMENU
nPos : Int32 # INT
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetMenuItemIDNative = Uint32 Function(Pointer<Void>, Int32);
typedef GetMenuItemIDDart = int Function(Pointer<Void>, int);
final GetMenuItemID = DynamicLibrary.open('USER32.dll')
.lookupFunction<GetMenuItemIDNative, GetMenuItemIDDart>('GetMenuItemID');
// hMenu : HMENU -> Pointer<Void>
// nPos : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetMenuItemID(
hMenu: THandle; // HMENU
nPos: Integer // INT
): DWORD; stdcall;
external 'USER32.dll' name 'GetMenuItemID';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetMenuItemID"
c_GetMenuItemID :: Ptr () -> Int32 -> IO Word32
-- hMenu : HMENU -> Ptr ()
-- nPos : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getmenuitemid =
foreign "GetMenuItemID"
((ptr void) @-> int32_t @-> returning uint32_t)
(* hMenu : HMENU -> (ptr void) *)
(* nPos : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("GetMenuItemID" get-menu-item-id :convention :stdcall) :uint32
(h-menu :pointer) ; HMENU
(n-pos :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetMenuItemID = Win32::API::More->new('USER32',
'DWORD GetMenuItemID(HANDLE hMenu, int nPos)');
# my $ret = $GetMenuItemID->Call($hMenu, $nPos);
# hMenu : HMENU -> HANDLE
# nPos : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetMenuItemCount — メニュー内の項目数を取得する。