Registriert seit: 16. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
Delphi 2007 Professional
|
Re: Problem mit CopyFileEx
27. Sep 2008, 21:59
Hier eine kleine Verbesserung: der Parameter lpData wird benützt um sich vom Formular unabhängig zu machen.
Delphi-Quellcode:
function CopyFileProgress(TotalFileSize, TotalBytesTransferred, StreamSize,
StreamBytesTransferred: LARGE_INTEGER; dwStreamNumber, dwCallbackReason,
hSourceFile, hDestinationFile, lpData: DWORD): DWORD; stdcall;
var
pb : TProgressBar;
begin
pb := TProgressBar(lpdata); // <===
Application.ProcessMessages;
if CancelCopy then
begin
ShowMessage('Abbruch');
result := PROGRESS_CANCEL;
pb.Position := 0;
Exit;
end
else
Application.ProcessMessages;
case dwCallbackReason of
CALLBACK_CHUNK_FINISHED:
begin
pb.Position := TotalBytesTransferred.QuadPart;
result := PROGRESS_CONTINUE;
end;
CALLBACK_STREAM_SWITCH:
begin
pb.Max := TotalFileSize.QuadPart;
result := PROGRESS_CONTINUE;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Cancel: PBOOL;
begin
CancelCopy := False;
Cancel := nil;
CopyFileEx('C:\aaa.exe', 'D:\aaa.exe',
@CopyFileProgress, Pointer(ProgressBar1), Cancel, 0);
ProgressBar1.Position := 0;
end;
|
|
Zitat
|