CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2001
    Posts
    81

    CView : creation

    I use two class in a none doc\view application. The first one is derive from CMDIChildWnd and the second one is derive from CView. I Create the CMDIChildWnd this way :

    HTML Code:
    pFrame->CreateNewChild( RUNTIME_CLASS(WndGridChild), IDR_INTERFTYPE, m_hMDIMenu, m_hMDIAccel);
    The CView derived class is create this way :

    Code:
    BOOL WndGridChild::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
    {
    	if (m_GridView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    		return TRUE;
    	
    	return CMDIChildWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }
    
    BOOL WndGridChild::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    	pContext->m_pNewViewClass = RUNTIME_CLASS(CGridView);
    
    	m_GridView = (CGridView*)CreateView(pContext);
    
    	if(NULL == m_GridView)
    	{
    		return FALSE;
    	}
    	
    	return CMDIChildWnd::OnCreateClient(lpcs, pContext);
    }
    When I create this window I don't why it call 2 times all functions for View creation ( OnInitialUpdate, PreCreateWindow, Constructor etc ).

    Evedently I would like it call it one time.

    Thank you

  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: CView : creation

    This is because you create two views.
    Do this:
    Code:
    BOOL WndGridChild::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    	pContext->m_pNewViewClass = RUNTIME_CLASS(CGridView);
    	
    	m_GridView = (CGridView*)CreateView(pContext); //Cretes view
    	
    	if(NULL == m_GridView)
    	{
    		return FALSE;
    	}
    	return TRUE;
    	//return CMDIChildWnd::OnCreateClient(lpcs, pContext); //creates view
    }
    Or this:

    Code:
    	BOOL WndGridChild::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    	{
    		pContext->m_pNewViewClass = RUNTIME_CLASS(CGridView);
    		
    		return CMDIChildWnd::OnCreateClient(lpcs, pContext); 
    	}
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Aug 2001
    Posts
    81

    Re: CView : creation

    Thank you very much for your reply, it is exactly what I want to know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured