在VC7中CHtmlView类本身就有OnNavigateError事件响应
可是VC6中却没有, 经过一番试验, 找到以下方法为VC6增加此响应
比如CHtmlCtrl
在头文件中增加以下内容
#define DISPID_NAVIGATEERROR 271 DECLARE_EVENTSINK_MAP()
public:
virtual void NavigateError(LPDISPATCH pDisp, VARIANT* pvURL,
VARIANT* pvFrame, VARIANT* pvStatusCode, VARIANT_BOOL* pvbCancel);
virtual void OnNavigateError(LPCTSTR lpszURL, LPCTSTR lpszFrame, DWORD dwError, BOOL *pbCancel);
在cpp文件中增加以下内容
BEGIN_EVENTSINK_MAP(CHtmlCtrl, CHtmlView)
ON_EVENT(CHtmlCtrl, AFX_IDW_PANE_FIRST, DISPID_NAVIGATEERROR, NavigateError, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
END_EVENTSINK_MAP()
....
void CHtmlCtrl::NavigateError(LPDISPATCH pDisp, VARIANT* pvURL,
VARIANT* pvFrame, VARIANT* pvStatusCode, VARIANT_BOOL* pvbCancel)
{
UNUSED_ALWAYS(pDisp);
ASSERT(pvURL != NULL);
ASSERT(pvFrame != NULL);
ASSERT(pvStatusCode != NULL);
ASSERT(pvbCancel != NULL);
ASSERT(V_VT(pvURL) == VT_BSTR);
ASSERT(V_VT(pvFrame) == VT_BSTR);
CString strURL(V_BSTR(pvURL));
CString strFrame(V_BSTR(pvFrame));
DWORD dwError = V_I4(pvStatusCode);
BOOL bCancel = FALSE;
// notify the user's class
OnNavigateError(strURL, strFrame, dwError, &bCancel);
if (pvbCancel)
*pvbCancel = bCancel ? AFX_OLE_TRUE : AFX_OLE_FALSE;
}
void CHtmlCtrl::OnNavigateError(LPCTSTR lpszURL, LPCTSTR lpszFrame, DWORD dwError, BOOL *pbCancel)
{
// default to continuing
*pbCancel = FALSE;
// user will override to handle this notification
UNUSED_ALWAYS(lpszURL);
UNUSED_ALWAYS(lpszFrame);
}
这样VC6的CHtmlView继承类也就有了OnNavigateError响应方法
参考 :http://www.codeguru.com/forum/archive/index.php/t-74676.html
http://www.itzhe.cn/article/20080119/57559.html