TLama

Untitled

Jun 20th, 2014
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.53 KB | None | 0 0
  1. uses
  2.   RichEdit, ComCtrls;
  3.  
  4. type
  5.   PNMMsgFilter = ^TNMMsgFilter;
  6.   TNMMsgFilter = packed record
  7.     nmhdr: TNMHdr;
  8.     msg: UINT;
  9.     wParam: WPARAM;
  10.     lParam: LPARAM;
  11.   end;
  12.  
  13.   TMouseButtons = set of TMouseButton;
  14.  
  15.   TRichEdit = class(ComCtrls.TRichEdit)
  16.   private
  17.     FAllowedButtons: TMouseButtons;
  18.     procedure CNNotify(var AMessage: TWMNotify); message CN_NOTIFY;
  19.   protected
  20.     procedure CreateWnd; override;
  21.   public
  22.     constructor Create(AOwner: TComponent); override;
  23.     property AllowedButtons: TMouseButtons read FAllowedButtons write FAllowedButtons;
  24.   end;
  25.  
  26. implementation
  27.  
  28. { TRichEdit }
  29.  
  30. constructor TRichEdit.Create(AOwner: TComponent);
  31. begin
  32.   inherited;
  33.   FAllowedButtons := [mbLeft, mbRight, mbMiddle];
  34. end;
  35.  
  36. procedure TRichEdit.CNNotify(var AMessage: TWMNotify);
  37. begin
  38.   if AMessage.NMHdr^.code = EN_MSGFILTER then
  39.   begin
  40.     case PNMMsgFilter(AMessage.NMHdr)^.msg of
  41.       WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK: AMessage.Result := Ord(not (mbLeft in FAllowedButtons));
  42.       WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK: AMessage.Result := Ord(not (mbRight in FAllowedButtons));
  43.       WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK: AMessage.Result := Ord(not (mbMiddle in FAllowedButtons));
  44.     else
  45.       inherited;
  46.     end;
  47.   end
  48.   else
  49.     inherited;
  50. end;
  51.  
  52. procedure TRichEdit.CreateWnd;
  53. var
  54.   EventMask: LRESULT;
  55. begin
  56.   inherited;
  57.   EventMask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
  58.   SendMessage(Handle, EM_SETEVENTMASK, 0, EventMask or ENM_MOUSEEVENTS);
  59. end;
Advertisement
Add Comment
Please, Sign In to add comment