'Code By 魑魅魍魉
'mailto:DemonStudio@hotmail.com
Private Declare Function SetMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal hMenu As Long) _
As Long
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) _
As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) _
As Long
Private Declare Function DestroyMenu Lib "user32" _
(ByVal hMenu As Long) _
As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) _
As Long
Private Declare Function WindowFromPoint Lib "user32" _
(ByVal xPoint As Long, _
ByVal yPoint As Long) _
As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim hMenu, mHwnd As Long
Dim Cur As POINTAPI
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
GetCursorPos Cur
mHwnd = WindowFromPoint(Cur.x, Cur.y)
Me.Caption = mHwnd
If mHwnd <> Me.hwnd Then hMenu = GetMenu(mHwnd)
If hMenu <> 0 Then SetMenu Me.hwnd, hMenu
DrawMenuBar Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
DestroyMenu hMenu
End Sub
效果如下: