type
TNoUseControl = class(TControl)
private
OldFormWndProc: TWndMethod;
procedure NewFormWndProc(var Msg: TMessage);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
constructor TNoUseControl.Create(AOwner: TComponent);
begin
inherited;
OldFormWndProc := TCustomForm(AOwner).WindowProc;
TCustomForm(AOwner).WindowProc := NewFormWndProc;
end;
destructor Destroy;
begin
if Assigned(OldFormWndProc) then
with TCustomForm(Owner) do
WindowProc := OldFormWndProc;
inherited;
end;
procedure TNoUseControl.NewFormWndProc(var Msg: TMessage);
begin
case Msg.Msg of
WM_DESTORY: // form窗口释放前恢复原windowproc值, 不然可能运行错
if csDestroying in TCustomForm(Owner).ComponentState then
with TCustomForm(Owner) do
begin
WindowProc := OldFormWndProc;
OldFormWndProc := nil;
WindowProc(Msg);
exit;
end;
WM_USER+5: // 假设是你自定义的消息
begin
.....
end;
end;
OldFormWndProc(Msg);
end;