网上有个VC.Net的例子,想在VC6下面用,可是编译通不过,不知为什么,VC.NET下有个atlsafe.h,但VC6没有,如果有用那个替换。代码如下:////////////////////////////////////////////////////////////////
// MSDN Magazine -- August 2003
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio .NET on Windows XP. Tab size=3.
//
// ---
// Implemenation for CHtmlCtrl -- web browser in a control. Overrides
// CHtmlView so you don't need a frame--can use in dialog or any other kind of
// window.
//
// Features:
// - SetCmdMap lets you set a command map for "app:command" links.
// - SetHTML lets you set document contents (HTML) from string.#include "StdAfx.h"
#include "HtmlCtrl.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif// macro to declare a typedef for ATL smart poitners; eg SPIHTMLDocument2
#define DECLARE_SMARTPTR(ifacename) typedef CComQIPtr<ifacename> SP##ifacename;// smart pointer to IHTMLDocument2
DECLARE_SMARTPTR(IHTMLDocument2)
//上面那行提示:syntax error : missing ';' before '<'
//是不是缺少头文件// useful macro for checking HRESULTs
#define HRCHECK(x) hr = x; if (!SUCCEEDED(hr)) { \
TRACE(_T("hr=%p\n"),hr);\
return hr;\
}

解决方案 »

  1.   

    这个看起来有些麻烦
    你用
    #import "mshtml.dll"  自己导入IHTMLDocument2这个接口,替换一下这个相关的东西然后改改代码,应该改动不会太大
      

  2.   

    在 stdafx.h 中加上 #include <atlbase.h>
      

  3.   

    //关键在这个函数,老提示SPINHTMLDocument2,CComSafeArray,CComBSTR没有定义。
    HRESULT CHtmlCtrl::SetHTML(LPCTSTR strHTML)
    {
    HRESULT hr; // Get document object
    SPIHTMLDocument2 doc = GetHtmlDocument(); // Create string as one-element BSTR safe array for IHTMLDocument2::write.
    CComSafeArray<VARIANT> sar;
    sar.Create(1,0);
    sar[0] = CComBSTR(strHTML); // open doc and write
    LPDISPATCH lpdRet;
    HRCHECK(doc->open(CComBSTR("text/html"),
    CComVariant(CComBSTR("_self")),
    CComVariant(CComBSTR("")),
    CComVariant((bool)1),
    &lpdRet));

    HRCHECK(doc->write(sar)); // write contents to doc
    HRCHECK(doc->close()); // close
    lpdRet->Release(); // release IDispatch returned return S_OK;
    }
      

  4.   

    正是缺什么补什么,我把VC.NET的atlsafe.h加入到工程了,搞定,但是还有个问题,
    m_wndView.SetHideContextMenu(TRUE); // hide context menu
    m_wndView.SetCmdMap(MyHtmlCmds); // set commands
    m_wndView.Navigate(_T("about:blank")); // create document
    m_wndView.SetHTML(“<html><body>.....</body><html>") // set contents from string
    这时里面的链接都变成:about:blank...
    比如,我有个锚点#a1,要跳转到网页的某一部分,此时就链接成了about:blank#a1,这当然是错的,请问如何能跳转过去。