一个朋友要 播放列表 文件管理 和 列表清单及播放清单de代码,顺便贴上
//Treeview自画过程
procedure TfrmPlaylist.TvCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode;
State: TCustomDrawState;
var DefaultDraw: Boolean);
var
NodeRect: TRect;
p1,p2:TPoint;
PointInNode:Boolean;
begin
with TV.Canvasdo
begin
tv.Color := colorsets[9];
tv.Font.Color := colorsets[1] ;
font.Assign(tv.Font);
if (node.Index mod 2)=1 then
Brush.Color := colorsets[2]
else
Brush.Color := colorsets[3];
//选取行字体颜色
if (cdsSelected in State) then
font.Color :=colorsets[7];
//播放行 (越靠后的,优先级越高)
if node.Index =mainfrm.currPlayList then
begin
font.Color :=colorsets[5];
Brush.Color := colorsets[4];
end;
//选取行背景
if (cdsSelected in State) then
Brush.Color := colorsets[6];
DefaultDraw:=false;
NodeRect := Node.DisplayRect(false);
p1.X :=NodeRect.left ;
p1.Y :=NodeRect.Top ;
p2.X :=NodeRect.Right ;
p2.Y :=noderect.Bottom;
p1:=tv.ClientToScreen(p1);
p2:=tv.ClientToScreen(p2);
PointInNode:=false;
if (mouse.CursorPos.X >=p1.X) and (mouse.CursorPos.X <=p2.X)
and (mouse.CursorPos.y >=p1.y) and (mouse.CursorPos.y <=p2.y) then
PointInNode:=true;
if (cdsSelected in State) and (cdsFocused in state) then
begin
brush.Style :=bsclear;
stretchdraw(noderect,CurItemImg);
end
else
begin
if PointInNode and (tv.DropTarget =node) and (node<> tv.Selected ) and (sglist.Dragging or tv.Dragging )
and (not PMyRec(node.Data)^.locked) then
brush.Color :=clNavy;
FillRect(NodeRect);
end;
NodeRect:=Node.DisplayRect(true);
NodeRect.Left := NodeRect.Left+7;
NodeRect.Right :=NodeRect.Right +7;
DrawText(Handle, PChar(Node.Text), Length(Node.Text), NodeRect, DT_SINGLELINE or DT_VCENTER);
if node.Index =mainfrm.currPlayList then
begin
NodeRect:=Node.DisplayRect(true);
NodeRect.Left := NodeRect.Left;
draw(nodeRect.Left,nodeRect.Top+(NodeRect.Bottom -NodeRect.Top -curPlaylistImg.Height ) div 2 ,curPlaylistImg );
end;
//焦点框
if (cdsSelected in State) then
//and tv.Focused
begin
NodeRect:=Node.DisplayRect(false);
pen.Color :=colorsets[1];
PenPos := Point(NodeRect.Left , NodeRect.Top );
Lineto(Noderect.Right-1,nodeRect.Top);
Lineto(Noderect.Right-1,nodeRect.bottom-1);
Lineto(Noderect.left,nodeRect.bottom-1);
Lineto(NodeRect.Left , NodeRect.Top);
end;
end;
end;
//播放清单 自画过程
procedure TfrmPlaylist.sglistDrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var drawStr:string;
aRect:TRect;
begin
with Sender as TStringGriddo
begin
DefaultDrawing:=false;
Color := colorsets[9];
if (Arow=0) then
//or (ACol=0)
Canvas.Brush.Color := colorsets[0]
else
begin
if ARow mod 2 =0 then
Canvas.Brush.Color := colorsets[2]
else
Canvas.Brush.Color :=colorsets[3];
end;
canvas.Brush.Style:=bsSolid;
canvas.Font.Name :='宋体';
canvas.Font.Size :=9;
canvas.Font.Color :=colorsets[1];
canvas.font.Style :=[];
//选取行字体颜色
if (acol<=Selection.right) and (acol>=Selection.left) and
(arow>=Selection.top) and (arow <=Selection.bottom) then
//选取的行
canvas.Font.Color :=colorsets[7];
//播放字 字体颜色和背景颜色 是否粗体
if (playerstate<>psClosed) and (mainfrm.GetGridCell('标记',ARow)=mainfrm.playfilesign)
and (tv.Selected.index = mainfrm.currPlayList) then
begin
// 正在播放的
if colorsets[8]=1 then
canvas.font.Style :=[fsbold]
else
canvas.font.Style :=[];
canvas.Font.Color :=colorsets[5];
canvas.Brush.Color :=colorsets[4];
end;
//选取行背景
if (acol<=Selection.right) and (acol>=Selection.left) and
(arow>=Selection.top) and (arow <=Selection.bottom) then
//选取的行
canvas.Brush.Color :=colorsets[6];
//选取行 背景色
if (acol<=Selection.right) and (acol>=Selection.left)
and (arow=sglist.Row ) then
begin
aRect:=Rect;
arect.Bottom :=arect.Bottom -1;
if sglist.Focused then
//选取的行 //sglist.Focused (gdFocused in State)
begin
canvas.Brush.Style :=bsclear;
canvas.StretchDraw(arect,CurItemImg );
canvas.Rectangle(arect);
end
else
begin
canvas.Rectangle(arect);
end;
end
else
Canvas.FillRect(Rect);
drawStr:=trim(cells[acol,arow]);
if (pos(cells[ACol,0] ,'文件名 '+'时间 '+'歌名 '+'全名 '+'歌手 '+'歌词文件 '+'评论 '+'专辑 ')<>0)
and (ARow<>0) then
drawStr:=mainfrm.ResetCharMax(drawStr,rect.Right-rect.Left-2);
if (drawStr='[未指定]') then
drawStr:=' - -'
else
if (drawStr='') and (aCol<>0) then
drawStr:=' -' ;
if (ARow=0) then
begin
//居中
DrawText(Canvas.Handle, PChar(drawStr), Length(drawStr), Rect, DT_CENTER or DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX)
end
else
begin
aRect:=Rect;
offsetrect(aRect,1,0);
aRect.Right :=aRect.Right-2 ;
if (ACol=0) and (ARow>0) then
//第一列
begin
aRect:=Rect;
offsetrect(aRect,2,0);
aRect.Right :=aRect.Right ;
DrawText(Canvas.Handle, PChar(drawStr+' '), Length(drawStr+' '), aRect, dt_RIght or DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
end
else
if (pos(cells[ACol,0] , '类型 '+'时间 '+'出版年 '+'流派 '+'最爱 ')<>0) then
//居中
DrawText(Canvas.Handle, PChar(drawStr), Length(drawStr), aRect, DT_CENTER or DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX)
else
//居左
DrawText(Canvas.Handle, PChar(drawStr), Length(drawStr), aRect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
end;
//特别选取 行
canvas.Pen.Width :=1;
canvas.Pen.Color :=colorsets[1];
canvas.Pen.style :=pssolid;
if length(mainfrm.selList)=RowCount then
if mainfrm.selList[ARow] then
//and (ACol=0)
begin
canvas.MoveTo(rect.left,rect.top);
canvas.LineTo(rect.right,rect.top);
//画左竖线
if ACol=0 then
begin
canvas.MoveTo(rect.left,rect.top);
canvas.LineTo(rect.Left,rect.Bottom-2);
end;
//画右竖线
if aCol=ColCount-1 then
begin
canvas.MoveTo(rect.right-1,rect.top);
canvas.LineTo(rect.right-1,rect.Bottom-2);
end;
//画下横线
canvas.MoveTo(rect.Left,rect.Bottom-2);
canvas.LineTo(rect.right,rect.Bottom-2);
end;
end;
end;
=============================================
const SIG_MYLIST = 'WANGLST';
//用于 播放列表文件
TLstTag = packed record //列表文件Tag 信息格式(共128字节)
Num:integer;
//曲目数量 (4)
Header:array[0..6] of char;
//TAG开始以:'WANGLST'为标志 (7)
Txt:array[0..29] of char;
//列表标题(名称) (30)
No:byte; //列表位置 (1)
Locked:boolean; //是否加锁 (1)
Pwd:array[0..29] of char;
//锁密码 (30)
Comment:array[0..54] of char;
//备注 (55)
end;
=====================================================================================
//------------读取所有播放列表------------------
procedure Tmainfrm.readallList;
var havelist:boolean;
//是否 已经 成功读取一个清单
SearchRec:TSearchRec;
findPath:string;
i:integer;
begin
havelist:=false;
findpath:=GetPlaylstPath+'*.*';
if findfirst(findpath,faAnyfile,searchRec)=0 then
begin
repeat
if (uppercase(extractfileext(searchRec.name))='.LST') then
begin
if not havelist then
begin
//读取列表及其清单
if readlist( searchRec.name,true) then
havelist:=True;
end
else
//读取列表
readlistName( searchRec.name,false);
end;
until findnext(SearchRec)<>0 ;
end ;
findclose(searchRec);
//不存在任何一个清单时,自动创建 空清单
if not havelist then
begin
//createList('');
createList('歌曲');
createList('电影');
createList('Flash动画');
end ;
if mnushowplaylist.Checked then
begin
playlistwindow.tv.Items.GetFirstNode.Selected :=true;
playlistwindow.ListBox1.ItemIndex :=0;
if not PMyRec(playlistwindow.tv.Selected.data)^.locked then
showlist(PMyRec(playlistwindow.tv.Selected.data)^.lfilename)
else
begin
showNullList;
end;
end
else
begin
listIndex:=0;
if not playlists[listIndex].Locked then
showlist(playlists[listIndex].lfilename)
else
begin
showNullList;
end;
end;
end;
//==============读取所有播放列表======================
//----------------度取并显示指定列表(目前为 当前选择列表)-----------------
//aName:目前无用
function Tmainfrm.Showlist(aName:string):boolean;
var i,j:integer;
begin
filenamechg:=false;
listChged:=false;
treeViewNodeChged:=false;
//Reset sglist
for i:=1 to tmpsglist.RowCount-1do
for j:=0 to tmpsglist.ColCount -1do
tmpsglist.Cells[j,i]:='';
for i:=1 to HideColGrid.RowCount-1do
for j:=0 to HideColGrid.ColCount -1do
HideColGrid.Cells[j,i]:='';
//显示指定的清单
if mnushowplaylist.Checked then
readlist(PMyRec(playlistwindow.tv.Selected.data)^.lfilename,false)
else
readlist(playlists[listIndex].lfilename,false);
//取消原来 特别选取
setlength(selList,tmpsglist.RowCount);
for i:=1 to Length(sellist)-1do
sellist:=false;
result:=true;
end;
//================度取并显示指定列表===============
//---------------显示 空列表-----------------------
procedure Tmainfrm.showNullList;
var i,j:integer;
begin
tmpsglist.RowCount :=2;
if MaxColNum-tmpsglist.ColCount >1 then
HideColGrid.ColCount := MaxColNum-tmpsglist.ColCount
else
HideColGrid.ColCount := 1;
if tmpsglist.ColCount <>MaxColNum then
HideColGrid.rowcount :=tmpsglist.RowCount ;
for i:=1 to tmpsglist.RowCount-1do
for j:=0 to tmpsglist.ColCount -1do
tmpsglist.Cells[j,i]:='';
for i:=1 to HideColGrid.RowCount-1do
for j:=0 to HideColGrid.ColCount -1do
HideColGrid.Cells[j,i]:='';
end;
//=====================显示 空列表======================
//-------------------读取列表文件-----------------------
//aName:列表文件
//addSign:读取的同时,是否在TreeView中添加节点
function Tmainfrm.Readlist(aName:string;addSign:boolean):boolean;
var
fs : TFileStream;
s ,sName : String;
i,m,l,g,p1,lNo: Integer;
answer:boolean ;
rootnode,NewNode:TTreenode;
MyRecPtr: PMyRec;
aLocked:boolean;
aPwd:string;
haveId3:boolean;
Info : TLstTag ;
begin
result:=false;
fs := TFileStream.Create(GetPlaylstPath+ aName, fmOpenRead);
with fsdo
begin
try
try
p1:=0;
p1:=1;
//-----------------------
if fs.Size <128 then
begin
fs.Free;
answer:= showQuestion2('非法列表文件1:'+GetPlaylstPath+aName
+#13#13+'是否删除该播放列表文件?');
if answer then
deletefile(GetPlaylstPath+aName);
exit;
end;
ReadBuffer(Info,sizeof(TLstTag));
if info.Header<>SIG_MYLIST then
begin
answer:= showQuestion2('非法列表文件2:'+GetPlaylstPath+aName
+#13#13+'是否删除该播放列表文件?');
exit;
end;
m:=Info.Num ;
sName:=TrimRight(Info.Txt);
lNo:=Info.No;
aLocked:=Info.Locked;
aPwd:=TrimRight(Info.Pwd);
//===============================
if addSign then
begin
if mnushowplaylist.Checked then
begin
rootNode:=playlistwindow.Tv.Items.GetFirstNode;
New(MyRecPtr);
MyRecPtr^.Lfilename := aName;
MyRecPtr^.LNo :=lNo;
MyRecPtr^.locked :=aLocked;
MyRecPtr^.pwd :=aPwd;
NewNode:=playlistwindow.Tv.Items.AddObject(rootNode,sName,MyRecPtr);
//NewNode.Selected :=true;
New(MyRecPtr);
Dispose(MyRecPtr);
playlistwindow.ListBox1.Items.Add(sname);
// playlistwindow.ListBox1.ItemIndex :=0;
// playlistwindow.ListBox1.Selected[0]:=true;
end
else
begin
//***
setlength(playlists,length(playlists)+1);
playLists[length(playlists)-1].LNo :=lNo;
playLists[length(playlists)-1].Lfilename :=aName;
playLists[length(playlists)-1].LTxt := sName;
playLists[length(playlists)-1].Locked :=aLocked;
playLists[length(playlists)-1].pwd :=aPwd;
p1:=57;
//***
end;
end;
if m=0 then
tmpsglist.RowCount :=2
else
tmpsglist.RowCount:=m+1;
if MaxColNum-tmpsglist.ColCount >1 then
HideColGrid.ColCount := MaxColNum-tmpsglist.ColCount
else
HideColGrid.ColCount := 1;
if tmpsglist.ColCount <>MaxColNum then
HideColGrid.rowcount :=tmpsglist.RowCount ;
p1:=58;
for i:=1 to mdo
//m
begin
SetGridCell('No.',inttostr(i),i);
p1:=2;
//Read Whole name
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
p1:=3;
SetGridCell('全名',s,i);
//Get file ext
SetGridCell('类型',copy(extractfileext(s),2,length(extractfileext(s))-1),i);
//Get file simple name
SetGridCell('文件名',copy(extractfilename(s),1,length(extractfilename(s))-length(extractfileext(s))),i);
p1:=4;
//Read time
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('时间',s,i);
p1:=5;
//read haveId3
read (haveId3, sizeof(Boolean));
p1:=6;
if haveId3 then
begin
//Read title
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('歌名',s,i);
p1:=7;
//read Artils
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('歌手',s,i);
p1:=8;
//Read Album
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('专辑',s,i);
p1:=9;
//Read Year
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('出版年',s,i);
p1:=10;
//Read Genre
read (g,SizeOf(integer));
SetGridCell('流派',GetGenreName(g),i);
p1:=101;
//Read Comment
read (l,sizeof(Integer));
setlength(s,l);
read (s[1],l);
SetGridCell('评论',s,i);
end;
p1:=11;
//Read 最爱
read (l,sizeof(Integer));
p1:=111;
Setlength(s,l);
p1:=112;
read (s[1],l);
p1:=113;
SetGridCell('最爱',s,i);
p1:=22;
//Read 歌词文件
read (l,sizeof(Integer));
Setlength(s,l);
read (s[1],l);
SetGridCell('歌词文件',s,i);
//Read 标记信息
read (l,sizeof(Integer));
Setlength(s,l);
read (s[1],l);
SetGridCell('标记',s,i);
end;
p1:=33;
result:=true;
except
if p1=1 then
begin
showinformation(' ReadList:因功能上的升级,与老版本列表文件 【'+GetPlaylstPath+aname +'】 不兼容!'
+#13+'请您 【将其 删除 或 移到其他地方】 即可,谢谢合作!'
+#13#13 +' 如有疑问,请与我们联系:wangxwabc@tom.com 或 QQ:375771206' );
end
else
begin
showinformation(' ReadList:'+inttostr(p1)+' 列表:'+sname+' 文件:'+aname
+#13#13+'因功能上的升级,与老版本产生了冲突!'
+#13#13+'如有疑问,请与我们联系:wangxwabc@tom.com 或 QQ:375771206' );
end;
application.Terminate;
end;
finally
free;
if (p1=1) and answer then
begin
deletefile(GetPlaylstPath+aName);
end;
{ if (result=false) and (p1=1) then
begin
deletefile(GetPlaylstPath+ aName);
DelListMnuClick(dellistmnu);
self.BringToFront;
end;
}
end;
end;
end;
//===========================读取列表文件=============================