http下载类(直接传入ProcessBarCtrl指针,用来显示进度)

类别:VC语言 点击:0 评论:0 推荐:

专用于下载到本地磁盘的同时显示进度条

使用本类,请先取得CHttpClient下载类


// HttpClientProcess.h: 专用于下载到本地磁盘的同时显示进度条
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_HTTPCLIENTPROCESS_H__)
#define AFX_HTTPCLIENTPROCESS_H__


#include "HttpClient.h"

class CHttpClientProcess : public CHttpClient 
{
public:
 CHttpClientProcess();
 virtual ~CHttpClientProcess();

 bool Download(char*url,char*fname,void* p);  //p为进度条控件的指针
 virtual void OnDataRecived(char* data,long datasize,int first = false );
private:
 CProgressCtrl* m_lpProcessBar;
};

#endif


//------------------------------------------------------------------
// HttpClientProcess.cpp
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HttpClientProcess.h"


CHttpClientProcess::CHttpClientProcess()
{
 m_lpProcessBar=NULL;
}

CHttpClientProcess::~CHttpClientProcess()
{

}
void CHttpClientProcess::OnDataRecived(char* data,long datasize,int first)
{
 CHttpClient::OnDataRecived(data,datasize,first);
 if(!m_lpProcessBar)return;

 if(first)
 {
  char buf[128];
  memset(buf,0,128);
  GetHeader("Content-Length",buf);
  m_lpProcessBar->SetRange32(0,atol(buf));
  m_lpProcessBar->SetPos(datasize);
 }
 else
 {
  m_lpProcessBar->SetPos(m_lpProcessBar->GetPos()+datasize);
 }
}

bool CHttpClientProcess::Download(char *url, char *fname, void *p)
{
 m_lpProcessBar=(CProgressCtrl*)p;
  return CHttpClient::Download(url,fname);
}

本文地址:http://com.8s8s.com/it/it592.htm