怎样地Memo中屏蔽掉右键弹出活动菜单功能,如何实现消息拦截(10分)

  • 主题发起人 主题发起人 sunnysheng
  • 开始时间 开始时间
S

sunnysheng

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样拦截消息使得右击不出现活动菜单?
 
不用拦截消息就能实现:<br>给Memo1 的 PopupMenu 属性设一个 PopupMenu1,这个PopupMenu1上没有MenuItem.<br>:P<br><br>
 
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; var Handled: Boolean);<br>begin<br><br>if Msg.message = WM_RBUTTONDOWN then<br>Begin<br>Form1.Caption:='aa';<br>Msg.message:=0;<br><br>end;<br>if Msg.message =WM_RBUTTONDBLCLK then<br>Begin<br>Form1.Caption:='bb';<br>Msg.message:=0;<br><br>end;<br><br>end;
 
谢谢各位,那怎样在Memo中实现这种功能,以达到无法复制,剪切,另外屏蔽掉Ctrl+C,Ctrl+V<br>
 
要是只是不让它弹出右键菜单的话, 不用那么复杂, 可以在memo的ContextPopup的handled:=true就行了, <br>但是如果要是想屏bi掉Ctrl+C, Ctrl+V那就得要拦截消息了~~~
 
自定义右键菜单,<br><br>好像就没有复制功能了
 
拦截其WM_CUT,WM_COPY,WM_PASTE消息即可,
 
枪手哈特:能否具体点,因为我也知道要拦截这两个消息,但是我只要指定的控件(比如:Memo1这个控件),应该怎么做啊?谢谢。
 
禁止粘贴的话,可以让 Memo1.ReadyOnly := true;<br>禁止 Copy 我也想知道。。。。<br>
 
unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br>type<br>&nbsp; TMemo1 = class(TMemo)<br>&nbsp; procedure WndProc(var Message : TMessage); override;<br>&nbsp; end;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations } &nbsp; &nbsp;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; mm : TMemo1;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; mm := TMemo1.Create(self);<br>&nbsp; mm.Parent := form1;<br>&nbsp; mm.Left :=10;<br>&nbsp; mm.Top := 10;<br>&nbsp; mm.Width := 300;<br>&nbsp; mm.Height := 80;<br>&nbsp; mm.Text := 'skdjflaskjdfaslkfj';<br>end;<br><br>{ TMemo1 }<br><br>procedure TMemo1.WndProc(var Message: TMessage);<br>begin<br>&nbsp; if message.Msg = WM_CUT then<br>&nbsp; begin<br>// &nbsp; &nbsp;form1.Caption := 'dd';<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; inherited;<br><br>end;<br><br>end.
 
在OnContextPopUp事件里写:handled:=true;<br>在OnkeyPress事件里写:key:=#0;<br>
 
可以类似以下的写法:<br>procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; if (ssCtrl in Shift)and(key=ord('X')) then<br>&nbsp; begin<br>//先保存粘贴板上的内容<br>&nbsp; &nbsp; memo1.PasteFromClipboard;<br>//恢复存粘贴板上的内容<br>&nbsp; end;<br>end;
 
就按照DouZheng说的做!
 
后退
顶部