UrlDownloadToFile mit ProgressBar
-
Hey
ich weiß nicht wie ich es hin bekomme, das ich den Fortschritt an das Gui übergebe. Bisher hat es noch nicht geklappt.
Vielleicht hat ja einer von euch ein Beispiel oder kann mir helfen, aus der Callback Funktion von URLDownloadToFile den Fortschritt an das UI zu senden.
Downloadcallback.h:#ifndef DownloadCallbackH #define DownloadCallbackH #include <urlmon.h> // URLDowbloadToFile #include <WinInet.h> // Delete Cache #include <shlwapi.h> // for StrFormatByteSize() #pragma comment(lib,"urlmon.lib") // URLDowbloadToFile #pragma comment(lib, "wininet.lib") // Delete Cache class DownloadCallback : public IBindStatusCallback { public: DownloadCallback(); ~DownloadCallback(); // This one is called by URLDownloadToFile // OnProgress Method! STDMETHOD(OnProgress)( /* [in] */ ULONG ulProgress, /* [in] */ ULONG ulProgressMax, /* [in] */ ULONG ulStatusCode, /* [in] */ LPCWSTR wszStatusText); // IBindStatusCallback methods. Note that the only method called by IE // is OnProgress(), so the others just return E_NOTIMPL. STDMETHOD(OnStartBinding)( /* [in] */ DWORD dwReserved, /* [in] */ IBinding __RPC_FAR *pib) { return E_NOTIMPL; } STDMETHOD(GetPriority)( /* [out] */ LONG __RPC_FAR *pnPriority) { return E_NOTIMPL; } STDMETHOD(OnLowResource)( /* [in] */ DWORD reserved) { return E_NOTIMPL; } STDMETHOD(OnStopBinding)( /* [in] */ HRESULT hresult, /* [unique][in] */ LPCWSTR szError) { return E_NOTIMPL; } STDMETHOD(GetBindInfo)( /* [out] */ DWORD __RPC_FAR *grfBINDF, /* [unique][out][in] */ BINDINFO __RPC_FAR *pbindinfo) { return E_NOTIMPL; } STDMETHOD(OnDataAvailable)( /* [in] */ DWORD grfBSCF, /* [in] */ DWORD dwSize, /* [in] */ FORMATETC __RPC_FAR *pformatetc, /* [in] */ STGMEDIUM __RPC_FAR *pstgmed) { return E_NOTIMPL; } STDMETHOD(OnObjectAvailable)( /* [in] */ REFIID riid, /* [iid_is][in] */ IUnknown __RPC_FAR *punk) { return E_NOTIMPL; } STDMETHOD_(ULONG, AddRef)() { return 0; } STDMETHOD_(ULONG, Release)() { return 0; } STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) { return E_NOTIMPL; } }; #endif
DownloadCallback.cpp:
DownloadCallback::DownloadCallback() { } DownloadCallback::~DownloadCallback() { } HRESULT DownloadCallback::OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR wszStatusText) { /*Patcher::MainForm main; main.progressBarAll->Maximum = ulProgressMax; main.progressBarAll->Value = ulProgress;*/ //cout << "Downloaded " << ulProgress << " of " << ulProgressMax << " byte(s), " << " Status Code = " << ulStatusCode << endl; return S_OK; }
MainForm.h:
#define _CRT_SECURE_NO_WARNINGS #include "config.h" #include "md5wrapper.h" #include "Patch.h" //#include "downloadcallback.h" //#include <iostream> //#include <string> //#include <climits> //#include <fstream> //#include <sys/types.h> //#include <sys/stat.h> //#include <stdio.h> //#include <sstream> //#include <shlobj.h> //#include <atlstr.h> //CString #include <algorithm> /*#include <urlmon.h> #include <WinInet.h> #pragma comment(lib,"urlmon.lib") #pragma comment(lib, "wininet.lib")*/ #pragma hdrstop using namespace std; #pragma once namespace Patcher { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::Threading; static string filePathForProgress; /// <summary> /// Zusammenfassung für MainForm /// </summary> public ref class MainForm : public System::Windows::Forms::Form { public: MainForm(void); /*{ InitializeComponent(); // //TODO: Konstruktorcode hier hinzufügen. // }*/ protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~MainForm() { if (components) { delete components; } } public: System::Windows::Forms::ProgressBar^ progressBarAll; protected: private: System::Windows::Forms::ProgressBar^ progressBarFile; private: System::Windows::Forms::Button^ btnPatch; private: System::Windows::Forms::RichTextBox^ richTextBox1; private: System::Windows::Forms::Label^ labFile; private: System::Windows::Forms::Timer^ timer1; private: System::Windows::Forms::Label^ label1; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Erforderliche Designervariable. /// </summary> #pragma region Windows Form Designer generated code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); this->progressBarAll = (gcnew System::Windows::Forms::ProgressBar()); this->progressBarFile = (gcnew System::Windows::Forms::ProgressBar()); this->btnPatch = (gcnew System::Windows::Forms::Button()); this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox()); this->labFile = (gcnew System::Windows::Forms::Label()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); this->label1 = (gcnew System::Windows::Forms::Label()); this->SuspendLayout(); // // progressBarAll // this->progressBarAll->Location = System::Drawing::Point(12, 147); this->progressBarAll->Name = L"progressBarAll"; this->progressBarAll->Size = System::Drawing::Size(421, 23); this->progressBarAll->TabIndex = 0; // // progressBarFile // this->progressBarFile->Location = System::Drawing::Point(12, 113); this->progressBarFile->Name = L"progressBarFile"; this->progressBarFile->Size = System::Drawing::Size(421, 23); this->progressBarFile->TabIndex = 1; // // btnPatch // this->btnPatch->Location = System::Drawing::Point(323, 44); this->btnPatch->Name = L"btnPatch"; this->btnPatch->Size = System::Drawing::Size(101, 33); this->btnPatch->TabIndex = 2; this->btnPatch->Text = L"Patchen"; this->btnPatch->UseVisualStyleBackColor = true; this->btnPatch->Click += gcnew System::EventHandler(this, &MainForm::button1_Click); // // richTextBox1 // this->richTextBox1->Location = System::Drawing::Point(13, 3); this->richTextBox1->Name = L"richTextBox1"; this->richTextBox1->Size = System::Drawing::Size(304, 74); this->richTextBox1->TabIndex = 3; this->richTextBox1->Text = L""; // // labFile // this->labFile->AutoSize = true; this->labFile->Location = System::Drawing::Point(12, 88); this->labFile->Name = L"labFile"; this->labFile->Size = System::Drawing::Size(12, 13); this->labFile->TabIndex = 4; this->labFile->Text = L"/"; // // timer1 // this->timer1->Enabled = true; this->timer1->Tick += gcnew System::EventHandler(this, &MainForm::timer1_Tick); // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(324, 13); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(35, 13); this->label1->TabIndex = 5; this->label1->Text = L"label1"; // // MainForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(445, 181); this->Controls->Add(this->label1); this->Controls->Add(this->labFile); this->Controls->Add(this->richTextBox1); this->Controls->Add(this->btnPatch); this->Controls->Add(this->progressBarFile); this->Controls->Add(this->progressBarAll); this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; this->MaximizeBox = false; this->Name = L"MainForm"; this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; this->Text = L"Patcher"; this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion void CheckPatch() { DeleteUrlCacheEntryA(url.c_str()); HRESULT hr; //DownloadCallback pCallback;// callback klasse URLDownloadToFileA(NULL, url.c_str(), filelist.c_str(), 0, NULL);//&pCallback); } //Funktionen vom Patcher private: System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Thread^ newThread = gcnew Thread(gcnew ThreadStart(this, &Patcher::MainForm::CheckPatch)); newThread->Start(); //CheckPatch(); } }; }
Ich hoffe jemand von euch kann mir helfen
Mit freundlichen Grüßen
-
Hier gibts eine Antwort: https://www.c-plusplus.net/forum/p2443449#2443449
-
Was soll das denn? Das ist doch nicht mein Thema. Tzzzzzz
-
Ist irgendwie doch dein Thema... und solange du nicht mal Hinweise in Form von Fehlermeldungen oder erwartetem, aber nicht aufgetretenem Verhalten preisgibst, ist es schwierig dir zu helfen.
Daher mein genereller Hinweis: Lass die Finger von C++/CLI ausser du MUSST die native und managed Welt miteinander verbinden. Wenn du die Finger nicht davon lassen kannst/willst, empfehle ich, wenigestens alles mit .NET zu machen - du ersparst dir dabei ne Menge Ärger.
Es ist oft so, dass unerfahreren Software-Entwickler die verschiedenen Technologien/Sprachen/etc. nicht auseinander halten können, so bei C und C++, so bei C++ und C++/CLI, etc.