MFC开发IM-显示网络图片

#include "resource.h"
#include "stdafx.h"
#include<windows.h>   
#include<wininet.h>   
  
#pragma   comment(lib,"wininet.lib")   
#pragma   comment(lib,"kernel32.lib")   
void    Entry();
int  APIENTRY WinMain( HINSTANCE  hInstance,
                      HINSTANCE  hPrevInstance,
                      LPSTR      lpCmdLine,
                      int        nCmdShow)
{
  
int  ret=URLDownloadToFile(NULL, "http://www.google.cn/intl/zh-CN/images/logo_cn.gif" ,
                           "c:\\logo.gif" ,0,NULL); 
 
 
if  (ret==S_OK)  //如果下载成功 
{
MessageBox(NULL,  "okok" "OK" , MB_OK);
}
  
     Entry();
     return  0;
}
 
     
   void    Entry()   
   {   
       HINTERNET   hSession=InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);   
       HINTERNET   hConnection=InternetOpenUrl(hSession, "http://www.google.com" ,NULL,0,0,0);   
     
         BYTE    Buffer[4096];   
         DWORD    Read=0,i;   
        HANDLE    hFile=CreateFile( "c:\\index.htm" ,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);   
   }

猜你喜欢

转载自blog.csdn.net/golddaniu/article/details/79805508