Ir al contenido


Foto

Copiar archivos con CopyFileEx


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 07 julio 2010 - 09:35

Un ejemplo sencillo en Builder para copiar archivos con la API CopyFileEx, una barra de progreso, un botón de inicio y un botón de cancelación.


cpp
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11.  
  12. int  Cancel;
  13. DWORD CALLBACK ProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, void* lpData)
  14. {
  15.   int Value;
  16.   Application->ProcessMessages();
  17.   if(dwCallbackReason == CALLBACK_CHUNK_FINISHED)
  18.       Form1->ProgressBar1->Position = ((*(__int64*)&TotalBytesTransferred) * 100) / (*(__int64*)&TotalFileSize);
  19.  
  20.   return PROGRESS_CONTINUE;
  21. }
  22.  
  23. //---------------------------------------------------------------------------
  24. __fastcall TForm1::TForm1(TComponent* Owner)
  25.         : TForm(Owner)
  26. {
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::Button1Click(TObject *Sender)
  30. {
  31.   Cancel = false;
  32.   CopyFileEx("Mi archivo fuente", "Mi archivo destino", ProgressRoutine, NULL, &Cancel, 0);
  33.   ShowMessage(SysErrorMessage(GetLastError()));
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::Button2Click(TObject *Sender)
  37. {
  38.   Cancel = true;
  39. }
  40. //---------------------------------------------------------------------------

También en delphi

Saludos.
  • 0




IP.Board spam blocked by CleanTalk.