Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI
I have created a splitter window and i have created 2 views. one view is loading properly but another one is not loading, while running i am getting the error like:
AccAccess violation reading location 0x00000020.

This error i am getting at line bellow under lined

AFX_STATIC void AFXAPI _AfxDeferClientPos(AFX_SIZEPARENTPARAMS* lpLayout,
CWnd* pWnd, int x, int y, int cx, int cy, BOOL bScrollBar)
{
ASSERT(pWnd != NULL);
ASSERT(pWnd->m_hWnd != NULL);.


My code for creating views is like this.

C#
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    m_splitwnd.CreateStatic( this, 1, 2 );
    m_splitwnd.CreateView( 0, 0, RUNTIME_CLASS(CFirstView), CSize( 100, 100 ), pContext );
    m_splitwnd.CreateView( 0, 1, RUNTIME_CLASS(CSecondView), CSize( 200, 200 ), pContext );

    return TRUE;
}




can any one help me.


Thanks In Advance
Posted
Comments
Olivier Levrey 22-Feb-11 7:41am    
Most likely the problem comes from CSecondView. Could you give more details about this class?

Take a look at this snippet:
https://vcpptips.wordpress.com/tag/oncreateclient/[^]

Regards
Espen Harlinn
 
Share this answer
 
Comments
savita_Bgm 2-Mar-11 0:43am    
not able to open this website.
Espen Harlinn 2-Mar-11 11:38am    
Works fine for me, I just tried it :)
The return statement seems incorrect to me. Try this:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,
    CCreateContext* pContext)
{
    m_splitwnd.CreateStatic( this, 1, 2 );
    m_splitwnd.CreateView( 0, 0, RUNTIME_CLASS(CFirstView),
        CSize( 100, 100 ), pContext );
    m_splitwnd.CreateView( 0, 1, RUNTIME_CLASS(CSecondView),
        CSize( 200, 200 ), pContext );
    return __super::OnCreateClient(lpcs, pContext);
}
 
Share this answer
 
v2
Comments
savita_Bgm 22-Feb-11 23:00pm    
Hi
Thanks for Suggestion But again it is showing the same error and if click on retry Button it's entering into endless loop. But when i put the same view name in the second line also it is running properly.
Olivier Levrey 23-Feb-11 3:37am    
Keep the return statement anyway. Just returning TRUE is without doubt not enough.
So there is a problem in the second class. Unless you give more details about that class I (or somebody else) can't help further.
savita_Bgm 25-Feb-11 3:33am    
HI

this code for the Second View Class

<pre lang="cs">#include "stdafx.h"

#include "SecondView.h"
#include "ComputerDoc.h"
#include <afxwin.h>
#include <afxcview.h>


// CSecondView

IMPLEMENT_DYNCREATE(CSecondView, CFormView)

CSecondView::CSecondView()
: CFormView(CSecondView::IDD)
{

}

CSecondView::~CSecondView()
{
}

void CSecondView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CSecondView, CFormView)
ON_BN_CLICKED(IDC_Browse_File, &CSecondView::OnBnClickedBrowsefile)
END_MESSAGE_MAP()


BOOL CSecondView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CFormView::PreCreateWindow(cs);
}

void CSecondView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();

}



// CSecondView diagnostics

#ifdef _DEBUG
void CSecondView::AssertValid() const
{
CFormView::AssertValid();
}

CComputerDoc* CSecondView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CComputerDoc)));
return (CComputerDoc*)m_pDocument;

}

#ifndef _WIN32_WCE
void CSecondView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CSecondView message handlers

void CSecondView::OnBnClickedBrowsefile()
{
// TODO: Add your control notification handler code here
}
</pre>

please check it.
sorry by mistakly i added my text here
 
Share this answer
 
v2
Comments
Olivier Levrey 25-Feb-11 4:38am    
Click the "Reject answer" button to show people you are still waiting for an answer.
savita_Bgm 2-Mar-11 0:42am    
ok thank you i m new for this website i don't know many things still now in this website.
OK here is your code for the CSecondView class. I just copied/pasted from your comment, so it is more readable:

#include "stdafx.h"
#include "SecondView.h"
#include "ComputerDoc.h"
#include <afxwin.h>
#include <afxcview.h>

// CSecondView
IMPLEMENT_DYNCREATE(CSecondView, CFormView)
CSecondView::CSecondView()
   : CFormView(CSecondView::IDD)
{
}
CSecondView::~CSecondView()
{
}
void CSecondView::DoDataExchange(CDataExchange* pDX)
{
   CFormView::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSecondView, CFormView)
   ON_BN_CLICKED(IDC_Browse_File, &CSecondView::OnBnClickedBrowsefile)
END_MESSAGE_MAP()

BOOL CSecondView::PreCreateWindow(CREATESTRUCT& cs)
{
   // TODO: Modify the Window class or styles here by modifying
   //  the CREATESTRUCT cs
   return CFormView::PreCreateWindow(cs);
}
void CSecondView::OnInitialUpdate()
{
   CFormView::OnInitialUpdate();
   GetParentFrame()->RecalcLayout();
   ResizeParentToFit();
}

// CSecondView diagnostics
#ifdef _DEBUG
void CSecondView::AssertValid() const
{
   CFormView::AssertValid();
}
CComputerDoc* CSecondView::GetDocument() const // non-debug version is inline
{
   ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CComputerDoc)));
   return (CComputerDoc*)m_pDocument;
}
#ifndef _WIN32_WCE
void CSecondView::Dump(CDumpContext& dc) const
{
   CFormView::Dump(dc);
}
#endif
#endif //_DEBUG

// CSecondView message handlers
void CSecondView::OnBnClickedBrowsefile()
{
   // TODO: Add your control notification handler code here
}


Since it is quite empty, there is not much to check:
- Check that your Form ID is correct (maybe you deleted the resource by mistake from the .rc file and the ID number is still defined in resource.h?).
- The problem may come from the 2 lines you added in OnInitialUpdate. Actually, since they are the only 2 lines you added, the problem must come from those lines...

Maybe the parent form is not fully initialized at that time and the call to RecalcLayout is too early. Try to remove them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900