#include once "window9.bi"

Function DisplayPopupMenu Alias "DisplayPopupMenu" (ByVal menu As HMENU,ByVal Xpos As Integer=MouseX(),ByVal Ypos As Integer=MouseY(), _
                                                    ByVal wnd As Integer=1,ByVal flag As Integer=64) As Integer 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
    Return TrackPopupMenuEx(menu,flag,Xpos,Ypos,GadgetID(gadget),0)
  Else
    Return TrackPopupMenuEx(menu,flag,Xpos,Ypos,Cast(HWND,wnd)  ,0)
  End If
End Function
