我想做个安装程序,用到进度条,但我想进度条能根据要copy文件的数量和大小来显示完成,以前我用都是用timer控件,如何实现我讲的功能,也就是说如何能得到文件数量和大小,能给出一段代码马?

解决方案 »

  1.   

    BOOL CopyFileEx(
      LPCTSTR lpExistingFileName,
      LPCTSTR lpNewFileName,
      LPPROGRESS_ROUTINE lpProgressRoutine,
      LPVOID lpData,
      LPBOOL pbCancel,
      DWORD dwCopyFlags
    );lpProgressRoutine 
    [in] Address of a callback function of type LPPROGRESS_ROUTINE that is called each time another portion of the file has been copied. This parameter can be NULL. For more information on the progress callback function, see CopyProgressRoutine. 
      

  2.   

    也可試下如下代碼:Source and Dest are both a list of files separated with #0, for exampleWinCopyFile('c:\1.txt' + #0 + 'c:\2.txt', 'a:\1.txt' + #0 + 'a:\2.txt');function WinCopyFile(Source, Dest: string): Boolean;
    var
       Struct : TSHFileOpStruct;
       Resultval: integer;
    begin
       ResultVal := 1;
       try
         Source := Source + #0#0;
         Dest := Dest + #0#0;
         Struct.wnd := 0;
         Struct.wFunc := FO_COPY;
         Struct.pFrom := PChar(Source);
         Struct.pTo := PChar(Dest);
         Struct.fFlags:= FOF_SIMPLEPROGRESS or FOF_NOERRORUI or FOF_NOCONFIRMATION;
         Struct.fAnyOperationsAborted := False;
         Struct.hNameMappings := nil;
         Resultval := ShFileOperation(Struct);
       finally
         Result := (Resultval = 0);
      end;
    end;
      

  3.   

    http://www.swissdelphicenter.ch/torry/showcode.php?id=330提供了四種解決方法