1

我有一个TFrame带有一些控件的控件,以及一个TPanel用于TPaintBox绘制视频的容器。

当我调整框架大小时,由于臭名昭著的背景擦除,油漆盒上的图像会闪烁。

我用谷歌搜索了几个小时并尝试了所有方法(将 PaintBox设置ControlStylecsOpaque,将面板设置Brush为,将面板bsClear更改为双缓冲,将面板设置FullRepaint为 false 等),但唯一能解决问题的是WM_ERASEBKGND在我的框架中截取消息:

void __fastcall TFrameSample::WndProc(TMessage &Message)
{
    if (Message.Msg == WM_ERASEBKGND)
        Message.Result = 1;
    else
        TFrame::WndProc(Message);
}

但是,这意味着没有重绘任何内容,包括框架的标题栏及其所有控件。

我知道这是一个非常普遍的问题,有解决方案吗?

4

1 回答 1

2

在 Remy Lebeau 的旧帖子中找到了答案,请参阅http://www.delphigroups.info/2/81/414040.html

有几种不同的方法可以拦截每个控件上的消息。派生一个新类只是其中之一。您还可以仅对现有对象实例的 WindowProc 属性进行子类化。例如:

private
    OldWndMethod: TWndMethod;
    procedure PanelWndProc(var Message: TMessage);
constructor TForm1.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    OldWndMethod := Panel1.WindowProc
    Panel1.WindowProc := PanelWndProc;
end;
procedure TForm1.PanelWndProc(var Message: TMessage);
begin
    if Message.Msg = WM_ERASEBKGND then
    begin
        //...
    end else
        OldWndMethod(Message);
end;
于 2021-06-08T14:36:27.793 回答