2009. 4. 15. 09:06

Document 를 공유하는 Frame 윈도우 생성하기

아래 처럼 하면, 동일한 Document 를 공유하는 새로운 Frame 과 View 를 생성하는 샘플 코드이다.

CWinApp * pApp = AfxGetApp();

POSITION pos = pApp->m_pDocManager->GetFirstDocTemplatePosition();

CDocTemplate * pDocTemplate = pApp->m_pDocManager->GetNextDocTemplate(pos);

 

CDocument * pDocument = GetDocument();

 

CFrameWnd * pwndFrame = (CFrameWnd *)RUNTIME_CLASS(CFrameWnd)->CreateObject();

ASSERT(pwndFrame != NULL);

 

CCreateContext context;

context.m_pCurrentFrame = NULL;

context.m_pCurrentDoc = pDocument;

context.m_pNewViewClass = RUNTIME_CLASS(CEditView);

context.m_pNewDocTemplate = pDocTemplate;

 

if( pwndFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context) == FALSE)

{

        return;

}

 

pDocTemplate->SetDefaultTitle(pDocument);

pDocTemplate->InitialUpdateFrame(pwndFrame, pDocument, TRUE);