Advertisement
| 12.04.2008 at 01:18AM PST, ID: 23956109 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: |
#include <urlmon.h>
//#include <afx.h>
class YDownloadMonitor : public IBindStatusCallback
{
private:
long m_dwRef;
public:
inline YDownloadMonitor() : m_dwRef(0) {}
inline ~YDownloadMonitor() { }
STDMETHOD_(ULONG, AddRef)()
{
return InterlockedIncrement(&m_dwRef);
}
STDMETHOD_(ULONG, Release)()
{
unsigned long lResult = InterlockedDecrement(&m_dwRef);
if (lResult == 0)
delete this;
return lResult;
}
IHTMLElement* Status;
/*BEGIN_COM_MAP(YDownloadMonitor)
COM_INTERFACE_ENTRY(IBindStatusCallback)
END_COM_MAP()*/
STDMETHOD(OnProgress)(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
{
CComBSTR newStatus(L"Buffering...");
std::wstring text = L"Buffering... ";
//text = szStatusText; // causes an exception so it is commented out
if (ulProgressMax!=0)
text += (100/ulProgressMax*ulProgress);
newStatus = W2BSTR((text).c_str());
this->Status->put_innerHTML(newStatus);
return S_OK;
}
STDMETHOD(OnStartBinding)(DWORD a, IBinding* b)
{
return E_NOTIMPL;
}
STDMETHOD(OnStopBinding)(HRESULT a, LPCWSTR b)
{
return E_NOTIMPL;
}
STDMETHOD(GetPriority)(LONG* a)
{
return E_NOTIMPL;
}
STDMETHOD(OnLowResource)(DWORD a)
{
return E_NOTIMPL;
}
STDMETHOD(GetBindInfo)(DWORD* a, BINDINFO* b)
{
return E_NOTIMPL;
}
STDMETHOD(OnDataAvailable)(DWORD a, DWORD b, FORMATETC* c, STGMEDIUM* d)
{
return E_NOTIMPL;
}
STDMETHOD(OnObjectAvailable)(REFIID a, IUnknown* b)
{
return E_NOTIMPL;
}
STDMETHOD(QueryInterface)(REFIID iid, void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
// check for the interfaces this object knows about
if (iid == IID_IUnknown || iid == IID_IBindStatusCallback)
{
*ppvObject = (IBindStatusCallback*)this;
InterlockedIncrement(&m_dwRef);
return S_OK;
}
// otherwise, incorrect IID, and thus error
return E_NOINTERFACE;
}
};
void CBhoApp::RunYAIPP(IHTMLElement* Status)
{
HRESULT hr;
hr = Status->put_innerHTML(CComBSTR("Buffering..."));
if (hr!=S_OK) return;
// CBindStatusCallback<YDownloadMonitor>::Download(this,
// OnData, m_bstrURL, m_spClientSite, FALSE);
YDownloadMonitor* yaippdownloader = new YDownloadMonitor();
yaippdownloader->Status = Status; // pass the HTML element
yaippdownloader->AddRef();
hr = URLDownloadToFile(reinterpret_cast<LPUNKNOWN>(this),"http://www.roket-games.com/games/","C:\\test.htm",0,yaippdownloader);
/*
if (hr)
{
hr = Status->put_innerHTML(CComBSTR("Unable to download file."));
if (hr!=S_OK) return;
}
else
{
hr = Status->put_innerHTML(CComBSTR("Downloaded file."));
if (hr!=S_OK) return;
}
*/
}
|
Advertisement