Problem splitting child window in MFC MDI program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Problem splitting child window in MFC MDI program

Hybrid View

  1. #1
    Join Date
    May 2002
    Posts
    1,717

    Problem splitting child window in MFC MDI program

    After months of searching, I finally found a post that outlines how to split a child window in an MFC MDI program.

    Splitting Child Window in MFC MDI Program
    http://stackoverflow.com/questions/5...fc-mdi-program

    For my purposes, this achievement is practically useless because I cannot find a way to pass text from one CRichEditView window to another.

    Given two CRichEditView windows, CInputViewView and COutputView as child windows in an MFC MDI app, my goal is to capture text in the former and print that text in the later using a button click.

    Using what appeared to me to be a logical way to proceed, I tried variations of the following code:
    Code:
    void CMainFrame::DoSomething()
    {
    	//MessageBox(_T("Like What ?"), _T("Do Something"));
    
    	//CInputViewView * pin = (CInputViewView*) GetActiveView();
    	CInputViewView * pin = (CInputViewView*)m_wndSplitter.GetPane(0,0);
    	pin->GetWindowTextW(m_csDisplay);
    	MessageBox(m_csDisplay);
    	//CInputViewView* pInVV = (CInputViewView*) CChildFrame
    	//long countChildren;
    	//CChildFrame * pChildFrm = (CChildFrame*) get_accChildCount(&countChildren); //this->GetAccessibleChild(VARIANT varChild, IDispatch **ppdispChild);
    	//pChildFrm->m_wndSplitter.GetPane(0, 1);
    	//pChildFrm->
    	//CString cs;
    	//cs.Format(_T("countChildren = %d"), countChildren);
    	//MessageBox(cs);
    
    }
    None of this works and even the attempt to access the pane results in an app crash in winsplit.cpp.
    Code:
    #ifdef _DEBUG
    void CSplitterWnd::AssertValid() const
    {
    	CWnd::AssertValid();
    >	ASSERT(m_nMaxRows >= 1);
    //..
    Please see attached demo.
    Appreciate any help in accessing the panes from CMainFrame. Thanks
    Attached Files Attached Files
    mpliam

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Problem splitting child window in MFC MDI program

    Mike!
    In a "standard" MDI splitter window belongs to a child frame. Why is your m_wndSplitter a member of a CMainFrame?
    Last edited by VictorN; December 5th, 2012 at 02:29 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2002
    Posts
    1,717

    Re: Problem splitting child window in MFC MDI program

    Victor,
    Why is your m_wndSplitter a member of a CMainFrame?
    I don't know. I was grasping for any possible solution at that point. Perhaps the question should be: How to access the child frame m_wndSplitter member from CMainFrame. The demo code shows a number of commented out unsuccessful attempts to do this. One of these involves some COM input that I could not figure out. The others simply don't work and/or crash the app.
    mpliam

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Problem splitting child window in MFC MDI program

    Did you look at the Microsoft samples like SCRIBBLE, VIEWEX, SwSplit?
    How did you create your application? Did you use AppWizard or you did it by hand?
    Victor Nijegorodov

  5. #5
    Join Date
    May 2002
    Posts
    1,717

    Re: Problem splitting child window in MFC MDI program

    Thanks Victor. I'd forgotten about viewex. Viewex turned out to have at least one way of doing what I wanted. Namely, it uses the GetDocument() pointer in the output view to capture the desired string and display it as text using OnUpdate. The doc string is a public CString which can be readily accessed from both the CMainFrame and COutView classes.

    The critical code is:
    Code:
    // in MainFrm.cpp
    void CMainFrame::DoSomething()
    {
    //..
    	CInputViewDoc* pDoc = (CInputViewDoc*) MDIGetActive()->GetActiveView()->GetDocument();
    	pDoc->m_csScript = m_csScript;  // should already be there ??
    	pDoc->UpdateAllViews(NULL);
    }
    
    // in OutView.cpp
    void COutputView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
    {
    	CInputViewDoc* pDoc = GetDocument();
    	m_csData = pDoc->m_csScript;
    	TRACE0("COutputView::OnUpdate : m_csScript =:\n"); OutputDebugString(m_csData); TRACE0("\n");
    	SetWindowText(m_csData);
    }
    One must provide the CInputViewDoc* GetDocument() const; and it's ancillary methods for this method to work.

    There must be many ways to accomplish the same ends, but this works for my purposes.

    Once again, Victor to the rescue. Thanks again.
    Attached Files Attached Files
    Last edited by Mike Pliam; December 20th, 2012 at 12:35 AM. Reason: Add demo
    mpliam

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center