如何判断一个Popupmenu是否弹出,注意不是mainmenu(100分)

  • 主题发起人 主题发起人 yanlei
  • 开始时间 开始时间
Y

yanlei

Unregistered / Unconfirmed
GUEST, unregistred user!
如何判断一个Popupmenu是否弹出,注意不是mainmenu
 
popupmenu的Onpopup事件。
 
我查过TMenu和TPopupmenu的源代码,好象没有这种属性可以继承或利用。<br>最简单的方法:<br>用一个临时变量IsPopup: Boolean记录PopupMenu的状态。<br>在Onpopup中如下 &nbsp; &nbsp;IsPopup := True;<br>在OnChange中如下 &nbsp; IsPopup := false<br><br>要判断时只需检查Ispopup的值。
 
type <br>TForm1 = class(TForm) <br>&nbsp;{...} <br>procedure FormMouseDown(Sender: TObject; Button: TMouseButton; <br>&nbsp; &nbsp; Shift: TShiftState; X, Y: Integer); <br><br>private <br>&nbsp; IsMenuOpen: Boolean; <br>&nbsp; procedure WMMENUSELECT(var message: TWMMENUSELECT); message WM_MENUSELECT; <br><br>{...} <br>implementation <br><br>{...} <br><br>procedure TForm1.WMMENUSELECT(var message: TWMMENUSELECT); <br>begin <br>&nbsp; inherited; <br>&nbsp; IsMenuOpen := not ((message.MenuFlag and $FFFF &gt; 0) and <br>&nbsp; &nbsp; (message.Menu = 0)); <br>end; <br><br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; <br>&nbsp; Shift: TShiftState; X, Y: Integer); <br>begin <br>&nbsp; if Button = mbRight then <br>&nbsp; &nbsp; with ClientToScreen(Point(X, Y)) do <br>&nbsp; &nbsp; &nbsp; TrackPopupMenuEx(PopupMenu1.Handle, TPM_LEFTALIGN, X, Y, <br>&nbsp; &nbsp; &nbsp; &nbsp; Self.Handle, nil); <br>end; <br>以后判断IsMenuOpen就行了。
 
后退
顶部