全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2047
推到 Plurk!
推到 Facebook!

複製檔案時有動畫及進度百分比的函式

 
kwu
中階會員


發表:10
回覆:57
積分:58
註冊:2003-10-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-02-20 18:28:28 IP:61.63.xxx.xxx 未訂閱
使用時只要呼叫此函式會動態產生 Form 若有寫得不好的地方,還請多多包涵及指教    
//請引入下列兩個標頭檔

#include 
#include "CGAUGES.h"    bool __fastcall CopyFileAni(AnsiString SourFileName,AnsiString DestFileName)
{
  const int MaxReadSize = 1024;
  int i,Count;
  int SourFileHandle,DestFileHandle;
  int FileLength;
  int ReadByte,WriteByte;
  char buf[MaxReadSize];
  bool Success = true;
  AnsiString SourDir,DestDir;      SourFileHandle = FileOpen(SourFileName,fmOpenRead);
  if(SourFileHandle == -1)
    return(false);      DestFileHandle = FileCreate(DestFileName);
  if(DestFileHandle == -1)
    return(false);      TForm *frm = new TForm(Application);
  frm->Width = 380;
  frm->Height = 151;
  frm->BorderStyle = bsDialog;
  frm->Caption = "正在複製...";
  frm->BorderIcons.Clear();
  frm->Position = poMainFormCenter;
  frm->FormStyle = fsStayOnTop;      TAnimate *ani = new TAnimate(frm);
  ani->Parent = frm;
  ani->Width = 370;
  ani->Height = 50;
  ani->Top = 0;
  ani->Left = 15;
  ani->CommonAVI = aviCopyFile;
  ani->Active = true;      TLabel *lblFileName = new TLabel(frm);
  lblFileName->Parent = frm;
  lblFileName->Top = 60;
  lblFileName->Left = 15;
  lblFileName->Caption = ExtractFileName(SourFileName);
  lblFileName->Width = 370;      TLabel *lblPath = new TLabel(frm);
  lblPath->Parent = frm;
  lblPath->Top = 80;
  lblPath->Left = 15;
  SourDir = ExtractFileDir(SourFileName);
  if(SourDir.Length() == 3)
    SourDir = SourDir.UpperCase();
  else
    SourDir = SourDir.SubString(SourDir.LastDelimiter("\\")   1,SourDir.Length());
  DestDir = ExtractFileDir(DestFileName);
  if(DestDir.Length() == 3)
    DestDir= DestDir.UpperCase();
  else
    DestDir = DestDir.SubString(DestDir.LastDelimiter("\\")   1,DestDir.Length());
  lblPath->Caption = "從【"   SourDir   "】到【"   DestDir   "】";
  lblPath->Width = 370;      TCGauge *gag = new TCGauge(frm);
  gag->Parent = frm;
  gag->Width = 343;
  gag->Height = 13;
  gag->Top = 103;
  gag->Left = 15;
  gag->ForeColor = clNavy;      frm->Show();      Application->ProcessMessages();      FileLength = FileSeek(SourFileHandle,0,2);  //end of file
  FileSeek(SourFileHandle,0,0);               //begin of file
  Count = FileLength / MaxReadSize;
  if(FileLength % MaxReadSize != 0)
    Count  ;      gag->MaxValue = Count;      for(i = 0; i < Count; i  )
  {
    ReadByte = FileRead(SourFileHandle,buf,MaxReadSize);
    WriteByte = FileWrite(DestFileHandle,buf,ReadByte);        if(ReadByte != WriteByte)
    {
      Success = false;
      break;
    }        gag->Progress = i   1;
  }      FileClose(SourFileHandle);
  FileClose(DestFileHandle);      if(Success)
  {  //複製成功時將來源檔案修改日期,寫入目的檔案修改日期
    int FileHandle = FileOpen(SourFileName,fmOpenRead);
    TDateTime FileDateTime = FileDateToDateTime(FileGetDate(FileHandle));
    FileClose(FileHandle);        DestFileHandle = FileOpen(DestFileName,fmOpenWrite);
    int iDateTime = DateTimeToFileDate(FileDateTime);
    FileSetDate(DestFileHandle,iDateTime);
    FileClose(DestFileHandle);
  }      frm->Close();      delete frm,ani,lblFileName,lblPath,gag;      return(Success);
}
發表人 - kwu 於 2004/02/21 00:59:40
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-02-21 09:43:05 IP:61.221.xxx.xxx 未訂閱
報告 請問 那類似這種的 【JAVA】【分享】Merlin 的魔力-不確定的進度條 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=44638 http://www-900.ibm.com/developerWorks/cn/java/j-mer11183/ kwu 兄是否 也能說明一下
kwu
中階會員


發表:10
回覆:57
積分:58
註冊:2003-10-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-02-23 08:53:04 IP:61.63.xxx.xxx 未訂閱
引言: 報告 請問 那類似這種的 【JAVA】【分享】Merlin 的魔力-不確定的進度條 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=44638 http://www-900.ibm.com/developerWorks/cn/java/j-mer11183/ kwu 兄是否 也能說明一下
conundrum你好: 我對 Java 不是很熟,所以可能無法做說明,不好意思!
China Join
中階會員


發表:81
回覆:242
積分:89
註冊:2003-03-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-04 15:54:57 IP:210.66.xxx.xxx 未訂閱
Hello: 呵呵,寫得很不錯喔!不過小弟測試複製超過 2 G 的資料時會出錯ㄟ ^^" ~ 學得越多,懂得越少 ~
fink003
一般會員


發表:0
回覆:1
積分:0
註冊:2005-04-19

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-05-06 16:30:03 IP:60.248.xxx.xxx 未訂閱
各位大大你好,我是新手,我不知如何呼叫此函數
系統時間:2024-05-15 12:03:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!