Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

About FormView nested in a dialog of a project based on SDI Project

$
0
0

Hi Everyone

Basic topic: I want to construct a nested formview in a child dialog of the SDI Project


I build a SDI project on the base class of CFormView, and construct two dialog class :

one class is named CDialogParent, based on CDialog

the other class is named CTestForm, based on CFormView

in the mainwnd's formview, the CDialogParent is Created(create modeless dialog)

void CMyView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();
    m_DialogParent.Create(IDD_DIALOGPARENT,this);//m_DialogParent is intance ofCDialogParent
    m_DialogParent.ShowWindow(SW_SHOW);
}

at the CDialogParent's OnCreate function, construct CTestForm, code as below

int CDialogParent::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
    
    // TODO: Add your specialized creation code here
    CRect rc;
    GetClientRect(&rc);
    
    m_pViewClass = RUNTIME_CLASS(CTestForm);//m_pViewClassis a pointer to the CRuntimeClass
    CCreateContext * pContext;
    pContext = new CCreateContext;
    pContext->m_pCurrentDoc = NULL;
    pContext->m_pCurrentFrame = NULL;
    pContext->m_pLastView = NULL;
    pContext->m_pNewDocTemplate =NULL;
    pContext->m_pNewViewClass = m_pViewClass;
    CWnd * pWnd = NULL;
    pWnd = DYNAMIC_DOWNCAST(CWnd, m_pViewClass->CreateObject());
    if(pWnd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, IDD_DIALOG1, pContext) == FALSE)
    {
        delete pContext;
        return -1;
    }
    delete pContext;
    
    
    m_pView = DYNAMIC_DOWNCAST(CTestForm, pWnd); //m_pView is a pointer to theCTestForm
    m_pView->MoveWindow(1, 1, rc.Width() - 5, rc.Height() - 1, TRUE);
    
    
    return 0;
}

after running the project, the CDialogParent and CTestFormare both showed normally,

but when I click the button of the CTestForm, the program is crashed. even I click some

empty area of the TestForm Window, the result is same. why?

note: Construct a project based on MFC Dilaog, other code aboutCDialogParent and

CTestForm is same,the project runs well.





Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>