首页 > 其他 > 详细

研究一下TForm.WMPaint过程

时间:2016-02-26 00:21:03      阅读:142      评论:0      收藏:0      [点我收藏+]

先擦除背景:

procedure TCustomForm.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  if not IsIconic(Handle) then inherited 
  else
  begin
    Message.Msg := WM_ICONERASEBKGND;
    DefaultHandler(Message);
  end;
end;

procedure TWinControl.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  with ThemeServices do
  if ThemesEnabled and Assigned(Parent) and (csParentBackground in FControlStyle) then
    begin
      { Get the parent to draw its background into the control‘s background. }
      DrawParentBackground(Handle, Message.DC, nil, False);
    end
    else
    begin
      { Only erase background if we‘re not doublebuffering or painting to memory. }
      if not FDoubleBuffered or
         (TMessage(Message).wParam = TMessage(Message).lParam) then
        FillRect(Message.DC, ClientRect, FBrush.Handle); // Brush的颜色事先读取好了
    end;

  Message.Result := 1;
end;

然后进行绘制(背景色已经实现存在,无论这里究竟绘制了什么都不影响背景色,如果不绘制,就全部都是背景色):

procedure TCustomForm.WMPaint(var Message: TWMPaint);
var
  DC: HDC;
  PS: TPaintStruct;
begin
  if not IsIconic(Handle) then
  begin
    ControlState := ControlState + [csCustomPaint];
    inherited;
    ControlState := ControlState - [csCustomPaint];
  end
  else
  begin
    DC := BeginPaint(Handle, PS);
    DrawIcon(DC, 0, 0, GetIconHandle);
    EndPaint(Handle, PS);
  end;
end;

这就是为什么我这样写:

procedure TForm1.FormCreate(Sender: TObject);
begin
  //
end;

也丝毫不影响整个Form1的显示。也许像上面那样写会被编译器删除,那么我这样写:

procedure TForm1.FormCreate(Sender: TObject);
begin
  tag := 100;
end;

还是丝毫不影响整个Form1的显示。

---------------------------------------------------------------------

唯一有个问题是,InitInheritedComponent读取dfm的颜色以后,是什么时候把它赋值给FBrush.Color的?继续研究。。。

研究一下TForm.WMPaint过程

原文:http://www.cnblogs.com/findumars/p/5218631.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!