向mshtml.dll高手请教:如何保存修改后的IE文档?
我想通过mshtml.dll中的IHTML***等COM接口来修改IE正在浏览的页面,然后保存成另一个html文件,这类似于一个HTML编辑器,打开一个文件,修改之后另存。我可以修改页面,但保存成另一个html文件时,发现还是旧的内容,新修改的东西并没有存进去,为什么?
我的代码如下:
#include <windows.h>
// Internet Explorer 5
#import <mshtml.tlb>
#import <shdocvw.dll>
// C RunTime Header Files
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr spSHWinds;
SHDocVw::IWebBrowser2Ptr spBrowser;
MSHTML::IHTMLDocument2Ptr spDoc;
IDispatchPtr spDisp;
// Get All Windows Explorer and IE Instances
spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
long nCount = spSHWinds->GetCount();
for (long i = 0; i < nCount; i++)
{
_variant_t va(i, VT_I4);
spDisp = spSHWinds->Item(va);
// Get IE Instance
spBrowser = spDisp;
if (spBrowser != NULL)
{
// Get IE Document
spDoc = spBrowser->GetDocument();
if (spDoc != NULL)
{
// Change color
VARIANT va_c;
va_c.vt = VT_I4;
va_c.lVal = 255;
spDoc->put_bgColor(va_c);
// Save as
IPersistFilePtr spPersFile(spDoc);
spPersFile->Save(L"c:\\unknown.html", FALSE);
}
break;
}
}
CoUninitialize();
return TRUE;
}
用IE打开一个页面,然后运行这个程序,页面的背景色改为蓝色,保存文件为c:\unknown.html,但我发现,蓝色背景并没有存到c:\unknown.html上。
怎么保存修改后的IE文档?望高手、过来人指点一二,谢谢!