#include once "window9.bi"

Sub DisplayPopupMenu(ByVal menu As HMENU, _
					ByVal Xpos As Long, _
					ByVal Ypos As Long, _
					ByVal wnd  As hwnd, _
					ByVal flag As Long) Export
	dim gadget as integer = cast(integer,menu)
	Dim pt As Point
	GetCursorPos(@pt)
	If Xpos=FB_IGNORE Then Xpos=pt.x
	If Ypos=FB_IGNORE Then Ypos=pt.y
	If wnd=1 then
		TrackPopupMenuEx(menu,flag,Xpos,Ypos,GadgetID(gadget),0)
	Else
		TrackPopupMenuEx(menu,flag,Xpos,Ypos, wnd  ,0)
	End If
	PostMessage (win9GetCurrent(), WM_NULL, 0, 0)
End Sub
