Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse Enter/Leave messages not working?

I'm trying to detect mouse enter/leave messages CM_MOUSEENTER and CM_MOUSELEAVE but it isn't catching it. What am I doing wrong here?

type
  TMyControl = class(TCustomControl)
  private
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  end;

procedure TMyControl.CMMouseEnter(var Message: TMessage);
begin
  //Handle mouse entering
  //Breakpoint never reached, procedure never called
end;

procedure TMyControl.CMMouseLeave(var Message: TMessage);
begin
  //Handle mouse leaving
  //Breakpoint never reached, procedure never called
end;

procedure TMyControl.WMNCHitTest(var Message: TWMNCHitTest);
var
  Ch: Bool;
begin
  if csDesigning in ComponentState then
    Message.Result := HTCLIENT
  else begin
    Ch:= False;

    //Do checks and pass `Ch:= True;` if something changed...

    if Ch then Invalidate;
  end;
end;
like image 630
Jerry Dodge Avatar asked May 29 '12 07:05

Jerry Dodge


1 Answers

I figured out my issue: I'm also using WM_NCHITTEST, where I was NOT passing inherited;. I added this, and now it works fine.

like image 194
Jerry Dodge Avatar answered Sep 22 '22 10:09

Jerry Dodge