Click to See Complete Forum and Search --> : How to Access MFC Status Bar from View class?


Chris Tessmer
April 3rd, 1999, 06:44 PM
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.

Masaaki
April 3rd, 1999, 08:27 PM
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-

Karl
April 6th, 1999, 04:47 AM
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.

Dave Lorde
April 6th, 1999, 06:08 AM
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