html文件修改怎么保存,动态修改网页之后,如何把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是当前状态。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值