首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

在窗体的标题上平滑滚动文字,平滑哦解决思路

2012-05-28 
在窗体的标题上平滑滚动文字,平滑哦一个窗体,现在想让他循环显示一段文字,要平滑的显示,所以用定时器来定

在窗体的标题上平滑滚动文字,平滑哦
一个窗体,现在想让他循环显示一段文字,要平滑的显示,所以用定时器来定时给caption赋值的方法就不行了

有什么好办法吗?
 
DrawText我找不到caption的句柄啊...

[解决办法]
用Timer来DrawText!

Delphi(Pascal) code
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 := Trueend;end. 

热点排行