0
votes

I need to disable both mouse buttons on the event OnMouseEnter of a TRichEdit component and enable again on the event OnMouseLeave.

Setting the TRichEdit enabled = false does not solve my problem.

Any tips ?

1
Well, disabling the rich edit won't disable mouse buttons. Or is that perhaps not the real problem. - David Heffernan
May I ask why? This seems highly counter to the way Windows applications work. What is the objective (goal) of doing this? There may be a better way. - Ken White
I don't understand why people are voting to close as "unclear what you're asking" it's very clear to me what's being asked, what's not clear is why. - Jerry Dodge
I have a form splitted in half. On the first half is a pannel created at runtime with user defined fields of different DataTypes. The other half is the TrichEdit that contains the text created using the fileds that the user filled on the pannel. The procedure that updates the richedit is activated on the fields onExit Event. If a field is focused and the user clicks directally on the TRichedit, raises an exception on the lineupdate event. The tip from Sertac Akyuz worked beautifully. Thanx to all !! - Leo Bruno
If you are getting an exception then you are probably doing something wrong in the first place, and then trying to solve the symptom rather than the cause. Please show your actual code and explain your goal, there is probably a better design to accomplish it. - Remy Lebeau

1 Answers

4
votes

You can subclass your rich edit so that to intercept mouse button down/up messages. Then you don't need to watch for the mouse entering, leaving the control. Example:

type
  TForm1 = class(TForm)
    ...
  private
    FSaveRichEditProc: TWndMethod;
    procedure RichEditWindowProc(var Message: TMessage);
    ..
  end;

  ...

procedure TForm1.FormCreate(Sender: TObject);
begin
  FSaveRichEditProc := RichEdit1.WindowProc;
  RichEdit1.WindowProc := RichEditWindowProc;
end;

procedure TForm1.RichEditWindowProc(var Message: TMessage);
begin
  case Message.Msg of
    WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK,
    WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK,
    WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK:
      begin
        Message.Result := 0;
        Exit;
      end;
  end;
  FSaveRichEditProc(Message);
end;