一,新建一个单文档工程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); } } } } }