哦,D5的作法与D4完全不同,简单多了。PopupList是全局变量呀。<br><br>先将Menus.pas的TrackPopupMenu那句改了,去掉Buttons[FTrackButton]<br><br>在FORM上加一PopupMenu1,随便填几个MenuItem。<br> private<br> DefMenuProc: TFarProc;<br> procedure MenuWndProc(var msg: Tmessage);<br> { Private declarations }<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> DefMenuProc:=Pointer(GetWindowLong(PopupList.Window,GWL_WNDPROC));<br> SetWindowLong(PopupList.Window,GWL_WNDPROC,LongInt(MakeObjectInstance(MenuWndProc)));<br>end;<br><br>var Item:Integer;<br><br>procedure TForm1.MenuWndProc(var msg:Tmessage);<br>var pop:HMENU; p:TPoint; s:array[0..255]of Char;<br>begin<br>case msg.Msg of<br> WM_MENURBUTTONUP: begin<br> GetCursorPos(p);<br> pop:=CreatePopupMenu;<br> GetMenuString(PopupMenu1.Handle,Item,s,255,MF_BYCOMMAND);<br> AppendMenu(pop,0,100,PChar('Popup From '+String(s)));<br> TrackPopupMenu(pop,1,p.x,p.y,0,PopupList.Window,nil);<br> DestroyMenu(pop);<br> end;<br> WM_MENUSELECT: Item:=LOWORD(msg.wParam);<br> WM_COMMAND: if LOWORD(msg.wParam)=100 then MessageBox(Handle,'','OK!',0);<br>end;<br>with msg do Result:=CallWindowProc(DefMenuProc,PopupList.Window,Msg,WParam,LParam);<br>end;<br><br><br><br>