⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filetrans.cpp

📁 用于开发Atmel的AVR系列单片机的GCC集成开发环境
💻 CPP
字号:
/**************************************************************************
Project: WinAVRIDE        Class: File Transfer Dialog
Copyright (C) 2005  Philipp Schober

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

History
19.Feb 2005 - First Release (V1.0)
****************************************************************************/

#include <vcl.h>
#pragma hdrstop

#include "FileTrans.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TTransDlg *TransDlg;
//---------------------------------------------------------------------------
__fastcall TTransDlg::TTransDlg(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TTransDlg::TransmitFile (TRS232Comm *com, AnsiString filename)
{
 Comm = com;
 readstream = new TFileStream(filename, fmOpenRead | fmShareExclusive);
 if (readstream->Handle == NULL)
 {
  Application->MessageBox ("Can't open File", "Error", MB_OK);
  return;
 }
 StopTransmission = false;
 TransDlg->Button1->Kind = bkCancel;
 TransDlg->Button1->Caption = "Cancel";
 ActLabel->Caption = "Transmitting : " + ExtractFileName (filename);
 Timer1->Enabled = true;
 ShowModal ();
}
//---------------------------------------------------------------------------
void __fastcall TTransDlg::Button1Click(TObject *Sender)
{
 if (StopTransmission == true) ModalResult = mrOk;
 StopTransmission = true;
}
//---------------------------------------------------------------------------
void __fastcall TTransDlg::Timer1Timer(TObject *Sender)
{
 char buf[11];
 int i, bytes, position;

 Timer1->Enabled = false;
 if (readstream == NULL) return;
 while (1)
 {
  Application->ProcessMessages ();
  bytes = readstream->Size - readstream->Position;
  position = ((double)100 / (double)readstream->Size) * (double)readstream->Position;
  TransDlg->Progress->Position = position;
  if (bytes == 0 || StopTransmission)
  {
   delete readstream;
   readstream = NULL;
   TransDlg->Button1->Kind = bkOK;
   TransDlg->Button1->Caption = "OK";
   StopTransmission = true;
   if (bytes != 0) ModalResult = mrCancel;
   break;
  }
  else if (bytes < 10)
  {
   readstream->Read (buf, bytes);
   buf[bytes] = 0;
   Comm->Write (buf, strlen(buf));
  }
  else
  {
   readstream->Read (buf, 10);
   buf[10] = 0;
   Comm->Write (buf, strlen(buf));
  }
 }
 ActLabel->Caption = "Done";
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -