CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2012
    Posts
    5

    MFC Splitter roadblock

    I have been scouring the internet for help for the past two days and nothing I have found has been able to answer my...most likely simple...question.

    I want to create and MFC application. Document/View architecture or not, doesn't matter. The goal is that I want a splitter window in the application. Divided into a left and right pane. The left pane will have a ListControl and radio buttons which, when selected, will display different edit boxes, scroll bars, etc. on the right pane.

    I have seen tutorials on creating splitter windows. Doing that just fine. The best tutorial I found was one where the splitter windows were created without using the document/view architecture as avoiding that bloat would be appealing.

    I am having a problem connecting the splitter window idea, to that of the panes interacting. I cannot figure out how to switch views on the right pane, from a button pressed on the left pane. That very basically example is what I am looking for. Currently I am using two dialogs with a base of CFormView for the layout in the left and right pane. I created a third dialog for the second right frame I would like to display, but I cannot figure out how to switch it.

    Any help, or a link to a tutorial on how to do what I have described here would be incredibly helpful. As I said, I am about 2 days deep in google searches trying to find an answer to suit the needs of my application, but I have yet been unsuccessful.

    Thank you so much,
    -Patrick

  2. #2
    Join Date
    Apr 2007
    Posts
    162

    Re: MFC Splitter roadblock

    It almost sounds like you would be better off using TABS rather than radio buttons to select your views.

  3. #3
    Join Date
    Mar 2012
    Posts
    5

    Re: MFC Splitter roadblock

    Quote Originally Posted by zapper222 View Post
    It almost sounds like you would be better off using TABS rather than radio buttons to select your views.
    Hopefully I didn't misquote that earlier.

    The idea is to have a list view on the left pane with several items in it. When the user selects an item and/or selects a radio button, the right pane form would change

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: MFC Splitter roadblock

    Wouldn't CSplitterWnd:: DeleteView and CSplitterWnd::CreateView do it for you?

  5. #5
    Join Date
    Mar 2012
    Posts
    5

    Re: MFC Splitter roadblock

    Quote Originally Posted by GCDEF View Post
    Wouldn't CSplitterWnd:: DeleteView and CSplitterWnd::CreateView do it for you?
    Maybe I am a bit confused on where that should be called out.
    In the example I am using now, it is a splitter window without the doc/view architecture.
    I have MainFrm, CFormLeft, CFormRight, CRightForm2.

    In the OnCreateClient for MainFrm I have:
    Code:
    if (!m_wndSplitter.CreateStatic(this, 1, 2))
    		return FALSE;
    
    if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CFormLeft), CSize(125, 100), pContext) ||!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFormRight), CSize(100, 100), pContext))
    		{
    			m_wndSplitter.DestroyWindow();
    			return FALSE;
    		}
    I am using two dialogs attached to the Left and Right forms. I have a third dialog for the Right2 form.

    What I want to be able to do is to switch to the Right2 when I click a button from the Left form.
    Add the event handler for the button but not sure what the next step is. I don't assume I can delete and create a view from the LeftForm button event function.

    What function is it up on the MainFrm that would be called when I hit the button on the LeftFrm that I could then do the suggested "Delete then Create" step.

    Thanks so much for the information thus far.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: MFC Splitter roadblock

    Quote Originally Posted by PBarnes View Post
    I don't assume I can delete and create a view from the LeftForm button event function.
    Why not. I don't know, but I'd try using the two functions I mentioned. Delete the old view and create the new one.

  7. #7
    Join Date
    Mar 2012
    Posts
    5

    Re: MFC Splitter roadblock

    Quote Originally Posted by GCDEF View Post
    Why not. I don't know, but I'd try using the two functions I mentioned. Delete the old view and create the new one.
    Code:
    void CFormLeft::OnBnClickedButtonHello()
    {
    	// TODO: Add your control notification handler code here
    
    	//DeleteView
    	CSplitterWnd::DeleteView(0,1);
    }
    
    Output: 
    Error	1	error C2352: 'CSplitterWnd::DeleteView' : illegal call of non-static member function
    CFormLeft has a base class of CFormView.
    It is called from MainFrm in the OnCreateClient function to create the splitter.
    MainFrm has the m_wndSplitter member which would probably be able to call a delete/create on the views. However, I am not sure how/where I would need to be at in the MainFrm to call that appropriately.

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: MFC Splitter roadblock

    Quote Originally Posted by PBarnes View Post
    Code:
    void CFormLeft::OnBnClickedButtonHello()
    {
    	// TODO: Add your control notification handler code here
    
    	//DeleteView
    	CSplitterWnd::DeleteView(0,1);
    }
    
    Output: 
    Error	1	error C2352: 'CSplitterWnd::DeleteView' : illegal call of non-static member function
    CFormLeft has a base class of CFormView.
    It is called from MainFrm in the OnCreateClient function to create the splitter.
    MainFrm has the m_wndSplitter member which would probably be able to call a delete/create on the views. However, I am not sure how/where I would need to be at in the MainFrm to call that appropriately.
    Put the button handler in your left view, then call AfxGetMainWnd() to get a pointer to your CMainFrame and from there, its m_wndSplitter

  9. #9
    Join Date
    Mar 2012
    Posts
    5

    Re: MFC Splitter roadblock

    Thanks so much for the continued support once again. This has been an incredible headache.

    This is the code from the button handler:
    Code:
    void CFormLeft::OnBnClickedButtonHello()
    {
    	// TODO: Add your control notification handler code here
    
    	//CSplitterWnd:: DeleteView and CSplitterWnd::CreateView
    	CMainFrame* x = (CMainFrame*)AfxGetMainWnd();
    	x->m_wndSplitter.DeleteView(0,1);
    	
    }
    What happens now is that I click the button...nothing appears to change. I click the button a second time and it crashes out.
    I am assuming this is because I have not replaced the view and it is just coming back to delete something that does not exist.
    (Confirmed. So far so good)

    The next step is to create the new view in that function.

    Code:
    void CFormLeft::OnBnClickedButtonHello()
    {
    	// TODO: Add your control notification handler code here
    
    	//CSplitterWnd:: DeleteView and CSplitterWnd::CreateView
    	CMainFrame* x = (CMainFrame*)AfxGetMainWnd();
    	x->m_wndSplitter.DeleteView(0,1);
    	x->m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFormRight2),CSize(100,100), x->m_pContext);
    	
    }
    You can see that I deleted the view, then attempted to create the new view. I saved the pContext from the MainFrm OnCreateclient() into a class member so I could reuse it here, as you can see.

    BEFORE button click:
    http://i.imgur.com/Cdf4g.jpg

    AFTER button click:
    http://i.imgur.com/n6bhz.jpg

    Pardon the outside links but I was not sure of the attachment policy on these forums.
    As you can see in the After button click, it looks like the second form CFormRight2 is being created, but is then stuffed in the upper left corner of the screen instead of being placed in the previous position of CFormRight (That you can see from the first picture)

    Any thoughts on what is happening that I am missing?

    Thanks again GCDEF. You have been an enormous help thus far

  10. #10
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: MFC Splitter roadblock

    For some ideas, see the "FormSwap" sample code from the "C++ Q&A" column in the December 1998 issue of Microsoft Systems Journal: http://www.microsoft.com/msj/1298/c/c1298.aspx

    Also look at the following KB article: "How to Replace a View in a Splitter Window" at http://support.microsoft.com/kb/q149257/

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured