我在一个窗体中弹出菜单
在Form2中用API来显示菜单就可以了。
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim rc As RECT
Dim pt As POINTAPI
pt.x = x / Screen.TwipsPerPixelX
pt.y = y / Screen.TwipsPerPixelX
ClientToScreen Me.hwnd, pt
TrackPopupMenu GetSubMenu(GetMenu(Me.hwnd), 0), 0, pt.x, pt.y, 0, Me.hwnd, rc
End Sub