views:

467

answers:

3

Hi all,

I have a main frame with a splitter. On the left I have my (imaginatively named) CAppView_Leftand on the right I have CAppView_Right_1and CAppView_Right_2. Through the following code I initialise the two primary views correctly:

if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
    TRACE0("Failed to CreateStaticSplitter\n");
    return FALSE;
}
else 
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CAppView_Left), CSize(300, 200), pContext))
{
    TRACE0("Failed to create left pane\n");
    return FALSE;
}
else 
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CAppView_Right_1), CSize(375, 200), pContext))
{
    TRACE0("Failed to create first right pane\n");
    return FALSE;
}

...

What I would like to do is create a second view inside the right frame, however when I try to add this:

if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CAppView_Right_2), CSize(375, 200), pContext))
{
    TRACE0("Failed to create first right pane\n");
    return FALSE;
}

VS compiles but fails to run the application, raising an exception telling me I have already defined the view.

Can someone suggest how I do this? Also, how to change between the views from either a view or the document class?

Many thanks.

A: 

You can't create a second right hand view because your

m_wndSplitter.CreateStatic(this, 1, 2)

has only created two columns. You could change this to

m_wndSplitter.CreateStatic(this, 1, 3)

and change your second right view to

if (!m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CAppView_Right_2), CSize(375, 200), pContext))
{    
TRACE0("Failed to create first right pane\n");   
 return FALSE;
}

This results in three columns each with a seperate view. You could also create an additional splitter window to split one of the existing views, e.g. something like

m_wndSplitter2.CreateStatic(m_View2, 2, 1)

where m_view2 was your second view

Shane MacLaughlin
Thanks for the input - I don't want to create three panes. I am happy with the two panes I have, I just want to be able to use two different views (interchangeably) in the right hand pane.
Konrad
+1  A: 

There is a CodeProject article that should help you achieve what you want:

http://www.codeproject.com/KB/splitter/usefulsplitter.aspx

I have replaced views in a splitter before, so if the above doesn't help I'll post some of my own code.

Rob
Thanks! I had found other examples on codeproject, but none as efficient as that. Many Thanks! :)
Konrad
A: 

To switch between views, you'll need to explicitly DeleteView before creating another view in its place.

If you need to preserve the state of the interchangeable views, you'd better make the views be able to initialize their state from the document. Be careful to update the document with any state that needs to stick around between deletion and re-creation of one of the views.

Aidan Ryan