我知道FileCopy
函数可用于复制[Code]
部分中的文件,这对大多数用途都有效。但是,有没有办法调用本机Windows文件复制操作,以便显示带有进度,剩余时间等的标准Windows文件复制对话框(即与执行Ctrl+C
相同,然后是Ctrl+V
),这还将允许用户在进程中取消或暂停复制操作?或者,更好的是,有没有办法直接在[Code]
部分复制类似的功能?
答案 0 :(得分:1)
将SHFileOperation
与FO_COPY
:
type
TSHFileOpStruct = record
hwnd: HWND;
wFunc: UINT;
pFrom: string;
pTo: string;
fFlags: Word;
fAnyOperationsAborted: BOOL;
hNameMappings: HWND;
lpszProgressTitle: string;
end;
const
FO_COPY = $0002;
FOF_NOCONFIRMATION = $0010;
function SHFileOperation(lpFileOp: TSHFileOpStruct): Integer;
external 'SHFileOperationW@shell32.dll stdcall';
procedure ShellCopyFile;
var
FromPath: string;
ToPath: string;
FileOp: TSHFileOpStruct;
begin
FromPath :=
ExpandConstant('{src}\data1.dat') + #0 +
ExpandConstant('{src}\data2.dat') + #0;
ToPath := ExpandConstant('{app}') + #0;
FileOp.hwnd := WizardForm.Handle;
FileOp.wFunc := FO_COPY;
FileOp.pFrom := FromPath;
FileOp.pTo := ToPath;
FileOp.fFlags := FOF_NOCONFIRMATION;
if SHFileOperation(FileOp) <> 0 then
begin
MsgBox('Copying failed.', mbError, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ShellCopyFile;
end;
end;
该代码适用于Inno Setup的Unicode版本。