打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
动态修改网页之后,如何把IHTMLDocument2中内容保存到文件?
void CMyHtmlView::OnDesignMode() 
{
// TODO: Add your command handler code here
HRESULT hr;
IHTMLDocument2* piDoc = 0;
IWebBrowser2* piWeb = 0;
IDispatch* piDisp = 0;
IUnknown* piUnk = m_wndBrowser.GetControlUnknown();
hr = piUnk->QueryInterface(IID_IWebBrowser2, (void**)&piWeb);
if(FAILED(hr))
{
AfxMessageBox("QueryInterface for IWebBrowser2");
return;
}
hr = piWeb->get_Document(&piDisp);
if(SUCCEEDED(hr))
{
hr = piDisp->QueryInterface(IID_IHTMLDocument2, (void**)&piDoc);
if(SUCCEEDED(hr))
{
if(m_MyClientSite.m_bDocDesignMode)
piDoc->put_designMode(L"Inherit");
else
piDoc->put_designMode(L"On");
m_MyClientSite.m_bDocDesignMode = !m_MyClientSite.m_bDocDesignMode;
piDoc->Release();
}
else
AfxMessageBox("QueryInterface doc");
piDisp->Release();
}
else
AfxMessageBox("get_Document");
}

void CMyHtmlView::OnSaveToFile() 
{
// TODO: Add your command handler code here
CFileDialog dlg(FALSE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
NULL, NULL);
if(dlg.DoModal()==IDCANCEL)
return;
_bstr_t path=dlg.GetPathName();

HRESULT hr;
IWebBrowser2* piWeb = 0;
IDispatch* piDisp = 0;
IPersistFile* piPF = 0;
IUnknown* piUnk = m_wndBrowser.GetControlUnknown();
hr = piUnk->QueryInterface(IID_IWebBrowser2, (void**)&piWeb);
if(FAILED(hr))
{
AfxMessageBox("QueryInterface for IWebBrowser2");
return;
}
hr = piWeb->get_Document(&piDisp);
if(SUCCEEDED(hr))
{
hr = piDisp->QueryInterface(IID_IPersistFile, (void**)&piPF);
if(SUCCEEDED(hr))
{
piPF->Save(path, TRUE);
piPF->Release();
}
piDisp->Release();
}
}

void CMyHtmlView::OnModifyBody() 
{
// TODO: Add your command handler code here
HRESULT hr;
IHTMLDocument2* piDoc = 0;
IWebBrowser2* piWeb = 0;
IDispatch* piDisp = 0;
IHTMLElement* piElem = 0;
IHTMLBodyElement* piBody = 0;
IUnknown* piUnk = m_wndBrowser.GetControlUnknown();
hr = piUnk->QueryInterface(IID_IWebBrowser2, (void**)&piWeb);
if(FAILED(hr))
{
AfxMessageBox("QueryInterface for IWebBrowser2");
return;
}
hr = piWeb->get_Document(&piDisp);
if(SUCCEEDED(hr))
{
hr = piDisp->QueryInterface(IID_IHTMLDocument2, (void**)&piDoc);
if(SUCCEEDED(hr))
{
hr = piDoc->get_body(&piElem);
if(SUCCEEDED(hr))
{
hr = piElem->QueryInterface(IID_IHTMLBodyElement, (void**)&piBody);
if(SUCCEEDED(hr))
{
VARIANT v;

piBody->get_bgColor(&v);
_bstr_t bstr=v;
// AfxMessageBox((char*)bstr);

v.vt=VT_BSTR;
v.bstrVal = ::SysAllocString(OLESTR("#00FF00"));
piBody->put_bgColor(v);
::SysFreeString(v.bstrVal);
piBody->Release();
}
else
AfxMessageBox("QueryInterface body");
piElem->Release();
}
else
AfxMessageBox("get_body");
piDoc->Release();
}
else
AfxMessageBox("QueryInterface doc");
piDisp->Release();
}
else
AfxMessageBox("get_Document");
}

其中m_MyClientSite.m_bDocDesignMode是当前状态。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[IE编程]IE网页截图技术总结
浏览器控件教学:使用流加载和保存HTML内容 - 斌子网站
delphi WebBrowser获取iframe页面内容
Delphi Webbrowser IE 窗口选择中,选中的文字内容
获取IE (控件)的所有链接(包括Frameset, iframe)
TWebBrowser访问IFrame
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服