Ad

Multiple Interchangeable Views (MFC/C++)

- 1 answer

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?

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad