how make new SDI Window with different view in MFC?

N

Neo

I am going to make SDI base application in MFC, which has a button for "New
Window", will show new window with different view.



How I can solve this problem? Main window view class inherited with
CListView, and New Window view class inherited with CFormView.



------------: Following windows are registered :------------



CSingleDocTemplate * pDocTemplate;

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME,

RUNTIME_CLASS(COtengoDoc),

RUNTIME_CLASS(CMainFrame),

RUNTIME_CLASS(COtengoView)); //Base Class of COtengoView is CListView



if (!pDocTemplate)

return FALSE;

AddDocTemplate(pDocTemplate); //Registered Main Window

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME1,

RUNTIME_CLASS(CNewMsgDoc),

RUNTIME_CLASS(CNewMsgFrm),

RUNTIME_CLASS(CNewMsgView)); //Base Class of CNewMsgView is CFormView



if (!pDocTemplate)

return FALSE;

AddDocTemplate(pDocTemplate);



------------: For New Window code :------------



CSingleDocTemplate * m_pDocTemplate;

m_pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME1,

RUNTIME_CLASS(CNewMsgDoc),

RUNTIME_CLASS(CNewMsgFrm),

RUNTIME_CLASS(CNewMsgView));



CDocument * pDoc = NULL;

CFrameWnd * pFrame = NULL;

pDoc = m_pDocTemplate->CreateNewDocument( );

if( pDoc != NULL )

{

pFrame = m_pDocTemplate->CreateNewFrame( pDoc, pFrame ); // <--
Exception comes

if( pFrame != NULL )

{

m_pDocTemplate->SetDefaultTitle( pDoc );

if( ! pDoc->OnNewDocument( ) )

{

pFrame->DestroyWindow( );

pFrame = NULL;

}

else

{

m_pDocTemplate->InitialUpdateFrame( pFrame, pDoc, TRUE );

}

}

}



if( pFrame == NULL || pDoc == NULL )

{

delete pDoc;

AfxMessageBox( AFX_IDP_FAILED_TO_CREATE_DOC );

}



in this code, when "pFrame = m_pDocTemplate->CreateNewFrame( pDoc,
pFrame );" give exception comes on this code



File : viewform.cpp



#ifdef _DEBUG

// dialog template must exist and be invisible with WS_CHILD set

if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))

{

ASSERT(FALSE); // invalid dialog template name

PostNcDestroy(); // cleanup if Create fails too soon

return FALSE;

}

#endif //_DEBUG



tell me, how solve this problem?



regards,

Mohammad Omer Nasir.
 
W

William DePalo [MVP VC++]

Neo said:
I am going to make SDI base application in MFC, which has
a button for "New Window", will show new window with
different view.

If no one responds here try posting again in one of the MFC groups, perhaps
here:

microsoft.public.vc.mfc.docview

Regards,
Will
 
W

www.fruitfruit.com

I am going to make SDI base application in MFC, which has a button for "New
Window", will show new window with different view.



How I can solve this problem? Main window view class inherited with
CListView, and New Window view class inherited with CFormView.



------------: Following windows are registered :------------



CSingleDocTemplate * pDocTemplate;

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME,

RUNTIME_CLASS(COtengoDoc),

RUNTIME_CLASS(CMainFrame),

RUNTIME_CLASS(COtengoView)); //Base Class of COtengoView is CListView



if (!pDocTemplate)

return FALSE;

AddDocTemplate(pDocTemplate); //Registered Main Window

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME1,

RUNTIME_CLASS(CNewMsgDoc),

RUNTIME_CLASS(CNewMsgFrm),

RUNTIME_CLASS(CNewMsgView)); //Base Class of CNewMsgView is CFormView



if (!pDocTemplate)

return FALSE;

AddDocTemplate(pDocTemplate);



------------: For New Window code :------------



CSingleDocTemplate * m_pDocTemplate;

m_pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME1,

RUNTIME_CLASS(CNewMsgDoc),

RUNTIME_CLASS(CNewMsgFrm),

RUNTIME_CLASS(CNewMsgView));



CDocument * pDoc = NULL;

CFrameWnd * pFrame = NULL;

pDoc = m_pDocTemplate->CreateNewDocument( );

if( pDoc != NULL )

{

pFrame = m_pDocTemplate->CreateNewFrame( pDoc, pFrame ); // <--
Exception comes

if( pFrame != NULL )

{

m_pDocTemplate->SetDefaultTitle( pDoc );

if( ! pDoc->OnNewDocument( ) )

{

pFrame->DestroyWindow( );

pFrame = NULL;

}

else

{

m_pDocTemplate->InitialUpdateFrame( pFrame, pDoc, TRUE );

}

}

}



if( pFrame == NULL || pDoc == NULL )

{

delete pDoc;

AfxMessageBox( AFX_IDP_FAILED_TO_CREATE_DOC );

}



in this code, when "pFrame = m_pDocTemplate->CreateNewFrame( pDoc,
pFrame );" give exception comes on this code



File : viewform.cpp



#ifdef _DEBUG

// dialog template must exist and be invisible with WS_CHILD set

if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))

{

ASSERT(FALSE); // invalid dialog template name

PostNcDestroy(); // cleanup if Create fails too soon

return FALSE;

}

#endif //_DEBUG



tell me, how solve this problem?



regards,

Mohammad Omer Nasir.
In my understanding, AddDocTemplate(pDocTemplate); is used to add
document template, not for registering View class.
here is a sample for mulitple view in SDI
support.microsoft.com/support/kb/articles/q141/3/33.asp
VSWAP Demos Multiple-View Switching in SDI
 
N

Neo

thanks alot,

regards,
Mohammad Omer Nasir.

www.fruitfruit.com said:
In my understanding, AddDocTemplate(pDocTemplate); is used to add
document template, not for registering View class.
here is a sample for mulitple view in SDI
support.microsoft.com/support/kb/articles/q141/3/33.asp
VSWAP Demos Multiple-View Switching in SDI
 
Top