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.
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.