假定你的浏览器控件ID为IDC_WEBBROWSER,并关联到CWebBrowser2 m_web变量。代码如下:
BEGIN_EVENTSINK_MAP(CMainDialog, CDialogSK)
//{{AFX_EVENTSINK_MAP(CMainDialog)
ON_EVENT(CMainDialog, IDC_WEBBROWSER, 273 /* NewWindow3 */, OnNewWindow3Explorer, VTS_PDISPATCH VTS_PBOOL VTS_I4 VTS_BSTR VTS_BSTR)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()//将需要在新窗口打开的链接放在本窗口打开
void CMainDialog::OnNewWindow3Explorer(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, DWORD dwFlags, LPCTSTR bstrUrlContext, LPCTSTR bstrUrl)
{
m_web.Navigate(bstrUrl,NULL,NULL,NULL,NULL);
*Cancel = TRUE;
}