CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    How to Access MFC Status Bar from View class?

    When I create a new MFC app, I get this status bar object in my CMainFrame class called "m_wndStatusBar." Is there any way I can access this from my View or Doc class? It would help greatly to be able to display text in it based on what happens in either class...

    Thanks a lot,

    - Chris.


  2. #2
    Join Date
    May 1999
    Location
    Atlanta, GA, USA
    Posts
    443

    Re: From "Visual C++4.0 HOW-TO"

    Hi,
    Accroding as "Visual C++ 4.0 HOW-TO". p99
    To show the caret postion of View to status bar

    static UINT indicators[] =
    { ......
    ID_INDICATOR_CARET,
    };
    //at the message map of CMyView
    afx_msg void OnUpdateCaretPos(CCmdUI* pCmdUI);

    void CMyView::OnUpdateCaretPos(CCmdUI* pCmdUI)
    {
    int nLine, nCol;
    GetCaretPosition(nLine, nCol);//determine the position of caret.
    CString str;

    str.Format("Ln %d, Col %d", nLine, nCol);

    pCmdUI->Enable(TRUE);
    pCmdUI->SetText(str);
    }

    Hope for help.
    -Masaaki Onishi-



  3. #3
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: How to Access MFC Status Bar from View class?

    your variable m_wndStatusBar is public, and you can access it from everywhere. So you may do:

    BOOL CMyView::UpdateStatusBar(int iPosition, CString &strNewText)
    {
    CMainFrame *pFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    return pFrame->m_wndStatusBar.SetPaneText(iPosition, strNewtext);
    }

    If you want to be "cleaner", you may define m_wndStatusBar as protected, and write an inline method GetStatusBar() in your method.

    HTH.

    K.

    Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

  4. #4
    Join Date
    Apr 1999
    Posts
    383

    Re: How to Access MFC Status Bar from View class?

    If you just want to display text on the status bar, use:

    CFrameWnd::SetMessageText( LPCTSTR lpszText );

    as in:

    dynamic_cast < CFrameWnd > (AfxGetMainWnd())->SetMessageText("Status message");

    Dave


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