delphi - 处理来自子组件的父 WndProc

标签 delphi winapi

我正在开发一个新组件,并且我想处理所有父消息。

Type
 TMyComponent= class(TComponent)
//Bla bla
/..
//.
published
property Parent: TWinControl read FParent write SetParent;

end;

我想访问Parent WndProc(处理所有父消息)。有什么方法可以从我的 TMyComponent 处理 Parent WndProc 吗?

最佳答案

像这样:

type
  TMyComponent = class(TComponent)
  private
    FParent: TWinControl;
    FParentWindowProc: TWndMethod;
    procedure WindowProc(var Message: TMessage);
    procedure SetParent(Value: TWinControl);
  published
    property Parent: TWinControl read FParent write SetParent;
  end;

procedure TMyComponent.SetParent(Value: TWinControl);
begin
  if Value=FParent then
    exit;

  if Assigned(FParent) then
    FParent.WindowProc := FParentWindowProc;
  FParentWindowProc := nil;

  FParent := Value;

  if Assigned(FParent) then
  begin
    FParentWindowProc := FParent.WindowProc;
    FParent.WindowProc := WindowProc;
  end;
end;

procedure TMyComponent.WindowProc(var Message: TMessage);
begin
  // do whatever we want with the message
  FParentWindowProc(Message);// delegate to parent's window procedure
end;

关于delphi - 处理来自子组件的父 WndProc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13892991/

相关文章:

delphi - Delphi 中的自定义 JPEG 图像处理

delphi - 当类助手在作用域内时,如何调用原始类的代码?

c - 将 SHGetSpecialFolderPath+SubFolder 与 SHFileOperation 结合使用

.net - 使用 Windows 事件日志有哪些选项?

C++/Win32 我在 Windows 2000+ 上启动线程的最佳方式

sql - 对于 FreePascal 和 Delphi,是否有用于清理 PostgreSQL 或 SQL 查询参数的库?

delphi - 双舍入

Delphi 内联更改了位读取的答案

winapi - 如何列出 NTFS 文件系统上的所有符号链接(symbolic link)

c++ - 在任何地方绘制一个类似系统的光标,最顶层