Home > Back-end >  How to combine the Progress bar the SHFileOperation function get Progress value
How to combine the Progress bar the SHFileOperation function get Progress value

Time:09-16

 procedure TForm1. Btn1Click (Sender: TObject); 
Var
S1, s2: string;
The begin
S1:=edt1. Text;
S2:=edt2. Text;
If CopyAllFile (s1, s2)=0 then ShowMessage (' copy success);


end;

The function TForm1. CopyAllFile (str1, str2: string) : Integer;
Var
MyStruct: TSHFileOpStruct;
The begin
With MyStruct do
The begin
Wnd:=Application. Handle;
WFunc:=FO_COPY;
PFrom:=PWideChar (# str1 + 0);
Office:=PWideChar (str2 + # 0);
FFlags:=FOF_NOCONFIRMATION or FOF_SIMPLEPROGRESS;
FAnyOperationsAborted:=false;
HNameMappings:=nil;
LpszProgressTitle:=nil;
end;
Result:=SHFileOperation (MyStruct);
end;



copy the whole folder example of above is my writing, but I'd like to add a TProgress in my window controls the progress bar, the SHFileOperation this function in the process of how to obtain replication schedule value, if the value is 0-100, a progress bar that how to combine SHFileOperation this function to obtain the corresponding numerical? Have no idea, hope the great god directions under the

CodePudding user response:

Another consideration, copying files can show an Animate file copying animation,

CodePudding user response:

The Animate file copying animation not good-looking, I just want a progress bar display

CodePudding user response:

First column contains a table to copy all the files, and then file a copy one, according to the number of replicated file or MB number change progress bar,

CodePudding user response:

Two way
1, if access to the file length, by calculating the value of percentage, showing the Progress bar
2, start copying files will show a dynamic Progress bar, copy finished, close the Progress bar, repeatedly Progress from 0-100, according to

In addition, through a thread to replicate and display the Progress bar, otherwise, the VCL control and looks, there will be a "waiting for" stop state,

CodePudding user response:

A lot of time to make a progress bar is not accurate, such as the download file at the time of the download can't know the total size, cannot know the percentage of the precise or schedule, you can set a range, roughly in the closing of operation after completion of the progress bar.

CodePudding user response:

1. The first search to copy all files, file size, addition amount, then call cycle CopyFileEx copy every file, this API supports the callback, in which processing progress,
2, use IFileOperation interface, support the callback, the disadvantage is that requires the Vista +, XP,
  • Related