MFC实现下载网络图片缓存到本地
2016-01-26 16:59
603 查看
#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
新建一个基于对话框的工程,然后给确定按钮添加如下处理事件!【引入头文件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
相关文章推荐
- openstack配置注意事项(主要是网络相关)
- 处理umeditor编辑器给a标签自动添加http://办法
- Apache httpd.conf配置详解
- 重启网络,报以下错误:Error: Connection activation failed: The connection is not for this device.
- android 网络请求遇到的坑:connect failed: EHOSTUNREACH (No route to host)
- 次成分分析MCA
- Linux下Apache配置SSL支持https
- 主成分分析PCA
- SVM支持向量机
- http://androidsource.top/code/source
- Widrow-Hoff Learning
- 感知机学习
- Hebb学习规则
- MyEclipse 项目部署到tomcat时出现错误之——deploy______http://yang8820.iteye.com/blog/1654466
- java网络编程(二)复用Socket连接以及使用多线程完成多个客户端的连接
- Nginx HTTP返回状态码修改
- Android利用Get、Post 获取网络数据
- HttpWebRequest请求返回非200的时候 HttpWebResponse怎么接受返回错误提示
- AngualrJS中每次$http请求时的一个遮罩层Directive
- 深入Android通过Apache HTTP访问HTTP资源