CDownLoadFile.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include <winerror.h>
  3. #include<BASETYPS.H>
  4. #include <urlmon.h>
  5. #pragma comment(lib, "urlmon.lib")
  6. #include "FileCore.h"
  7. #include "KeyVar.h"
  8. #include <WinInet.h>
  9. #include <tchar.h>
  10. class DownloadProgress : public IBindStatusCallback
  11. {
  12. public:
  13. static double Currentpercentage;
  14. static double pro_Sum;
  15. static double pro_value;
  16. HRESULT __stdcall QueryInterface(const IID&, void**) {
  17. return E_NOINTERFACE;
  18. }
  19. ULONG STDMETHODCALLTYPE AddRef(void) {
  20. return 1;
  21. }
  22. ULONG STDMETHODCALLTYPE Release(void) {
  23. return 1;
  24. }
  25. HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD dwReserved, IBinding* pib) {
  26. return E_NOTIMPL;
  27. }
  28. virtual HRESULT STDMETHODCALLTYPE GetPriority(LONG* pnPriority) {
  29. return E_NOTIMPL;
  30. }
  31. virtual HRESULT STDMETHODCALLTYPE OnLowResource(DWORD reserved) {
  32. return S_OK;
  33. }
  34. virtual HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT hresult, LPCWSTR szError) {
  35. return E_NOTIMPL;
  36. }
  37. virtual HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD* grfBINDF, BINDINFO* pbindinfo) {
  38. return E_NOTIMPL;
  39. }
  40. virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed) {
  41. return E_NOTIMPL;
  42. }
  43. virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID riid, IUnknown* punk) {
  44. return E_NOTIMPL;
  45. }
  46. virtual HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
  47. {
  48. if (ulProgressMax != 0)
  49. {
  50. pro_Sum = ulProgressMax;
  51. pro_value = ulProgress;
  52. double* percentage = new double(ulProgress * 1.0 / ulProgressMax * 100);
  53. DownloadProgress::Currentpercentage = *percentage;
  54. //将percentage 发送给显示
  55. delete percentage;
  56. }
  57. return S_OK;
  58. }
  59. };
  60. class CDownLoadFile
  61. {
  62. public:
  63. bool GetInstallPackage(std::wstring SaveFolder);
  64. };
  65. class NetWorkState
  66. {
  67. public:
  68. static bool IsNetWorking();//是否有网络
  69. static bool IsProxyEnable();//是否设置为LAN使用代理服务器
  70. static bool IsProxyNetError();//是否因开启代理服务器或代理参数不对,而没法联网
  71. };