MFC实现下载网络图片缓存到本地

#include <afxinet.h>
新建一个基于对话框的工程,然后给确定按钮添加如下处理事件!【引入头文件afxinet.h】 void CTestDlg::OnOK()  { const int dwBufSize = 1024; CInternetSession   *   Session   =   new   CInternetSession;  CHttpFile*                 pHttpFile   =   NULL;    CStdioFile                 pLocalFile;                DWORD dwlen;  try {  LPBYTE   lpBuf   =   new   byte[dwBufSize];    //   把这个szPath置为D://test.jpg就行了 pLocalFile.Open(   "D://test.jpg",  CFile::modeCreate   |    CFile::modeWrite     |    CFile::typeBinary   );  pHttpFile   =(CHttpFile*)Session->OpenURL(  "http://hiphotos.baidu.com/q252061160/pic/item/e4a5a9f010c6502bb17ec59d.jpg",  1,  INTERNET_FLAG_TRANSFER_BINARY   |  INTERNET_FLAG_RELOAD   |    INTERNET_FLAG_DONT_CACHE,  NULL,  0);  while(dwlen   =   pHttpFile-> Read(lpBuf,   dwBufSize-1   ))  {  pLocalFile.Write(lpBuf,dwlen);  }  pLocalFile.Close();    pHttpFile->Close();  pHttpFile=NULL;  delete[]   lpBuf;  } catch(CInternetException   eInt)  {  eInt.Delete(); }  catch(CMemoryException   eMem)    {  eMem.Delete();  }  catch(CFileException   eFile)    {  eFile.Delete();  }  CDialog::OnOK(); } http://blog.csdn.net/ccjjyy/article/details/6098104

你可能感兴趣的:(图片缓存,缓存本地,网路图片)