动态修改网页之后,如何把IHTMLDocument2中内容保存到文件? ---------------(现在无法把修改结果保存下来)
解决方案 »
- 在vc6中用GDI+来做控件效果.
- 在线程中 可以接受WINDOWS消息吗?可以用UI吗,像对话框啊,按钮啊,............?
- 如何获取外部程序的ListBox控件内容?
- 怎样卸载别的程序的钩子阿?急
- 高价求购---QQ最新通讯协议
- 看起来简单:画线的问题的请教
- 关于磁盘读写
- 高手请看......................
- 我实在忍不住要说几句了.一点点看法,欢迎大家指正
- 请问在Button中只有单击和双击事件,那可以添加其他事件吗?(比如:Buttondown/up等)?
- IOCP非常疑惑的问题:GetQueuedCompletionStatus到底是如何知道是发送还是接收的?
- 这种效果如何实现
你不会想把你修改的页面保存到服务器上吧?如果你能做到,麻烦告诉我下。
源码本机路径:C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\src\mfc\viewhtml.cpp
[code]
BOOL CHtmlEditDoc::OnSaveDocument(LPCTSTR lpszFileName)
{
BOOL bRet = FALSE;
CHtmlEditView *pView = GetView();
if (pView != NULL)
{
CFile file;
if (file.Open(lpszFileName, CFile::modeCreate|CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
CArchiveStream as(&ar);
CComPtr<IHTMLDocument2> spHTMLDocument;
CComQIPtr<IPersistStreamInit> spPSI;
pView->GetDHtmlDocument(&spHTMLDocument);
if (spHTMLDocument)
{
spPSI = spHTMLDocument;
if (spPSI)
{
if (S_OK == spPSI->Save((IStream*)&as, TRUE))
{
SetModifiedFlag(FALSE);
bRet = TRUE;
}
}
}
}
}
return bRet;
}
[/code]
BOOL CHtmlEditDoc::OnSaveDocument(LPCTSTR lpszFileName)
{
BOOL bRet = FALSE;
CHtmlEditView *pView = GetView();
if (pView != NULL)
{
CFile file;
if (file.Open(lpszFileName, CFile::modeCreate|CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
CArchiveStream as(&ar);
CComPtr<IHTMLDocument2> spHTMLDocument;
CComQIPtr<IPersistStreamInit> spPSI;
pView->GetDHtmlDocument(&spHTMLDocument);
if (spHTMLDocument)
{
spPSI = spHTMLDocument;
if (spPSI)
{
if (S_OK == spPSI->Save((IStream*)&as, TRUE))
{
SetModifiedFlag(FALSE);
bRet = TRUE;
}
}
}
}
}
return bRet;
}
if ( S_OK != pDisp2->QueryInterface(IID_IHTMLDocument3,(LPVOID*)&pDoc3) )
{
AfxMessageBox(TEXT("get modify source failed"));
return;
}
//save modified html file
//HTML object
CComQIPtr<IHTMLElement> pRootElem;
pDoc3->get_documentElement(&pRootElem);
_bstr_t bstrHtml;
pRootElem->get_outerHTML(bstrHtml.GetAddress());
wstring sNewHtml( bstrHtml );
//write to file
strDir = strDir.substr(0, strDir.rfind(TEXT(".")));
strDir += TEXT(".html");
absPath = CString(arrTmpPath);
absPath += TEXT("DevHelper\\");
absPath += strDir.c_str();
HANDLE hFile = CreateFile(absPath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
if ( INVALID_HANDLE_VALUE == hFile )
{
AfxMessageBox(TEXT("Open Save Failed"));
return;
}
pDoc2->get_URL(bstrHtml.GetAddress());
CStringA comment;
comment.Format(("<!-- saved by DevHelper from url=%s -->\n"),CStringA(bstrHtml.GetBSTR()));
DWORD dwBytesWritten = 0;
BOOL bRet;
if ( FALSE == WriteFile(hFile,comment.GetBuffer(),comment.GetLength(),&dwBytesWritten,NULL) )
{
AfxMessageBox(TEXT("Write temp file head failed"));
} bRet = WriteFile(hFile,pTmp,bufLenExp,&dwBytesWritten,NULL);
if ( FALSE == bRet )
{
AfxMessageBox(TEXT("Write temp file failed"));
return;
}
CloseHandle(hFile);