首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

获取网站的图片到本地硬盘中,该怎么处理

2012-02-03 
获取网站的图片到本地硬盘中如何获取网站的图片到本地硬盘中?已经知道了该图片的url,比如图片的url为http:

获取网站的图片到本地硬盘中

    如何获取网站的图片到本地硬盘中?已经知道了该图片的url,比如图片的url为
    http://www.xxxx.site/1.jpg,怎么根据该url得到图片并且下载到本地硬盘中。

    请高手赐教!

[解决办法]
InternetReadFile
[解决办法]
URLDownloadToFile
[解决办法]
//下载
#include <wininet.h>
#pragma comment(lib, "wininet.lib ")

void Down(CString Url,CString Path)
{
HINTERNET hSession=InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
HINTERNET hConnection=InternetOpenUrl(hSession,Url,NULL,0,0,0);
if(hConnection == NULL)return FALSE;//返回
BYTE Buffer[4096];
DWORD Read=0,i;
HANDLE hFile=CreateFile(Path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
InternetReadFile(hConnection,Buffer,sizeof(Buffer),&Read);
while(Read!=0)
{
WriteFile(hFile,Buffer,Read,&i,NULL);
InternetReadFile(hConnection,Buffer,sizeof(Buffer),&Read);
}
CloseHandle(hFile);

InternetCloseHandle(hConnection);
InternetCloseHandle(hSession);
return TRUE;
}

热点排行