关于标题栏文字移动的问题(30分)

  • 主题发起人 主题发起人 嫩手
  • 开始时间 开始时间

嫩手

Unregistered / Unconfirmed
GUEST, unregistred user!
Winamp能在任务样上的标题栏上做出滚动字幕,请问这是怎么做出来的?可否来段代码
 
Application.Title:="我是程序标题";
然后用循环.
 
算出窗体的宽,然后用一个循环补空格
 
加空格应该可以,注意到头时的处理
 
m:=窗体caption本身的字符数;
n :=窗体caption可容纳的字符数.
for i:=m to n do
begin
form1.caption :=' '+form1.caption
if i=n then
i=m;
end;
 
用ttimer控件与加空格处理
特别简单
procedure TForm1.Timer1Timer(Sender: TObject);
var CaptionLength:integer;
begin
CaptionLength:=length(Form1.Caption);
if CaptionLength=200 then
begin
Form1.Caption:='aaaa';
end;
Form1.Caption:=' '+Form1.Caption;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=true;
Form1.Caption:='aaaa';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;


 
当有混合字符时会出现乱码,如汉字与拼音字母的混合...因为汉字为2个字节.....
 
没问题呀,
不会出现乱码呀,我试过了
Timer1的interval属性设为10 移动速度刚好
 
to zswenyun:
在任务栏中怎么做呀?我说的是在任务栏的Title上滚动显示!
 

Form1.Caption
改为
Application.Title

 
procedure TForm1.Timer1Timer(Sender: TObject);
var CaptionLength:integer;
begin
CaptionLength:=length(Application.Title);
if CaptionLength=10 then
begin
Application.Title:='aaaa';
end;
Application.Title:=' '+Application.Title;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=true;
Application.Title:='aaaa';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;
 
to zswenyun:
谢谢你!
  还有,能不能再给一段完整的代码,我想要的是像WinAmp那样循环滚动的,可以吗?
 
Winamp是画上去的。实例:
procedure TWinampSkin.SetTitle(const Value: string);
begin
FTitle := Value;
TextScrollPos:=0;
if titlelength>30 then
ScrollTimer.Enabled := True;
PaintTitle;
//画标题栏
end;

procedure TWinampSkin.PaintTitle;
var text:string;
begin
if systemtitle='' then
text:=title
else
text:=systemtitle;
//给标题栏赋值
TextBMP.Canvas.Brush.color:=clBlack;
TextBMP.Canvas.FillRect(rect(0,0,155,10));
//画布区域
TitleLength:=TextOut(TextBMP.Canvas,Title,0,0,[]);
Canvas.CopyRect(rect(110,27,265,33),skmain.canvas,rect(110,27,265,33));
if Length(Text)>31 then
begin
if abs(TextScrollPos) >= TitleLength then
TextScrollPos:=0;
//循环
Canvas.CopyRect(rect(110,27,265,33),textbmp.canvas,rect(TextScrollPos,0,TextScrollPos+155,6));
if TextScrollPos+155 > TitleLength then
// nach links
Canvas.CopyRect(rect(110+Titlelength-TextScrollPos,27,265,33),textbmp.canvas,rect(0,0,265-(110+TitleLength-TextScrollPos),6));
if TextScrollPos < 0 then
// nach rechts
if TextScrollPos < -155 then
Canvas.CopyRect(rect(110,27,265,33),textbmp.canvas,rect(titlelength+textscrollpos,0,titlelength+textscrollpos+155,6))
else
Canvas.CopyRect(rect(110,27,110-textscrollpos,33),textbmp.canvas,rect(titlelength+textscrollpos,0,titlelength,6));
end else
TextOut(Canvas,Text,110,27,[]);
end;

procedure TWinampSkin.TextTimer(Sender: TObject);
begin
TextScrollPos:=TextScrollPos+5;

PaintTitle;
end;
 
以上只是一个控件的源码。
下载地址:http://cn.torry.net/vcl/shapes/enhancedshapes/waskin.zip
(很苦的一个控件哦! *^_^* )
不过很可惜,对中文支持得不太好,谁解决了请告诉我一声。
 
to soFtangel:
怎么这个控件不能用?我安装没问题,但使用的时候总提示:Stream read error
 
不用这么凡
 
说白了就是一个加空格嘛,用不着这么难吧。
 
var
Form1: TForm1;
begin
Str:string;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
var CaptionLength,PostionCount:integer;
TempFlage:boolean;
begin
CaptionLength:=length(form1.Caption);
if CaptionLength=100 then
begin
form1.Caption:='';
CaptionLength:=0;
end;
if CaptionLength < length(begin
Str) then
begin
PostionCount:=length(begin
Str)-length(form1.Caption);
if Windows.IsDBCSLeadByte(byte(begin
Str[PostionCount])) then
//判断是否为双字节的引导字节若是则读取两个字节
form1.Caption:=copy(begin
Str,PostionCount-1,(length(form1.Caption)+2))
else
form1.Caption:=begin
Str[PostionCount]+form1.Caption;
end else
form1.Caption:=' '+form1.Caption;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
begin
Str:=edit1.text;
form1.Caption:=begin
Str;
Timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;
 
这样就可以把单字节的英文单词与双字节的中文汉语区分,不会出现半字截取
 
忘了把form1.Caption改为Application.titlele
自己改把
 
后退
顶部