一,新建一个单文档工程WatchSourceFile,视图类基于CHtmlView。
二,更改CWatchSourceFileView::OnInitialUpdate()函数,具体代码如下:
void CWatchSourceFileView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();
Navigate2(_T("www.vcshare.net"),NULL,NULL);
}
三,在工具栏增加两个按钮ID_SEE1,IDD_SEE2,并在视力类为它们增加响应函数,具体代码如下:
#include "mshtml.h"
#include "atlbase.h"
void CWatchSourceFileView::OnSee1()
{
CString refString ;
CComPtr<IDispatch> spDisp = GetHtmlDocument();
if ( spDisp )
{
HGLOBAL hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if( NULL != hMemory )
{
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
if( spPersistStream )
{
CComPtr <IStream> spStream;
if(SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPersistStream-> Save(spStream, FALSE);
LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if( pstr )
{
refString = pstr;
AfxMessageBox(refString);
GlobalUnlock(hMemory);
}
::GlobalFree(hMemory);
}
}
}
}
}
2021年目标:完成新书《闻缺陷则喜》,本博客右上公告有下载、阅读链接。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)