5

我正在尝试检测鼠标输入/离开消息CM_MOUSEENTERCM_MOUSELEAVE但它没有捕捉到它。我在这里做错了什么?

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;
4

1 回答 1

7

我发现了我的问题:我也在使用WM_NCHITTEST,我没有通过inherited;。我添加了这个,现在它工作正常。

于 2012-05-29T08:06:09.710 回答