我需要intercept the WM_PASTE
message对于放置在 TFrame
的后代类中的 TEdit
组件。
如果不满足条件,我想启动粘贴操作。
有没有办法在帧级别做到这一点? (我的意思是,没有声明 TEdit
的后代)
最佳答案
Is there a way to do this at the frame level? (I mean, without declaring a
TEdit
's descendant)
WM_PASTE
直接发送至TEdit
窗口,TFrame
永远不会看到它,所以您必须子类化 TEdit
直接拦截消息。您可以:
有
TFrame
将处理程序分配给TEdit
的WindowProc
属性(property)。如果您只有几个TEdit
,这是一个简单的方法。 s 到子类,但越多就越复杂TEdit
您想要子类化:type TMyFrame = class(TFrame) Edit1: TEdit; ... procedure FrameCreate(Sender: TObject); ... private PrevWndProc: TWndMethod; procedure EditWndProc(var Message: TMessage); ... end; procedure TMyFrame.FrameCreate(Sender: TObject); begin PrevWndProc := Edit1.WindowProc; Edit1.WindowProc := EditWndProc; ... end; procedure TMyFrame.EditWndProc(var Message: TMessage); begin if Message.Msg = WM_PASTE then begin if SomeCondition then Exit; end; PrevWndProc(Message); end;
编写并安装一个源自
TEdit
的新组件,类似于TMemo
example you presented .定义一个仅位于
TFrame
本地的插入器类。的单位,位于TFrame
上方类声明,它将拦截WM_PASTE
对于每个TEdit
在框架上:type TEdit = class(Vcl.StdCtrls.TEdit) procedure WMPaste(var Message: TMessage); message WM_PASTE; end; TMyFrame = class(TFrame) Edit1: TEdit; Edit2: TEdit; ... end; procedure TEdit.WMPaste(var Message: TMessage); begin if not SomeCondition then inherited; end;
关于delphi - 如何拦截和抑制 TFrame 子组件的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304718/