请教关于点击超链接的问题

bnututu 2002-12-17 06:49:15
我做好了一个单文档的浏览器,但当我点击页面上的链接时,会启动ie,而不是在我的浏览器中出现新的页面,这是因为我建立的是单文档的问题吗?还是什么别的应该注意的问题?请赐教!无比感谢!
...全文
201 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2003-01-09
  • 打赏
  • 举报
回复
错了,是MSDN
chenybin 2003-01-09
  • 打赏
  • 举报
回复
估计是那个地方了:)
chenybin 2003-01-09
  • 打赏
  • 举报
回复
codeproject
ruxming 2002-12-27
  • 打赏
  • 举报
回复
Please 楼上的网友 注明文章的出处和url.
chenmu_2002 2002-12-18
  • 打赏
  • 举报
回复
First let's create an MDI MFC application using the AppWizard. During the final page of the wizard, select a view class that is derived from CHtmlView. Then use the ClassWizard to add an event handler for the NewWindow2 event. Finally, add code to your NewWindow2 event handler function:

void CMyHtmlView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
{
// Get a pointer to the application object.
CWinApp* pApp = AfxGetApp();

// Get the correct document template.
POSITION pos = pApp->GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate( pos );

// Create a new frame.
CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(
GetDocument(),
(CFrameWnd*)AfxGetMainWnd() );

// Activate the frame.
pDocTemplate->InitialUpdateFrame( pFrame, NULL );
CNewWindow2View* pView = (CNewWindow2View*)pFrame->GetActiveView();

// Pass pointer of WebBrowser object.
pView->SetRegisterAsBrowser( TRUE );
*ppDisp = pView->GetApplication();
}

Navigate to a Web page that opens a new window and you'll see the Web page displayed in your application. This works because your application intercepts the NewWindow2 event, creates a new document/frame/view combination, and passes the IDispatch for the WebBrowser object. This causes your CHtmlView-derived class to be used to display the Web page. Note that the WebBrowser object must be created each time and not have navigated to a URL, or this won’t work.

You'll probably want to make this more useful by obtaining the window information, such as the height and width, so that you can modify your view accordingly. A simple approach to this is to handle the BeforeNavigate2 event that is fired after the new window is created. Add the following code to your application to resize the view to the size of the new window. Note that this is an overridden method that allows access to the WebBrowser object, and that an additional Boolean member, m_bResizeWindow, is required. Set this to false in the constructor and true in the NewWindow2 event handler to ensure this code is only called for new windows.

void CMyHtmlView::BeforeNavigate2(LPDISPATCH pDisp, VARIANT* URL,
VARIANT* Flags, VARIANT* TargetFrameName,
VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
if ( m_bResizeWindow )
{
IWebBrowser2* pWB = NULL;

// QI the dispatch for WebBrowser control.
HRESULT hr = pDisp->QueryInterface( IID_IWebBrowser2,
(void**)&pWB );
if ( SUCCEEDED(hr) )
{
long x,y;

// Get dimensions.
pWB->get_Width( &x );
pWB->get_Height( &y );

// Resize frame.
SetScrollSizes( MM_TEXT, CSize(x,y) );
ResizeParentToFit();
pWB->Release();
}
m_bResizeWindow = false;
}
}

3,056

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧