http://blog.csdn.net/gnixuyil/article/details/7688439
Get Network pictures
[CPP]View PlainCopy
- CString url="Http://www.google.com.hk/images/srpr/logo3w.png"
- CInternetSession session;
- CHttpFile *httpfile = (CHttpFile *) session. OpenURL (URL);
- CStdioFile Imgfile;
- Char buff[1024]; //Cache
- Imgfile.open ("picture name. png", Cfile::modecreate | Cfile::modewrite | Cfile::typebinary);
- DWORD Dwstatuscode;
- Httpfile->queryinfostatuscode (Dwstatuscode);
- if (Dwstatuscode = = HTTP_STATUS_OK) {
- int size=0;
- Do {
- Size = Httpfile->read (buff,1024); //Read pictures
- Imgfile.write (buff,size);
- }while (Size > 0);
- }
- Httpfile->close ();
- Session. Close ();
Gets the HTML of the URL
[CPP]View PlainCopy
- CInternetSession session;
- CHttpFile *httpfile = (CHttpFile *) session. OpenURL (M_url);
- DWORD Dwstatuscode;
- Httpfile->queryinfostatuscode (Dwstatuscode);
- CString getdata=_t ("");
- if (Dwstatuscode = = HTTP_STATUS_OK) {
- CString line_data=_t ("");
- While (Httpfile->readstring (line_data)) {
- GetData + = Line_data; //Read HTML
- }
- GetData. TrimRight ();
- }
- Httpfile->close (); //HTML data has been placed in the GetData
- Session. Close ();
- If the Utf_8 page is saved in GetData (you can see the Meta field of HTML)
- Strcoding CFM; //Code conversion class, see below for details
- String temp = (LPCSTR) GetData. GetBuffer (); //Web data, converted to string type
- string output;
- Utf_8 to GB2312 so that MFC controls can display
- cfm. utf_8togb2312 (output, (char *) temp.data (), strlen (Temp.data ()));
- If the MFC character set is Unicode, you also need to convert multibyte to wide-byte
- temp = output;
- DWORD dwnum = MultiByteToWideChar (CP_ACP, 0, Temp.c_str (),-1, NULL, 0);
- wchar_t *pwtext;
- Pwtext = new wchar_t[dwnum];
- MultiByteToWideChar (CP_ACP, 0, Temp.c_str (),-1, Pwtext, dwnum);
- Gets the converted result m_data used to display
- m_data = Pwtext;
- delete []pwtext;
Encoding Conversion class: http://blog.csdn.net/gnixuyil/article/details/7688469
C + + Get URL picture, HTML file, CInternetSession "Go"