為VC6的CHtmlView繼承類新增NavigateError事件響應
在VC7中CHtmlView類本身就有OnNavigateError事件響應
可是VC6中卻沒有, 經過一番試驗, 找到以下方法為VC6增加此響應
比如CHtmlCtrl
在標頭檔案中增加以下內容
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響應方法