如何显示文件复制进度条(50分)

  • 主题发起人 主题发起人 唐纳王
  • 开始时间 开始时间

唐纳王

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在Windows98上实现显示文件复制的进度条?
 
SHFileOperation好像可以。
 
用SHFileOperation查找, 我记得以前我把它的解释译成中文了.
 
D5中不是有自带的吗?[8D]
 
我用的是B4
 
很抱歉,我写错了:我用的是D4.
 
如何得到SHFileOperation?
 
MSDN或者Delphi5 Help中的MS SDK Help Files/Win32s Programmer's Reference<br><br>SHFileOperation<br>Copies, moves, renames, or deletes a file system object. <br><br>int SHFileOperation(<br>&nbsp; &nbsp; LPSHFILEOPSTRUCT lpFileOp<br>);<br><br>Parameters<br>lpFileOp <br>[in] Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation. This parameter must contain a valid value that is not NULL. You are responsibile for validating the value. If you do not validate it, you will experience unexpected results. <br>Return Values<br>Returns zero if successful, or nonzero otherwise.
 
D4下应该也是可以的<br>Requirements <br>&nbsp; Version 4.00 and later of Shell32.dll<br><br>&nbsp; Windows NT/2000: Requires Windows NT 4.0 or later. <br>&nbsp; Windows 95/98/Me: Requires Windows 95 or later. <br>&nbsp; Header: Declared in Shellapi.h. <br>&nbsp; Import Library: Shell32.lib.
 
用文件流来操作
 
我来给你答案吧。<br>你需要在窗体上加个TProgressBar控件<br>Procedure TForm1.CopyFileWithProgressBar(Source,Destination : string);<br><br>var<br><br>FromF,ToF : file of byte;<br><br>Buffer : array[0..4096] of char;<br><br>NumRead : integer;<br><br>FileLength : longint;<br><br><br>begin<br><br>AssignFile(FromF,Source);<br><br>reset(FromF);<br><br>AssignFile(ToF,Destination);<br><br>rewrite(ToF);<br><br>FileLength:=FileSize(FromF);<br><br>With Progressbar1 do<br><br>begin<br><br>Min := 0;<br><br>Max := FileLength;<br><br>while FileLength &gt; 0 do<br><br>begin<br><br>BlockRead(FromF,Buffer[0],SizeOf(Buffer),NumRead);<br><br>FileLength := FileLength - NumRead;<br><br>BlockWrite(ToF,Buffer[0],NumRead);<br><br>Position := Position + NumRead;<br><br>end;<br><br>CloseFile(FromF);<br><br>CloseFile(ToF);<br><br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br><br>begin<br><br>CopyFileWithProgressBar('c:/Windows/Welcome.exe','c:/temp/Welcome.exe');<br><br>end;<br>
 
多人接受答案了。
 
后退
顶部