Discussion:
Alternative view for a document
(too old to reply)
RainMan
2007-11-27 20:52:01 UTC
Permalink
I assume you have MDI application and you are trying to create another child
frame with view that is wired to the same document. Try this:
CRuntimeClass *pClass = RUNTIME_CLASS(CChildFrame);
ASSERT(pViewClass);
CChildFrame *pNewFrame = (CChildFrame*)pClass->CreateObject();

You can pass CMDIChildWnd for a class if you do not want to have any control
over the frame behavior.

If you still have problem with ASSERT please post exact code that causes
assertion.
--
RainMan
VOID CSampleDoc::CreateNewView(CView* pView,CRuntimeClass* pRuntimeClass)
{
CFrameWnd* pMainWnd = (CFrameWnd*) AfxGetMainWnd();
CFrameWnd* pNewFrame = (CFrameWnd*) pMainWnd->CreateObject();
CCreateContext context;
context.m_pCurrentDoc = this;
// context.m_pLastView = pView;
// context.m_pCurrentFrame = pMainWnd;
context.m_pNewViewClass = RUNTIME_CLASS(CCustomView);
// context.m_pNewDocTemplate = GetDocTemplate();
pNewFrame->LoadFrame(IDR_CustomTYPE,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context);
pNewFrame->SetTitle(L"Test");
pNewFrame->InitialUpdateFrame(NULL, TRUE);
}
This code is called from the active view (this is a samaple a I've made for tests, not the real app) and it creates another type of view OK, but it is always an overlapped window. If I change window type to WS_CHILD I always get an assert - it seems I can't figure what windows should be used as a parent one.
Any help/hints/ideas welcome
Thank you for your time
--
Regards,
Waleri
Ajay Kalra
2007-11-30 02:29:46 UTC
Permalink
A brief question - it normal for MFC to ask to save document on closing on
any view of the document? Shouldn't it ask when the last view is closed? I
suspect
that for some reason it treats different views as if they were different
documents.
It should ask this when document is closing and not when *any* view is
closing. It just happens that document closes when last view is closed. You
should make sure that this is how its working for you if you have changed
this behavior.

--
Ajay

Loading...