Chilkat • HOME • Android™ • Classic ASP • C • C++ • C# • Mono C# • .NET Core C# • C# UWP/WinRT • DataFlex • Delphi ActiveX • Delphi DLL • Visual FoxPro • Java • Lianja • MFC • Objective-C • Perl • PHP ActiveX • PHP Extension • PowerBuilder • PowerShell • PureBasic • CkPython • Chilkat2-Python • Ruby • SQL Server • Swift 2 • Swift 3,4,5... • Tcl • Unicode C • Unicode C++ • Visual Basic 6.0 • VB.NET • VB.NET UWP/WinRT • VBScript • Xojo Plugin • Node.js • Excel • Go
(MFC) HTTP Download with Progress Event CallbacksDownloads a file via HTTP or HTTPS and uses event callbacks to monitor progress.
#include <CkHttp.h> #include <CkHttpProgress.h> class httpProgress : public CkHttpProgress { public: httpProgress() { } virtual ~httpProgress() { } void AbortCheck(bool *abort) { // Application code goes here. } void PercentDone(int percentDone, bool *abort) { strOut.append("Percent Done: "); strOut.appendInt(percentDone); strOut.append("\r\n"); // Explicitly abort at 25% or greater. // Remove this to allow for the HTTP download to run to completion. if (percentDone > 25) { *abort = true; } } void ProgressInfo(const char *name, const char *value) { strOut.append(name); strOut.append(": "); strOut.append(value); strOut.append("\r\n"); } }; void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; httpProgress http_progress; http.put_EventCallbackObject(&http_progress); // Set a heartbeat in milliseconds http.put_HeartbeatMs(200); // Download a file... const char *localFilePath = "qa_output/Python-3.4.4.tar.xz"; bool success = http.Download("https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tar.xz",localFilePath); if (success != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("OK!"); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.