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

来源:互联网 发布:ubuntu chrome 编辑:程序博客网 时间:2024/06/13 12:03
#include <afxinet.h>
新建一个基于对话框的工程,然后给确定按钮添加如下处理事件!【引入头文件afxinet.h】void CTestDlg::OnOK() {const int dwBufSize = 1024;CInternetSession   *   Session   =   new   CInternetSession; CHttpFile*                 pHttpFile   =   NULL;   CStdioFile                 pLocalFile;               DWORD dwlen; tryLPBYTE   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
0 0