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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is m_pRowInfo valid? Is row out of range?
ASKER
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 (LPCREATES TRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CRect cr;
GetClientRect( &cr);
if ( !m_mainSplitter.CreateStat ic( 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(CNewTreeList CtrlView), 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;
}
If it helps, here is the code I use to set up the splitter:
BOOL CMainFrame::OnCreateClient
{
// TODO: Add your specialized code here and/or call the base class
CRect cr;
GetClientRect( &cr);
if ( !m_mainSplitter.CreateStat
{
MessageBox( "Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
return FALSE;
}
if ( !m_mainSplitter.CreateView
{
MessageBox( "Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
return FALSE;
}
if ( !m_mainSplitter.CreateView
{
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.
ASKER
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?
ASKER
row is 0
m_pRowInfo:
all three values are "Error: expression cannot be evaluated"
m_pRowInfo:
all three values are "Error: expression cannot be evaluated"
ASKER
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.CreateStati c() 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.CreateStati c() 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?
> 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
ASKER
m_pRowInfo[row].nIdealSize
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(
m_mainSplitter.SetColumnIn
m_mainSplitter.SetColumnIn
m_mainSplitter.RecalcLayou
}
What do I need to do?