ホーム › UI.WindowsAndMessaging › GetMenuItemRect
GetMenuItemRect
関数メニュー項目の画面上の矩形領域を取得する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL GetMenuItemRect(
HWND hWnd, // optional
HMENU hMenu,
DWORD uItem,
RECT* lprcItem
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | inoptional | メニューを含むウィンドウのハンドル。 |
| hMenu | HMENU | in | 対象メニューのハンドル。 |
| uItem | DWORD | in | 矩形を取得する項目の位置(0始まり)。 |
| lprcItem | RECT* | out | 項目の境界矩形(スクリーン座標)を受け取るRECT構造体へのポインター。 |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL GetMenuItemRect(
HWND hWnd, // optional
HMENU hMenu,
DWORD uItem,
RECT* lprcItem
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetMenuItemRect(
IntPtr hWnd, // HWND optional
IntPtr hMenu, // HMENU
uint uItem, // DWORD
IntPtr lprcItem // RECT* out
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetMenuItemRect(
hWnd As IntPtr, ' HWND optional
hMenu As IntPtr, ' HMENU
uItem As UInteger, ' DWORD
lprcItem As IntPtr ' RECT* out
) As Boolean
End Function' hWnd : HWND optional
' hMenu : HMENU
' uItem : DWORD
' lprcItem : RECT* out
Declare PtrSafe Function GetMenuItemRect Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal hMenu As LongPtr, _
ByVal uItem As Long, _
ByVal lprcItem As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetMenuItemRect = ctypes.windll.user32.GetMenuItemRect
GetMenuItemRect.restype = wintypes.BOOL
GetMenuItemRect.argtypes = [
wintypes.HANDLE, # hWnd : HWND optional
wintypes.HANDLE, # hMenu : HMENU
wintypes.DWORD, # uItem : DWORD
ctypes.c_void_p, # lprcItem : RECT* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetMenuItemRect = Fiddle::Function.new(
lib['GetMenuItemRect'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND optional
Fiddle::TYPE_VOIDP, # hMenu : HMENU
-Fiddle::TYPE_INT, # uItem : DWORD
Fiddle::TYPE_VOIDP, # lprcItem : RECT* out
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn GetMenuItemRect(
hWnd: *mut core::ffi::c_void, // HWND optional
hMenu: *mut core::ffi::c_void, // HMENU
uItem: u32, // DWORD
lprcItem: *mut RECT // RECT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, uint uItem, IntPtr lprcItem);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMenuItemRect' -Namespace Win32 -PassThru
# $api::GetMenuItemRect(hWnd, hMenu, uItem, lprcItem)#uselib "USER32.dll"
#func global GetMenuItemRect "GetMenuItemRect" sptr, sptr, sptr, sptr
; GetMenuItemRect hWnd, hMenu, uItem, varptr(lprcItem) ; 戻り値は stat
; hWnd : HWND optional -> "sptr"
; hMenu : HMENU -> "sptr"
; uItem : DWORD -> "sptr"
; lprcItem : RECT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global GetMenuItemRect "GetMenuItemRect" sptr, sptr, int, var ; res = GetMenuItemRect(hWnd, hMenu, uItem, lprcItem) ; hWnd : HWND optional -> "sptr" ; hMenu : HMENU -> "sptr" ; uItem : DWORD -> "int" ; lprcItem : RECT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global GetMenuItemRect "GetMenuItemRect" sptr, sptr, int, sptr ; res = GetMenuItemRect(hWnd, hMenu, uItem, varptr(lprcItem)) ; hWnd : HWND optional -> "sptr" ; hMenu : HMENU -> "sptr" ; uItem : DWORD -> "int" ; lprcItem : RECT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetMenuItemRect(HWND hWnd, HMENU hMenu, DWORD uItem, RECT* lprcItem) #uselib "USER32.dll" #cfunc global GetMenuItemRect "GetMenuItemRect" intptr, intptr, int, var ; res = GetMenuItemRect(hWnd, hMenu, uItem, lprcItem) ; hWnd : HWND optional -> "intptr" ; hMenu : HMENU -> "intptr" ; uItem : DWORD -> "int" ; lprcItem : RECT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetMenuItemRect(HWND hWnd, HMENU hMenu, DWORD uItem, RECT* lprcItem) #uselib "USER32.dll" #cfunc global GetMenuItemRect "GetMenuItemRect" intptr, intptr, int, intptr ; res = GetMenuItemRect(hWnd, hMenu, uItem, varptr(lprcItem)) ; hWnd : HWND optional -> "intptr" ; hMenu : HMENU -> "intptr" ; uItem : DWORD -> "int" ; lprcItem : RECT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetMenuItemRect = user32.NewProc("GetMenuItemRect")
)
// hWnd (HWND optional), hMenu (HMENU), uItem (DWORD), lprcItem (RECT* out)
r1, _, err := procGetMenuItemRect.Call(
uintptr(hWnd),
uintptr(hMenu),
uintptr(uItem),
uintptr(lprcItem),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetMenuItemRect(
hWnd: THandle; // HWND optional
hMenu: THandle; // HMENU
uItem: DWORD; // DWORD
lprcItem: Pointer // RECT* out
): BOOL; stdcall;
external 'USER32.dll' name 'GetMenuItemRect';result := DllCall("USER32\GetMenuItemRect"
, "Ptr", hWnd ; HWND optional
, "Ptr", hMenu ; HMENU
, "UInt", uItem ; DWORD
, "Ptr", lprcItem ; RECT* out
, "Int") ; return: BOOL●GetMenuItemRect(hWnd, hMenu, uItem, lprcItem) = DLL("USER32.dll", "bool GetMenuItemRect(void*, void*, dword, void*)")
# 呼び出し: GetMenuItemRect(hWnd, hMenu, uItem, lprcItem)
# hWnd : HWND optional -> "void*"
# hMenu : HMENU -> "void*"
# uItem : DWORD -> "dword"
# lprcItem : RECT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。