一个窗体,现在想让他循环显示一段文字,要平滑的显示,所以用定时器来定时给caption赋值的方法就不行了有什么好办法吗?
 
DrawText我找不到caption的句柄啊...

解决方案 »

  1.   

    在OnPaint中画,搞一个timer定时Invalidate
      

  2.   

    窗口边框标题的绘制,消息是WM_NCPAINT,而不是OnPaint的WM_PAINT;某些人想都没想,
    得参考默认处理过程
    procedure TWinControl.WMNCPaint(var Message: TMessage);百度了这个资料给你
    http://www.phpzy.com/php/1127924.html
      

  3.   

    用Timer来DrawText!
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
        dc: HDC;
        v: Integer;
        l,t,b,r: Integer;
        f: HFONT;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    {$o-}procedure TForm1.FormCreate(Sender: TObject);
    var
      n:  NONCLIENTMETRICS;
    begin
      Timer1.Enabled := False;
      Timer1.Interval := 10;  dc := GetWindowDC(Handle);  n.cbSize := SizeOf( NONCLIENTMETRICS );
      SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf( NONCLIENTMETRICS ), @n, 0);
      f := CreateFontIndirect(n.lfCaptionFont);//取真正的标题的字体
      SelectObject(dc, f);//设置 动态画的标题的字体 为 真正的标题的字体  //取动态标题的最大显示区域:left, top, bottom, right
      l := 2*(GetSystemMetrics(SM_CXBORDER)+GetSystemMetrics(SM_CXDLGFRAME))+GetSystemMetrics(SM_CXSMICON);
    //  Inc(l,2);
      t := 0;
      b := GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYCAPTION);
    //  Inc(b,3);
      r := Width - GetSystemMetrics(SM_CXSIZE) * 3;  SetBkMode(dc, TRANSPARENT);//设置背景透明
      SetTextColor(dc, GetSysColor(COLOR_CAPTIONTEXT)); //设置文本颜色 为 真正的标题的文本颜色  SetTextBuf(nil);//置 真正标题 为空
      Timer1.Enabled := True;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      DeleteObject(f);
      ReleaseDC(Handle, dc)
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    var
      rc: TRect;
    begin
      Timer1.Enabled := False;  if v > l then Dec(v) else v := r;//修改区域的right  SetWindowPos(Handle, 0 ,0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE
        or SWP_NOSIZE or SWP_DRAWFRAME);//重画,去除先前画的内容
      rc := Rect(l, t, v, b);
      DrawText(dc, 'Form1', 5, rc, DT_SINGLELINE or DT_VCENTER or DT_RIGHT);//真正的标题其实不是垂直居中的!  Timer1.Enabled := True
    end;end.
      

  4.   

    平滑是相对的概念,相对于重画的间隔时间,所以只要定时器的interval设置得越小,就越平滑。