开发者

The difference between PopupMenuItem Click and MouseOver

开发者 https://www.devze.com 2023-03-12 05:38 出处:网络
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 click开发者_StackOverflow中文

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 click开发者_StackOverflow中文版s?

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

EDIT Delphi 2007


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.


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;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号