创建新窗口的代码如下,是使用 CreateNewFrame ,在使用这个函数创建窗口时,程序会收到什么消息,还有新创建的窗口被关闭时,又会收到什么消息?想在这两个过程中处理一些事务。void CMyView::OnNewWindow2(LPDISPATCH * ppDisp, BOOL * Cancel)
{
//在新窗口打开链接CWinApp *pApp = AfxGetApp(); CDocTemplate *pDocTemplate;
POSITION pos = pApp->GetFirstDocTemplatePosition();
pDocTemplate = pApp->GetNextDocTemplate(pos); ASSERT(pDocTemplate); CFrameWnd* pNewFrame = pDocTemplate-> CreateNewFrame(GetDocument(), (CFrameWnd*)AfxGetMainWnd());
ASSERT(pNewFrame); pDocTemplate->InitialUpdateFrame(pNewFrame, NULL); CMyView *pWBVw = (CMyView*)pNewFrame-> GetActiveView();
ASSERT(pWBVw); *ppDisp = pWBVw->GetApplication(); }
{
//在新窗口打开链接CWinApp *pApp = AfxGetApp(); CDocTemplate *pDocTemplate;
POSITION pos = pApp->GetFirstDocTemplatePosition();
pDocTemplate = pApp->GetNextDocTemplate(pos); ASSERT(pDocTemplate); CFrameWnd* pNewFrame = pDocTemplate-> CreateNewFrame(GetDocument(), (CFrameWnd*)AfxGetMainWnd());
ASSERT(pNewFrame); pDocTemplate->InitialUpdateFrame(pNewFrame, NULL); CMyView *pWBVw = (CMyView*)pNewFrame-> GetActiveView();
ASSERT(pWBVw); *ppDisp = pWBVw->GetApplication(); }
SDI切换View:
void CMainFrame::SwitchViews(int ID)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView;
CCreateContext cc;
cc.m_pCurrentDoc=pOldActiveView->GetDocument();
CString title=cc.m_pCurrentDoc->GetPathName();;
// which one
switch (ID)
{
case 1://
pNewActiveView=(CView*) new CWinOh51View;
title += " Binary View";
break;
}
// Create new
pNewActiveView->Create(0,0,0,CFrameWnd::rectDefault,this,ID,&cc);
pNewActiveView->OnInitialUpdate();
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
// Exchange view window ID's so RecalcLayout() works.
SetWindowLong(pNewActiveView->m_hWnd, GWL_ID,AFX_IDW_PANE_FIRST);
RecalcLayout();
//If we use: delete pOldActiveView,
//we got : Warning: calling DestroyWindow in CWnd::~CWnd,
//OnDestroy or PostNcDestroy in derived class will not be called.
pOldActiveView->DestroyWindow();
// new title
SetWindowText(title);
}