Link to home
Start Free TrialLog in
Avatar of rjahrman
rjahrman

asked on

Confused With Views

I'm a total newb when it comes to the Doc/View architecture . . . I mean, I understand the concept, I just can't implement anything beyond a simple SDI app with one view.  Anyway, I have an example prog by someone else that I want to modify (as a "learning experience") to have a second view.

Basically, it's an SDI application with the author's version of a Tree/List control as its only view.  I'm trying to add a second view on the right that is a list box (or list view, I guess).

Anyway, my first problem:  I went into ClassWizard and clicked "New Class", then named it "CRightView" and said it should be derived from CListView.  However, I get all sorts of errors when compiling:

RightView.cpp
error C2504: 'CListView' : base class undefined
error C2440: 'return' : cannot convert from 'class CRightView *' to 'class CObject *'
error C2653: 'CListView' : is not a class or namespace name
error C2065: 'classCListView' : undeclared identifier
error C2653: 'CListView' : is not a class or namespace name
error C2065: 'GetDocument' : undeclared identifier
error C2440: 'initializing' : cannot convert from 'int' to 'class CDocument *'
error C2653: 'CListView' : is not a class or namespace name
error C2653: 'CListView' : is not a class or namespace name

On another forum, they suggested that I add it as an MFC class.  I did it again and was careful to select MFC class, but I still get the errors.  What am I doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjahrman
rjahrman

ASKER

OK, it compiled after I did that.  However, now that I've added the code from an article I read to it, I get an access violation when I try to run the program.  The debugger went to this line in SetRowInfo:

m_pRowInfo[row].nIdealSize = cyIdeal;

My call to this function (that I think it's talking about) looks like so:

CFrameWnd::OnSize(nType, cx, cy);
CRect cr;
GetWindowRect(&cr);
if (  m_bInitSplitter && nType != SIZE_MINIMIZED )
      m_mainSplitter.SetRowInfo( 0, cy, 0 );  // RIGHT HERE!
      m_mainSplitter.SetColumnInfo( 0, (cr.Width()/4)*3, 50);
      m_mainSplitter.SetColumnInfo( 1, cr.Width() / 4, 50);
      m_mainSplitter.RecalcLayout();
}

What do I need to do?
Is m_pRowInfo valid? Is row out of range?
I'm not sure . . . but in the MFC source, right before that there's an assert that looks like it detects that.

If it helps, here is the code I use to set up the splitter:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
      // TODO: Add your specialized code here and/or call the base class

      CRect cr;
      GetClientRect( &cr);

      if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )
      {
            MessageBox( "Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
            return FALSE;
      }

      if ( !m_mainSplitter.CreateView( 0, 0, RUNTIME_CLASS(CNewTreeListCtrlView), CSize((cr.Width()/4)*3, cr.Height()), pContext ) )
      {
            MessageBox( "Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
            return FALSE;
      }

      if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CRightView), CSize(cr.Width()/4, cr.Height()), pContext ) )
      {
            MessageBox( "Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
            return FALSE;
      }

      m_bInitSplitter = TRUE;

      return TRUE;
}
What is the assert? Please copy it here.
There _isn't_ an assert . . . that's just it.  It exits with an access violation (probably caused by that array).  What I meant was that the asserts above it should have caught it if that was the problem.  Right?
What were the values of m_pRowInfo and row at that time?
row is 0
m_pRowInfo:
   all three values are "Error: expression cannot be evaluated"
Also, m_nMaxRows is 1.
>m_pRowInfo:
>  all three values are "Error: expression cannot be evaluated"

This means m_pRowInfo is invalid.

I think the problem is that OnSize() is actually called before CMainFrame::OnCreateClient(). So, at that point, the m_mainSplitter.CreateStatic() has not been called yet. The solution is to have a flag. You initialize the flag to false and set it to true after m_mainSplitter.CreateStatic() succeeds. In your OnSize(), check the flag. But it seems to me that you already have a flag m_bInitSplitter. Did you initialize it to FALSE?