Vista下CopyFileEx进度条问题(20分)

F

formiss

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, ComCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ProgressBar1: TProgressBar;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>function CopyProgress(<br>&nbsp; TotalFileSize &nbsp; &nbsp; &nbsp; &nbsp; : LARGE_INTEGER; &nbsp;// total file size, in bytes<br>&nbsp; TotalBytesTransferred : LARGE_INTEGER; &nbsp;// total number of bytes transferred<br>&nbsp; StreamSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: LARGE_INTEGER; &nbsp;// total number of bytes for this stream<br>&nbsp; StreamBytesTransferred: LARGE_INTEGER; &nbsp;// total number of bytes transferred for this stream<br>&nbsp; dwStreamNumber &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// the current stream<br>&nbsp; dwCallbackReason &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// reason for callback<br>&nbsp; hSourceFile &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : THANDLE; &nbsp; &nbsp; &nbsp; &nbsp;// handle to the source file<br>&nbsp; hDestinationFile &nbsp; &nbsp; &nbsp;: THANDLE; &nbsp; &nbsp; &nbsp; &nbsp;// handle to the destination file<br>&nbsp; lpData &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Pointer &nbsp; &nbsp; &nbsp; &nbsp; // passed by CopyFileEx<br>&nbsp; ) : DWORD; stdcall;<br>var<br>&nbsp; S : String;<br>begin<br>&nbsp; Form1.ProgressBar1.Position := Form1.ProgressBar1.Position+1;<br>end;<br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; Cancel &nbsp; &nbsp;: Bool;<br>&nbsp; Src, Dest : String;<br>&nbsp; hf : HFile;<br>&nbsp; ofs : OFSTRUCT;<br>&nbsp; size : Cardinal;<br>begin<br>&nbsp; Cancel := False;<br>&nbsp; Src := 'j:/[大富翁论坛离线资料].DelphiBBSchm.rar';<br>&nbsp; Dest:= 'e:/1.rar';<br>&nbsp; hf := OpenFile(PChar(src), ofs, 0);<br>&nbsp; size := GetFileSize(hf, nil);<br>// &nbsp;ShowMessage(IntToStr(size));<br>&nbsp; self.ProgressBar1.Max := (size shr 16)+2;<br>&nbsp; self.ProgressBar1.Position := 0;<br>&nbsp; _lclose(hf);<br>&nbsp; CopyFileEx(PChar(Src), PChar(Dest), @CopyProgress, nil, @Cancel,COPY_FILE_FAIL_IF_EXISTS)<br>end;<br><br>在winxp,2000,2003下都可以正确显示进度条。<br>在vista下,文件已经复制完成,而进度条却停留在某个位置不动了。<br><br><br>end.
 
奇怪的现象,加一句Application.ProcessMessages;试试看
 
顶部