你好,谢谢你的代码。<br>我试了,但是发现弹出式菜单还是无效,主菜单是可以的。<br><br>我测试的代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Menus, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> PopupMenu1: TPopupMenu;<br> fsafdsafds1: TMenuItem;<br> safdsa1: TMenuItem;<br> fsda1: TMenuItem;<br> fdas1: TMenuItem;<br> f1: TMenuItem;<br> dsa1: TMenuItem;<br> f2: TMenuItem;<br> Memo1: TMemo;<br> MainMenu1: TMainMenu;<br> fdsafdsa1: TMenuItem;<br> fdsafd1: TMenuItem;<br> sdafdsaf1: TMenuItem;<br> sda1: TMenuItem;<br> fsd1: TMenuItem;<br> af1: TMenuItem;<br> dsa2: TMenuItem;<br> procedure Button1Click(Sender: TObject);<br> procedure FormContextPopup(Sender: TObject; MousePos: TPoint;<br> var Handled: Boolean);<br> private<br> { Private declarations }<br> procedure EnterMenuLoop(var Message: TWmEnterMenuLoop); message WM_ENTERMENULOOP;<br> procedure ExitMenuLoop(var Message: TWmExitMenuLoop); message WM_EXITMENULOOP;<br> procedure InitMenuPopup(var Message: TWMInitMenuPopup); message WM_INITMENUPOPUP;<br> procedure UnInitMenuPopup(var Message: TWMInitMenuPopup); message WM_UNINITMENUPOPUP;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> p1,<br> p2: TPoint;<br>begin<br> p1.X := Button1.Left;<br> p1.Y := Button1.Top + Button1.Height;<br> p2 := ClientToScreen(p1);<br> PopupMenu1.Popup(p2.X, p2.Y);<br>end;<br><br>procedure TForm1.EnterMenuLoop(var Message: TWmEnterMenuLoop);<br>begin<br> Memo1.Lines.Add('EnterMenuLoop')<br>end;<br><br>procedure TForm1.ExitMenuLoop(var Message: TWmExitMenuLoop);<br>begin<br> Memo1.Lines.Add('LeaveMenuLoop')<br>end;<br><br>procedure TForm1.FormContextPopup(Sender: TObject; MousePos: TPoint;<br> var Handled: Boolean);<br>begin<br> Handled := True;<br> Memo1.Lines.Add('Popup a menu');<br> PopupMenu1.Popup(MousePos.X, MousePos.Y);<br> Memo1.Lines.Add('Popup menu close');<br>end;<br><br>procedure TForm1.InitMenuPopup(var Message: TWMInitMenuPopup);<br>begin<br> Memo1.Lines.Add('1')<br>end;<br><br>procedure TForm1.UnInitMenuPopup(var Message: TWMInitMenuPopup);<br>begin<br> Memo1.Lines.Add('2')<br>end;<br><br>end.