📄 download.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "Download.h"
#include "_SFT.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmDownload *frmDownload;
extern char MachineName[128];
extern int FileCount;
extern long TotalSize;
extern int TotalProgress;
extern char CurrentFile[128];
extern char CurrentFileSaveAs[128];
extern long CurrentSize;
extern int CurrentProgress;
extern int Stop;
bool Downloading;
bool DownloadStop;
extern bool Uploading;
extern bool UploadStop;
extern int ReceiveResult;
extern char ReceiveResultMsg[128];
bool DownloadManualCancel;
DWORD DownloadThreadID;
HANDLE DownloadThread;
DWORD WINAPI Download( LPVOID param)
{
Uploading=false;
Downloading=true;
DownloadStop=false;
DownloadManualCancel=false;
SFT_ReceiveFiles("",-1,NULL);
return 0;
}
//---------------------------------------------------------------------------
__fastcall TfrmDownload::TfrmDownload(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TfrmDownload::RefreshDisplay(void)
{
LabelMachineName->Caption = MachineName;
LabelFileCount->Caption = FileCount;
LabelTotalSize->Caption = TotalSize;
LabelTotalProgress->Caption= TotalProgress;
if( TotalSize==0 )ProgressTotalProgress->Position = 0;
else ProgressTotalProgress->Position = TotalProgress*100L/TotalSize;
LabelCurrentFile->Caption = CurrentFile;
LabelCurrentFileSaveAs->Caption = CurrentFileSaveAs;
LabelCurrentSize->Caption = CurrentSize;
LabelCurrentProgress->Caption = CurrentProgress;
if( CurrentSize==0 )ProgressCurrentProgress->Position = 0;
else ProgressCurrentProgress->Position = CurrentProgress*100L/CurrentSize;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDownload::SpeedButton1Click(TObject *Sender)
{
DownloadManualCancel=true;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmDownload::FormClose(TObject *Sender,
TCloseAction &Action)
{
unsigned long code;
DownloadStop=true;
if( GetExitCodeThread(DownloadThread,&code) )
{
if( code == STILL_ACTIVE ){ Action = caNone;return; };
}
Downloading=false;
if( DownloadManualCancel==true ){ frmMain->CheckBox3->Checked = false; }
if( ReceiveResult&&DownloadManualCancel==false ){ ReceiveResult=0;Application->MessageBox(ReceiveResultMsg,"错误",MB_ICONERROR|MB_OK); };
Timer1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDownload::FormShow(TObject *Sender)
{
strcpy(MachineName,"");
FileCount=0;
TotalSize=0;
TotalProgress=0;
strcpy(CurrentFile,"");
strcpy(CurrentFileSaveAs,"");
CurrentSize=0;
CurrentProgress=0;
Timer1->Enabled = true;
DownloadThread=CreateThread(NULL,0,Download,NULL,0,&DownloadThreadID);
}
//---------------------------------------------------------------------------
void __fastcall TfrmDownload::Timer1Timer(TObject *Sender)
{
unsigned long code;
RefreshDisplay();
if( GetExitCodeThread(DownloadThread,&code) )
{
if( code != STILL_ACTIVE ){ Close(); };
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -