Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- RichEdit, ComCtrls;
- type
- PNMMsgFilter = ^TNMMsgFilter;
- TNMMsgFilter = packed record
- nmhdr: TNMHdr;
- msg: UINT;
- wParam: WPARAM;
- lParam: LPARAM;
- end;
- TMouseButtons = set of TMouseButton;
- TRichEdit = class(ComCtrls.TRichEdit)
- private
- FAllowedButtons: TMouseButtons;
- procedure CNNotify(var AMessage: TWMNotify); message CN_NOTIFY;
- protected
- procedure CreateWnd; override;
- public
- constructor Create(AOwner: TComponent); override;
- property AllowedButtons: TMouseButtons read FAllowedButtons write FAllowedButtons;
- end;
- implementation
- { TRichEdit }
- constructor TRichEdit.Create(AOwner: TComponent);
- begin
- inherited;
- FAllowedButtons := [mbLeft, mbRight, mbMiddle];
- end;
- procedure TRichEdit.CNNotify(var AMessage: TWMNotify);
- begin
- if AMessage.NMHdr^.code = EN_MSGFILTER then
- begin
- case PNMMsgFilter(AMessage.NMHdr)^.msg of
- WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK: AMessage.Result := Ord(not (mbLeft in FAllowedButtons));
- WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK: AMessage.Result := Ord(not (mbRight in FAllowedButtons));
- WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK: AMessage.Result := Ord(not (mbMiddle in FAllowedButtons));
- else
- inherited;
- end;
- end
- else
- inherited;
- end;
- procedure TRichEdit.CreateWnd;
- var
- EventMask: LRESULT;
- begin
- inherited;
- EventMask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
- SendMessage(Handle, EM_SETEVENTMASK, 0, EventMask or ENM_MOUSEEVENTS);
- end;
Advertisement
Add Comment
Please, Sign In to add comment