网上有个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;\
}
// 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;\
}
解决方案 »
- 怎么通过子对话框中的变量来影响父对话框中编辑框的内容?
- 在线急等--对XML/XSL解析熟悉
- 一个紧急的问题,在线等待解决!
- 如果有一个好的创业的点子,如何去筹集资金呢?
- 看看这段代码,急,在线等待,9点结贴
- 咨询OpenGL方面的问题
- 用CPictureEx类加载gif动画的疑难问题,给分50
- 找人做毕业设计(linux下的ppp程序),杭州地区的来
- com的dll文件是不是已经包含了关于类型和接口的"元数据"?
- 我有一个access的表,有三个字段:主机厂,型号,件号。设置三个下拉列表,当我选择主机厂的时候,型号只出现对应主机厂的型号,而件号也只出现对应主机厂和型号的。
- 关于CEdit的滚动问题
- 跪求从bmp文件读取,转弯成灰度图的VC程序
你用
#import "mshtml.dll" 自己导入IHTMLDocument2这个接口,替换一下这个相关的东西然后改改代码,应该改动不会太大
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;
}
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,这当然是错的,请问如何能跳转过去。