//設(shè)定消息處理的窗口句柄
HttpDown.SetParentWindow(hwnd);
//添加要下載的文件路徑
HttpDown.AddFile();
//開始下載
m_HttpDown.BeginDownLoad();
//這兩個函數(shù)都是消息通知,自己添加自定義消息處理
LRESULT CAutoUpdateDlg::EndDown(WPARAM wParam, LPARAM lParam)
{
//下載完成以后調(diào)用的函數(shù)
return 0;
}
LRESULT CAutoUpdateDlg::OnDisplayStatus(WPARAM wParam, LPARAM lParam)
{
//處理下載進(jìn)度的函數(shù)
const DOWNLOADSTATUS *const pDownloadStatus =
reinterpret_cast<DOWNLOADSTATUS *>(lParam);
CString strStatus;
if (pDownloadStatus != NULL)
{
#ifdef _DEBUG
VERIFY(strStatus.LoadString(pDownloadStatus->ulStatusCode -
UF_BINDSTATUS_FIRST +
IDS_BINDSTATUS01));
strStatus += _T(" ");
strStatus += pDownloadStatus->szStatusText;
CString strProgress;
strProgress.Format(_T(" %lu of %lu"),
pDownloadStatus->ulProgress,
pDownloadStatus->ulProgressMax);
strStatus += strProgress + _T("\r\n");
TRACE(strStatus);
#endif
m_Progress.SetPos(MAX_PROGRESS_NUM/((pDownloadStatus->ulProgressMax/(pDownloadStatus->ulProgress+1))+1));
}
return 0;
}
//下載失敗我就在函數(shù)里處理關(guān)閉主窗口,具體自己實現(xiàn)
// empty the filename string if failed or canceled
if (!SUCCEEDED(hr))
{
strFileName.ReleaseBuffer(-1);
pThis->m_DownList.clear();
//如果下載失敗或是取消下載就關(guān)閉窗口
::PostMessage(pThis->m_hWnd, WM_CLOSE, 0, 0);
return 0;
}
回復(fù) 更多評論