The difference between PopupMenuItem Click and MouseOver

跟風遠走 提交于 2020-02-28 07:52:07

问题


When a Menu Item has a sub Menu hovering the mouse expands the sub-menu it fires a click event.

Is there any difference between this click event and if the user actually clicks?

I'm using a TPopupMenu as dropdown property of a cxButton.

EDIT Delphi 2007


回答1:


Not sure this will work with D2007; it does in D7. Can you try the following?

type
  THackPopupList = class(TPopupList)
  private
    FActuallyClicked: Boolean;
  protected
    procedure WndProc(var Message: TMessage); override;
  public
    property ActuallyClicked: Boolean read FActuallyClicked;
  end;

{ THackPopupList }

procedure THackPopupList.WndProc(var Message: TMessage);
begin
  FActuallyClicked := Message.Msg = WM_COMMAND;
  inherited WndProc(Message);
end;

{ TForm1 }

procedure TForm1.MenuFileOpenClick(Sender: TObject);
var 
  ActuallyClicked: Boolean;
begin
  ActuallyClicked := THackPopupList(PopupList).ActuallyClicked;
  ...
end;

initialization
  PopupList.Free;
  PopupList := THackPopupList.Create;

end.

Explanation: The OnClick which is triggered by a hover is initiated by a WM_INITMENUPOPUP, but the OnClick which is triggered by a mouse click is initiated by this WM_COMMAND.

This depends on Menus.pas already having been initialized. But as I understand from Delphi unit initialization order, that is guaranteed even if you put this code in an auxiliary unit.




回答2:


Well, if the user actually clicks a MenuItem with sub menu items, the OnClick event is not fired. So the distinction is made by:

procedure TForm1.MenuFileOpenClick(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;

And if the menu item has a linked action:

procedure TForm1.FileOpenExecute(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  if Sender is TBasicAction then
    Sender := TBasicAction(Sender).ActionComponent;
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;



回答3:


No there isn't. If the user clicks the item or hover it, the same OnClick event is fired.
I've checked this for Delphi 2009.



来源:https://stackoverflow.com/questions/6328497/the-difference-between-popupmenuitem-click-and-mouseover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!