CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Calling functions from different views

    Hi Everybody
    I have a splitter window and when the user clicks on one of the tool bar buttons it is supposed to call a function in each of the 2 view's. Could somebody please give me an example of how to make a function in my view class and be able to call it in my MainFrame class.
    Thanks


  2. #2
    Join Date
    Apr 1999
    Location
    SungNam KyungKi Korea
    Posts
    14

    Re: Calling functions from different views

    Apply this Problem and solution.
    Let's make three Splitter-Windows like this.

    ---------------------------------
    | CLeftPane     | |
    -----------------|  CRightPane  |
    | | |
    | CLeftBotPane   | |
    | | |
    ---------------------------------




    1) Make three Views-CLeftPane, CLeftBotPane, CRightPane from Base-Class(CView,CFormView, etc) what you want.
    2) then, make this member-variable in CMainFrame

    CSplitterWnd    m_wndChSplitter;

    3) Next, write this code in MainFrame::OnCreateClient()

    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext)
    {

    m_wndSplitter.CreateStatic(this,1,2);
    int nID=m_wndSplitter.IdFromRow(0,0);

    m_wndChSplitter.CreateStatic(&m_wndSplitter,2,1,WS_CHILD|WS_VISIBLE,nID);
    m_wndChSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftPane),CSize(100,100),pContext);
    m_wndChSplitter.CreateView(1,0,RUNTIME_CLASS(CLeftBotPane),CSize(100,100),pContext);

    m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightPane),CSize(100,100),pContext);

    m_wndSplitter.SetColumnInfo(0,100,0);
    return TRUE;
    }

    4) you'd like to access a View from another View or MainFrame.
    example! say " Call OnDraw() in CLeftBotPane class from CRightPane View.
    You can do that in this way.

    CLeftBotPane *pView=
    (CLeftBotPane *)((CSplitterWnd *)GetParent())->GetPane(0,0);

    pView->OnDraw();

    OR , in this way.

    CLeftBotPane *pView=
    (CLeftBotPane *)((CSplitterWnd *)GetParent())->GetPane(0,0);
    pView->test();
    Invalidate(FALSE);

    where test() function is a member-function in CLeftBotPane class .
    Remember the SplitterWindow is derived from CWnd.

    Is that all-right! I hope so!.



    by <I><font color=cyan>nfuox</font></I>

  3. #3
    Guest

    Re: Calling functions from different views

    Thanks tchung!!!
    That is exaclty what I was trying to do!!!


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