网上有个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;\
}
解决方案 »
- 请教各位大人:VC sprintf()如何格式化中文 ?
- 请问各位,那里可以找到GDIPlus(GDI+)的帮助文档 谢谢!
- 如何拦截CLISTCTRL CHECKBOX 消息?
- ATL/WTL爱好者的福音:ATL实现的CDHtmlDialog模板类(原创)
- 在一个工程当中,seting-library-ouput file name是***.lib,请问这是用那种工程类型生成的
- 一个exe的grid问题。
- 08环境转换到vc6.0的开发平台
- csdn的贴子如何存盘?
- 新建QQ群--215232537--希望软件行业朋友都来交流交流--共享编程资料
- 'book'转化成int是多少??
- 关于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,这当然是错的,请问如何能跳转过去。