📄 httpdownload.h
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#ifndef HttpDownloadH
#define HttpDownloadH
#include <urlmon.h>
#include "istring.h"
//---------------------------------------------------------------------------
using namespace KCeasyEngine;
typedef enum
{
HttpDownloadNew,
HttpDownloadActive,
HttpDownloadCancelling,
HttpDownloadCancelled,
HttpDownloadFailed,
HttpDownloadCompleted
} THttpDownloadState;
// callback message:
// WParam: THttpDownload*
// LParam: NULL
class THttpDownload : public IBindStatusCallback
{
friend DWORD WINAPI gThreadFunc(void* data);
public:
THttpDownload(HWND CallbackWindow, int CallbackMessage);
bool Start(string& NUrl, string& NSavePath);
bool Cancel();
THttpDownloadState GetState() { return State; }
const string& GetUrl() { return Url; }
const string& GetSavePath() { return SavePath; }
unsigned long GetProgress() { return Progress; }
unsigned long GetProgressMax() { return ProgressMax; }
// IUnknown interface
STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
STDMETHOD_(ULONG,AddRef)();
STDMETHOD_(ULONG,Release)();
// IBindStatusCallback interface
STDMETHOD(OnProgress)(ULONG ulProgress, ULONG ulProgressMax,
ULONG ulStatusCode, LPCWSTR wszStatusText);
STDMETHOD(OnStartBinding)(DWORD dwReserved, IBinding *pib);
STDMETHOD(GetPriority)(LONG *pnPriority);
STDMETHOD(OnLowResource)(DWORD reserved);
STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR szError);
STDMETHOD(GetBindInfo)(DWORD *grfBINDF, BINDINFO *pbindinfo);
STDMETHOD(OnDataAvailable)(DWORD grfBSCF, DWORD dwSize,
FORMATETC *pformatetc, STGMEDIUM *pstgmed);
STDMETHOD(OnObjectAvailable)(REFIID riid, IUnknown *punk);
private:
~THttpDownload();
void ThreadFunc();
void SetState(THttpDownloadState NState, bool RaiseCallback = true);
long RefCount;
HWND CallbackWnd;
int CallbackMsg;
HANDLE ThreadHandle;
THttpDownloadState State;
string Url;
string SavePath;
unsigned long Progress;
unsigned long ProgressMax;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -