mfc拦截CDHtmlDialog中某些特殊页面链接并做其他处理

在.h文件中定义一个函数
DECLARE_EVENTSINK_MAP()
virtual void XOnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel);
在.CPP中

BEGIN_EVENTSINK_MAP(CXXXHTMLDialog, CDHtmlDialog)
ON_EVENT(CXXXHTMLDialog, AFX_IDC_BROWSER, 250 /* BeforeNavigate2 */, XOnBeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
END_EVENTSINK_MAP()

void CXXXHTMLDialog::XOnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel) {
  CString url = *URL;

  if (url == "http://localhost:8800/testhtml/zadan/zjmd.jsp"){

     CDHtmlDialog* m_myHtmlDg=new CDHtmlDialog();
     CWnd* pParent = NULL;
     m_myHtmlDg-> Create(IDD_DIALOG2,pParent);
     m_myHtmlDg-> Navigate(_T(url));
     m_myHtmlDg-> SetHostFlags(DOCHOSTUIFLAG_NO3DBORDER);
     m_myHtmlDg-> ShowWindow(SW_SHOW);

     *Cancel = true;
  }else{
     return;
  }
}

你可能感兴趣的:(jsp,mfc)