MenuItems with Enter/Leave

Please discuss general Delphi programming topics here.

MenuItems with Enter/Leave

Postby HPW » September 24th, 2007, 2:48 pm

I tried to made an enhanced TMenuItem with Enter/Leave:

Code: Select all
unit MenuItemEx;

interface

uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,
Dialogs,ExtCtrls, menus;

type
  TMenuItemEx=class (TMenuItem)
  private
  { Private declarations }
  FOnMouseLeave:TNotifyEvent;
  FOnMouseEnter:TNotifyEvent;
  procedure CM_MouseEnter( var msg:TMessage);  message CM_MOUSEENTER;
  procedure CM_MouseLeave( var msg:TMessage);  message CM_MOUSELEAVE;
  protected
  { Protected declarations }
  procedure DoMouseEnter;dynamic;
  procedure DoMouseLeave;dynamic;
  public
  { Public declarations }
  published
  { Published declarations }
  property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents( 'Samples',[TMenuItemEx]);
end;

procedure TMenuItemEx.CM_MouseEnter( var msg:TMessage);
begin
  DoMouseEnter;
end;

procedure TMenuItemEx.CM_MouseLeave( var msg:TMessage);
begin
  DoMouseLeave;
end;

procedure TMenuItemEx.DoMouseEnter;
begin
  if Assigned( FOnMouseEnter) then FOnMouseEnter( Self);
end;

procedure TMenuItemEx.DoMouseLeave;
begin
  if Assigned( FOnMouseLeave) then FOnMouseLeave( Self);
end;

end.


But the events don not fire.

Any ideas?
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby Kambiz » September 24th, 2007, 5:14 pm

It is because TMenuItem is not a TControl descendant.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby HPW » September 24th, 2007, 7:02 pm

So it was the wrong idea.

WM_MENUSELECT seems to be better.

Here I found a interesting solution:
http://delphi.about.com/od/vclusing/a/menuitemhints.htm
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 27 guests

cron