CSplitterWnd

Hi Experts,

I've got an MFC SDI app that already does multiple view switching.  I'd like to add a new view that has a CSplitterWnd in it.

What base class should my new view class be?  CSplitterWnd?  I ask this because CSplitterWnd is just a CWnd, but CView is a derived class from CWnd - and I think I need a CView at a minimum...

So just guessing - do I create a CView and add a CSplitterWnd?  My issue with this is all examples seem to suggest that the CSplitterWnd needs a parent frame (CMainFrame) - but its parent is really the CView.... I'm confused.

Any help is much appreciated!
Mike
LVL 1
threadyAsked:
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.

jkrCommented:
>> So just guessing - do I create a CView and add a CSplitterWnd?

Actually, it's the other way round: You use a CSpliiterWnd and add CView instances to it. See http://www.codeproject.com/Articles/3509/Splitter-Window-Tutorial ("Splitter Window Tutorial"), e.g.

if ( !m_mainSplitter.CreateView( 0, 0, 
       RUNTIME_CLASS(CSplitterWindowTutorialView), 
       CSize(cr.Width()/2, 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(CSplitterWindowTutorialView), 
        CSize(cr.Width()/2, cr.Height()), pContext ) ) 
{ 
    MessageBox( "Error setting up splitter frames!", 
        "Init Error!", MB_OK | MB_ICONERROR );
    return FALSE; 
}

Open in new window


Well, the tutorial has a lot more...
0
jkrCommented:
Ooops, make that read "add CView-derived instances to it"
0
threadyAuthor Commented:
Yeah that I knew- but I only want the splitter in that particular view.  I've got 2 views already and that splitter doesn't belong there...
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

threadyAuthor Commented:
I don't really need the splitter actually... But now I'm wondering if I can add a cview to a cview (so I can create the left "pane" controls that would have been in my splitter dynamically, and add the RHS view to the view dynamically as well)....
0
jkrCommented:
No, you can't add a CView to a CView - if you need more than one view, you'll need a 'container' like CSplitterWnd.
0
threadyAuthor Commented:
I hate MFC.
0
sarabandeCommented:
you would not add the new view to the previous view but would add a new view to your document. for that you would add a new doc template, best in a member function of your document class. In the Your2ndView::OnInitialUpdate you would call a function of your document such that both views were synchronized and share the view place within the main frame. of course, a splitter window is one way to implement the same, but two views of one document may be a little bit simpler (even if you reinvent the wheel by that in some way).

Sara
0
threadyAuthor Commented:
Hi Sara,

I already had 2 views added that way - I'm looking to add a third view.  The problem is that the 3rd view is the only one of the 3 that has a splitter - the other 2 views take up the full space.

I'm left to think I need to add the splitter in all cases and somehow hide the fact that it's there for the other 2 views and resize it to what it was at with the 3rd view that needs it....  Such a hack though....  :(
0
threadyAuthor Commented:
I guess it's also impossible to add a CView to a CWnd?
0
sarabandeCommented:
actually none of the views needs to be full size. the splitter window could help but actually it is not more than a helper too.

of course you could add a CView to a CWnd, but why should you do that?

the document-view framework gives you a base and helps you to not struggle against wind mills. you shouldn't change all what worked but go step by step. if you already have two full-size views, first make them not full size anymore. if you achieved that, try to ize them properly such that both were visualized on the screen. if you have done so far, you could add bars where the user could increase one view and the other would shrink accordingly. if you have done that, you may add  a 3rd view ...

Sara
0
threadyAuthor Commented:
Hi Sara,

I'm not sure we're on the same page - I need my existing 2 views to remain full size.  It's only in the 3rd view that I want to have a splitter (to have 2 separate views in my 3rd view basically)...

Example - I have 3 modes in my program - mode 1 --> shows this full size view, mode 2--> another full size view.  Mode 3 shows a left side view and a right side view (that's why I need a splitter in mode 3)...

Mike
0
sarabandeCommented:
you can every view have in full size or in modified size. so, one solution of what you want is to have a splitter for 3rd view with two child windows. another - probably simpler - solution is to have 3rd view and 4th view both not maximized but both moved into the mainframe, one to the left and one to the right.

Sara
0
threadyAuthor Commented:
I don't see how I can have a splitter for the 3rd view - it doesn't inherit from CView...  

I don't also don't understand your simpler solution- you're saying instead of a 3rd view, that I should create a 3rd and 4th view and put them beside eachother?  Am I right in saying that in order to "switch" to that new conglomerated view, I'd have to create a single view with 2 other views in it (as the 3rd conglomerated view)?
0
sarabandeCommented:
I don't see how I can have a splitter for the 3rd view - it doesn't inherit from CView...
indeed the splitter window only is a helper.

you're saying instead of a 3rd view, that I should create a 3rd and 4th view and put them beside eachother?  Am I right in saying that in order to "switch" to that new conglomerated view, I'd have to create a single view with 2 other views in it (as the 3rd conglomerated view)?
no, a view is a non-modal window which size and positions are independent of the frame if not maximized. in a SDI model you have one main frame and one document which may have multiple views. there is no parent-child hierarchy between views. the views can be maximized within the frame or can be organized in a splitter or can be unbound windows, like dialogs or toolboxes. so, if you would have four views, view1 and view2 can be resized to fit fully into the frame window (see for example CScrollView::ResizeParentToFit how you could resize view and frame). you then can minimize the current view and create view3 and view4 and place them anywhere into the frame window. the splitter window concept would be similar beside that the splitter window provides a means where the user could arrange the views by themselves.

Sara
0

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
threadyAuthor Commented:
Thank you!  Now I get it!
0
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
C++

From novice to tech pro — start learning today.