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