MultiTop

// SAMPLE: make a spot to store the template
 // we're using so we can access it later

CMultiTopApp 中加入成员变量

CMultiDocTemplate* m_pDocTemplate;

 

// CMultiTopApp commands

// SAMPLE: This function handles the "New Frame Window" menu

 

void CMultiTopApp::OnFileMakeNewFrame()
{
 ASSERT(m_pDocTemplate != NULL);

 CDocument* pDoc = NULL;
 CFrameWnd* pFrame = NULL;

 pDoc = m_pDocTemplate->CreateNewDocument();
 if (pDoc != NULL)
 {
  pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL);
  if (pFrame != NULL)
  {
   m_pDocTemplate->SetDefaultTitle(pDoc);
   if (!pDoc->OnNewDocument())
   {
    pFrame->DestroyWindow();
    pFrame = NULL;
   }
   else
    m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);
  }
  else
   delete pDoc;
 }

 if (pFrame == NULL || pDoc == NULL)
  AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
}

BOOL CMultiTopApp::InitInstance()

加入// Enable drag/drop open
 m_pMainWnd->DragAcceptFiles();

 

// CMainFrame message handlers

// SAMPLE: if we load a frame and there's no main window
// yet in the app, we're loading the main frame right now and
// that window should become the main window of the application.

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
  CWnd* pParentWnd, CCreateContext* pContext)
{
 // base class does the real work

 if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
  pParentWnd, pContext))
 {
  return FALSE;
 }

 // test for main-ness

 CWinApp* pApp = AfxGetApp();
 if (pApp->m_pMainWnd == NULL)
  pApp->m_pMainWnd = this;

 return TRUE;
}

 

 

posted @ 2010-11-09 22:57  CHRIS-ZSY  阅读(145)  评论(0编辑  收藏  举报