1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
le .h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "LMDBrowseDlg.hpp"
#include "LMDCustomComponent.hpp"
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
enum TCopyAction {AcSuspend,AcRelease,AcCancel,AcContinue};
class TForm1 : public TForm
{
__published: // Composants gérés par l'EDI
TPanel *Panel1;
TOpenDialog *Opd;
TLMDBrowseDlg *Browsedir;
TGroupBox *GroupBox1;
TButton *Button3;
TButton *Button2;
TProgressBar *Prb;
TLabeledEdit *LbSource;
TLabeledEdit *LbDest;
TLabeledEdit *LbFile;
TButton *BtCopy;
TButton *btAct;
TButton *btCancel;
TBevel *Bevel1;
void __fastcall BtCopyClick(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall btActClick(TObject *Sender);
void __fastcall btCancelClick(TObject *Sender);
private: // Déclarations de l'utilisateur
AnsiString SourceFile;
AnsiString DestFolder;
AnsiString FileName;
AnsiString DestFile;
void __fastcall ClearEntry();
public: // Déclarations de l'utilisateur
__fastcall TForm1(TComponent* Owner);
TCopyAction FAction;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
le .cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "LMDBrowseDlg"
#pragma link "LMDCustomComponent"
#pragma resource "*.dfm"
TForm1 *Form1;
int CanInterupt=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ClearEntry();
}
//---------------------------------------------------------------------------
DWORD __stdcall CopyProgressRoutine(
LARGE_INTEGER TotalFileSize, // total file size, in bytes
LARGE_INTEGER TotalBytesTransferred, // total number of bytes transferred
LARGE_INTEGER StreamSize, // total number of bytes for this stream
LARGE_INTEGER StreamBytesTransferred, // total number of bytes transferred for this stream
DWORD dwStreamNumber, // the current stream
DWORD dwCallbackReason, // reason for callback
HANDLE hSourceFile, // handle to the source file
HANDLE hDestinationFile, // handle to the destination file
LPVOID lpData) // passed by CopyFileEx
{
unsigned long ReturnValue;
Application->ProcessMessages();
Form1->Prb->Max=TotalFileSize.QuadPart;
Form1->Prb->Position=TotalBytesTransferred.QuadPart;
if(TotalBytesTransferred.QuadPart>=TotalFileSize.QuadPart)
Form1->Prb->Position=0;
switch (Form1->FAction)
{
case AcCancel:
Form1->Prb->Position=0;
ReturnValue=PROGRESS_CANCEL;
break;
case AcContinue:
ReturnValue= PROGRESS_CONTINUE;
break;
case AcRelease:
Form1->Prb->Position=0;
ReturnValue= PROGRESS_QUIET;
break;
case AcSuspend:
Form1->Prb->Position=0;
ReturnValue= PROGRESS_STOP;
break;
}
return ReturnValue;
}
void __fastcall TForm1::BtCopyClick(TObject *Sender)
{
if(LbFile->Text.IsEmpty())
{
MessageDlg("Le Fichier de destination ne doit pas être vide", mtError, TMsgDlgButtons() << mbOK, 0);
LbFile->SetFocus();
return;
}
if (SourceFile.IsEmpty())
{
MessageDlg("Veuillez indiquez le fichier source", mtError, TMsgDlgButtons() << mbOK, 0);
LbSource->SetFocus();
return;
}
if (DestFolder.IsEmpty())
{
MessageDlg("Veuillez indiquez le directory de destination", mtError, TMsgDlgButtons() << mbOK, 0);
LbDest->SetFocus();
return;
}
DestFile=DestFolder;
DestFile+="\\";
DestFile+=LbFile->Text;
FAction=AcContinue;
if(CopyFileEx(SourceFile.c_str(),
DestFile.c_str(),
CopyProgressRoutine,
NULL,
&CanInterupt,
COPY_FILE_RESTARTABLE ))ClearEntry();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(Opd->Execute())
SourceFile=Opd->FileName;
LbSource->Text=SourceFile;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(Browsedir->Execute())
DestFolder=Browsedir->SelectedFolder;
LbDest->Text=DestFolder;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClearEntry()
{
LbFile->Text=""; //TODO: Add your source code here
LbSource->Text="";
LbDest->Text="";
SourceFile="";
DestFolder="";
FileName="";
DestFile="";
FAction=AcContinue;
BtCopy->Caption="Copier";
}
void __fastcall TForm1::btActClick(TObject *Sender)
{
FAction=AcSuspend;
BtCopy->Caption="Reprendre";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btCancelClick(TObject *Sender)
{
FAction=AcCancel;
ClearEntry();
}
//---------------------------------------------------------------------------
le .dfm
object Form1: TForm1
Left = 314
Top = 246
Width = 689
Height = 291
AutoSize = True
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 681
Height = 257
TabOrder = 0
object GroupBox1: TGroupBox
Left = 1
Top = 1
Width = 672
Height = 240
TabOrder = 0
object Bevel1: TBevel
Left = 0
Top = 176
Width = 673
Height = 50
Shape = bsTopLine
end
object LbSource: TLabeledEdit
Left = 3
Top = 24
Width = 505
Height = 21
EditLabel.Width = 50
EditLabel.Height = 13
EditLabel.Caption = 'SourceFile'
EditLabel.Color = clBtnFace
EditLabel.ParentColor = False
LabelPosition = lpAbove
LabelSpacing = 3
TabOrder = 0
end
object LbDest: TLabeledEdit
Left = 4
Top = 64
Width = 505
Height = 21
EditLabel.Width = 98
EditLabel.Height = 13
EditLabel.Caption = 'Destination Directory'
LabelPosition = lpAbove
LabelSpacing = 3
TabOrder = 1
end
object LbFile: TLabeledEdit
Left = 6
Top = 102
Width = 225
Height = 21
EditLabel.Width = 44
EditLabel.Height = 13
EditLabel.Caption = 'FileName'
LabelPosition = lpAbove
LabelSpacing = 3
TabOrder = 2
end
end
end
object Button3: TButton
Left = 512
Top = 64
Width = 25
Height = 25
BiDiMode = bdLeftToRight
Caption = '. . .'
ParentBiDiMode = False
TabOrder = 1
OnClick = Button3Click
end
object Button2: TButton
Left = 512
Top = 24
Width = 25
Height = 25
BiDiMode = bdLeftToRight
Caption = '. . .'
ParentBiDiMode = False
TabOrder = 2
OnClick = Button2Click
end
object Prb: TProgressBar
Left = 8
Top = 136
Width = 633
Height = 25
Min = 0
Max = 100
TabOrder = 3
end
object BtCopy: TButton
Left = 96
Top = 200
Width = 75
Height = 25
Caption = 'Copier'
TabOrder = 4
OnClick = BtCopyClick
end
object btAct: TButton
Left = 264
Top = 200
Width = 75
Height = 25
Caption = 'Suspendre'
TabOrder = 5
OnClick = btActClick
end
object btCancel: TButton
Left = 408
Top = 200
Width = 75
Height = 25
Caption = 'Annuler'
TabOrder = 6
OnClick = btCancelClick
end
object Opd: TOpenDialog
Left = 592
Top = 8
end
object Browsedir: TLMDBrowseDlg
Left = 624
Top = 8
end
end |
Partager