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?
rjahrmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
You need to add the following #include.

#include <afxcview.h>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rjahrmanAuthor Commented:
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?
chensuCommented:
Is m_pRowInfo valid? Is row out of range?
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

rjahrmanAuthor Commented:
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;
}
chensuCommented:
What is the assert? Please copy it here.
rjahrmanAuthor Commented:
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?
chensuCommented:
What were the values of m_pRowInfo and row at that time?
rjahrmanAuthor Commented:
row is 0
m_pRowInfo:
   all three values are "Error: expression cannot be evaluated"
rjahrmanAuthor Commented:
Also, m_nMaxRows is 1.
chensuCommented:
>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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.