Listing 1 The function handling the NewWindow2 event in MDI
///////////////////////////////////////////////////////////////// // Function: OnNewWindow2() // Note: Handle the NewWindow2 event in MDI ///////////////////////////////////////////////////////////////// void CMfcieView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel) { CWinApp* pApp = AfxGetApp(); // Get the correct document template CDocTemplate* pDocTemplate; POSITION pos = pApp->GetFirstDocTemplatePosition(); pDocTemplate = pApp->GetNextDocTemplate(pos); ASSERT(pDocTemplate); // Create the new document CDocument* pNewDoc = pDocTemplate->CreateNewDocument(); ASSERT(pNewDoc); // Create the new frame CFrameWnd* pNewFrame =pDocTemplate->CreateNewFrame(pNewDoc, (CFrameWnd*)AfxGetMainWnd()); ASSERT(pNewFrame); // Activate the frame and set its active view pDocTemplate->InitialUpdateFrame(pNewFrame, NULL); CMfcieView* pWBVw =(CMfcieView*)pNewFrame->GetActiveView(); ASSERT(pWBVw); pWBVw->SetRegisterAsBrowser(TRUE); *ppDisp = pWBVw->GetApplication(); // Set a flag for cleanup of intermediate empty windows ((CMainFrame*)AfxGetMainWnd())->m_bClean = TRUE; }