How To Use the WebBrowser Control NewWindow2 Event

출처 : http://support.microsoft.com/default.aspx?scid=kb;EN-US;q184876

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

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

    ASSERT(pDocTemplate);

    // Create the new frame
    CFrameWnd* pNewFrame = pDocTemplate->CreateNewFrame(GetDocument(),
                                   (CFrameWnd*)AfxGetMainWnd());
    ASSERT(pNewFrame);

    // Activate the frame and set its active view
    pDocTemplate->InitialUpdateFrame(pNewFrame, NULL);

    CYourView* pWBVw = (CYourView*)pNewFrame->GetActiveView();
    ASSERT(pWBVw);

    pWBVw->m_webBrowser.SetRegisterAsBrowser(TRUE);

    *ppDisp = pWBVw->m_webBrowser.GetApplication();
}

댓글 남기기