求一思路.我想把网页上的Html代码保存为.txt文件,上网找了说要用CHtmlView,这个类具体该怎么用啊???

lizhigang34 2008-04-15 11:35:05
高手帮帮忙啊..最好能赋上段代码..谢谢啦!!
...全文
247 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhigang34 2008-04-19
  • 打赏
  • 举报
回复
太感谢 lzj290438714 ..
问题解决,虽然代码不是很懂,但我会慢慢研究的..真的很感谢!!
唐巧 2008-04-16
  • 打赏
  • 举报
回复
直接写socket也挺方便的,50行以内就可以解决.
Thorwein 2008-04-16
  • 打赏
  • 举报
回复

The CHtmlView class provides the functionality of the WebBrowser control within the context of MFC's document/view architecture. The WebBrowser control is a window in which the user can browse sites on the World Wide Web, as well as folders in the local file system and on a network. The WebBrowser control supports hyperlinking, Uniform Resource Locator (URL) navigation, and maintains a history list.

Using the CHtmlView Class in an MFC Application

In the standard MFC framework application (either SDI or MDI based), the view object is commonly derived from a specialized set of classes. These classes, all derived from CView, provide specialized functionality beyond that provided by CView.

Basing the application's view class on CHtmlView provides the view with the WebBrowser control. This effectively makes the application a web browser. The preferred method of creating a web browser-style application is to use the MFC AppWizard, and specify CHtmlView as the view class. For more information on implementing and using the WebBrowser control within MFC applications, seeWeb Browser-Style Applications.

The functionality of CHtmlView is designed for applications that are access the Web (and/or HTML documents). The following CHtmlView member functions apply to the Internet Explorer application only. These functions will succeed on the WebBrowser control, but they will have no visible effect.

// 具体还是看MSDN吧
lzj290438714 2008-04-16
  • 打赏
  • 举报
回复
CString URL;
CString HostName;
CString FileName;
CString htmlString;

URL.Format(_T("http://www.google.cn/search?complete=1&hl=zh-CN&newwindow=1&q=中国&meta=&aq=0"));

INTERNET_PORT port;

DWORD serverType = AFX_INET_SERVICE_HTTP;
if(!AfxParseURL(URL,serverType,HostName,FileName,port))
return ;
HINTERNET hOpen; // 会话句柄
HINTERNET FhConnect; // http连接句柄
HINTERNET FhRequest; // http请求句柄

hOpen = InternetOpen(_T("http-get-demo"),
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
1
);
if(hOpen==NULL)
{
MessageBox(_T("hOpen is NULL"));
return ;

}


FhConnect = InternetConnect(hOpen,
HostName,
INTERNET_DEFAULT_HTTP_PORT,
NULL,NULL,
INTERNET_SERVICE_HTTP, 0, 0);
if(FhConnect==NULL)
{
MessageBox(_T("Connected failed"));

return ;
}


const char *FAcceptTypes = "*/*";
CString accept ;
accept.Format(_T("*/*"));
CString refer;
refer.Format(_T("http://www.yahoo.cn"));




FhRequest = HttpOpenRequest(FhConnect,
_T("GET"), // 从服务器获取数据
FileName, // 想读取的文件的名称
_T("HTTP/1.1"), // 使用的

NULL,
NULL,//&FAcceptTypes,
INTERNET_FLAG_RELOAD,
0);

if(FhRequest==NULL)
{
MessageBox(_T("HttpOpenRequest failed"));
return ;
}

HttpSendRequest(FhRequest, NULL, 0, NULL, 0);
if(HttpSendRequest==NULL)
{
MessageBox(_T("HttpOpenRequest failed"));
return ;
}

DWORD BufLen=100;
DWORD dwByteToRead=0;
DWORD dwIndex=0;
BOOL RetQueryInfo=HttpQueryInfo(FhRequest,
HTTP_QUERY_FLAG_NUMBER |HTTP_QUERY_CONTENT_LENGTH,
&dwByteToRead, &BufLen,
NULL);

if(!RetQueryInfo)
{
// MessageBox(_T("HttpQueryInfo failed"));

// return ;

}
// std::cout<<"FileSize:"<<dwByteToRead<<std::endl;
// DWORD fileLen = atoi (dwByteToRead);

TCHAR Buffer[256];
DWORD dwRequest=0;
dwRequest =dwByteToRead;
DWORD dwRead =0;

CFile file;
file.Open(_T("E://test.html"),CFile::modeCreate|CFile::modeWrite);
while(true)
{

BOOL ReadReturn = InternetReadFile(FhRequest,
(LPVOID)Buffer,
256,
&dwRead);


if(!ReadReturn)break;
if(dwRead==0)break;
// 保存数据

file.Write(Buffer,dwRead);
file.Flush();
// std::cout<<"size of downloaded data:"<<dwRead<<std::endl ;
}
file.Close();
phoenix35 2008-04-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 coldwindtang 的回复:]
直接写socket也挺方便的,50行以内就可以解决.
[/Quote]

是啊 ,去掉html响应头就是html网页的内容了
lizhigang34 2008-04-16
  • 打赏
  • 举报
回复
up
daohua 2008-04-16
  • 打赏
  • 举报
回复
不懂 帮顶

64,687

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧