Inno Setup调用或复制本机Windows文件复制操作

时间:2017-07-21 18:13:20

标签: inno-setup pascalscript

我知道FileCopy函数可用于复制[Code]部分中的文件,这对大多数用途都有效。但是,有没有办法调用本机Windows文件复制操作,以便显示带有进度,剩余时间等的标准Windows文件复制对话框(即与执行Ctrl+C相同,然后是Ctrl+V ),这还将允许用户在进程中取消或暂停复制操作?或者,更好的是,有没有办法直接在[Code]部分复制类似的功能?

1 个答案:

答案 0 :(得分:1)

SHFileOperationFO_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版本。

enter image description here