使用時只要呼叫此函式會動態產生 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