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.
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-
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.
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