给你一段我写的代码,比较完整。 准备工作和申明参加代码猎手的。procedure TfrmMain.HandleDropedFile(var Msg:TMessage); var hDrop:THandle; strFile:string; i, iBufSize, iCharCount,iFileCount:integer; begin hDrop:=Msg.WParam; SetLength(strFile,255); iCharCount:=0; iFileCount:=DragQueryFile(hDrop,$ffffffff,pchar(strFile),iCharCount); for i:=0 to iFileCount-1 do begin iBufSize:=DragQueryFile(hDrop,i,nil,iCharCount); SetLength(strFile,iBufSize+1); iCharCount:=DragQueryFile(hDrop,i,pchar(strFile),iBufSize+1); clbSource.Items.Add(strFile);//这是一个列表框 end; DragFinish(hDrop); Msg.Result:=0; end;
http://www.playicq.com/dispdocnew.php?id=3231还可以自己写文件拖放到 Form 的实现如下:
在 TForm1.Create 中加入一句:
DragAcceptFiles(Self.Handle,Enabled);
让它接受拖放操作,然后使这个 Form 能够解释拖放内容:
procedure DropFiles(var Msg:TMessage);message WM_DROPFILES;
对消息进行查询就可以知道文件数和文件名:
DragQueryFile(Msg.WParam,$FFFFFFFF,@FileName,256);// 第一次调用得到拖放文件的个数
DragQueryFile(msg.WParam,i,@FileName,256);// 第二次调用得到文件名称
将得到的文件名称送入你的播放器进行播放。
给你一段我写的代码,比较完整。
准备工作和申明参加代码猎手的。procedure TfrmMain.HandleDropedFile(var Msg:TMessage);
var
hDrop:THandle;
strFile:string;
i, iBufSize, iCharCount,iFileCount:integer;
begin
hDrop:=Msg.WParam;
SetLength(strFile,255);
iCharCount:=0;
iFileCount:=DragQueryFile(hDrop,$ffffffff,pchar(strFile),iCharCount);
for i:=0 to iFileCount-1 do begin
iBufSize:=DragQueryFile(hDrop,i,nil,iCharCount);
SetLength(strFile,iBufSize+1);
iCharCount:=DragQueryFile(hDrop,i,pchar(strFile),iBufSize+1);
clbSource.Items.Add(strFile);//这是一个列表框
end;
DragFinish(hDrop);
Msg.Result:=0;
end;