曾经做过类似的程序功能,共享一下!!!!
在窗口初始化中
//设置需要处理文件WM_DROPFILES拖放消息
DragAcceptFiles(ListBox1.Handle, TRUE);
//设置AppMessage过程来捕获所有消息
Application.OnMessage := AppMessage;
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
nFiles, UpI: Integer;
UpFilename: string;
begin
if (Msg.message = WM_DROPFILES) and (msg.hwnd = ListBox1.Handle) then
begin
nFiles := DragQueryFile (Msg.wParam, $FFFFFFFF, nil, 0);
try
for UpI := 0 to nFiles - 1 do
begin
SetLength (UPFilename, 80);
DragQueryFile (Msg.wParam, UpI, PChar (UpFilename), 80);
UPFilename := PChar (UpFilename);
showmessage(upfilename);
end;
finally
DragFinish (Msg.wParam);
end;
Handled := True;
end;
end;