Globalizing the StausBar

I'm a VisualBasic expert. i Used to be a CPP expert when DOS was around.
now, trying MFC - i found that unlike VB - the Statusbar is not a GLOBAL resource (or whatever u call it....).
in VB you can address and change the StatusBar text from anywhere in your code because it's a PUBLIC control of the
form it belongs to which is PUBLIC itself.
is there a way in MFC to simplify usage of the code from
anywhere to change text in statusbar panels ?
Who is Participating?
kenghwangConnect With a Mentor Commented:
CMainFrm class from "MainFrm.h"  file  has a data member call "m_wndStatusBar" which declare privately. Declare it on public section and you can access it by this command anywhere of the code. eg, view.cpp

char temp[10] = "abc";
CMainFrame* pAppFrame = (CMainFrame *) AfxGetApp()->m_pMainWnd;
pAppFrame->m_wndStatusBar.SetWindowText( temp );

hopefully this is the answer u want
For a SDI and MDI appwizard generated application the status bar control is a data member of the CMainFrame class. To access it globally you can:

CStatusBar* pStatusBar =
  ((CMainFrame*) AfxGetMainWnd())->GetStatusBar();

I hope this helps.
AnswerTheManAuthor Commented:
tnx SteveGTR, but your answer is not an answer to the question i asked.
here is MSDN page reffering to the function you suggested :
BOOL GetStatusBar( ) const;

Return Value

Nonzero if the status bar can be displayed; otherwise zero.


Call this member function to determine whether the WebBrowser control displays a status bar.

Applies to Internet Explorer. If you use this call with a WebBrowser control, it will return no error, but it will ignore this call.

1) who talked about the CLASS CHtmlView ???
2) i did not asked for a Boolean to know if the StatusBar can be displayed.
3) i did not mentioned WebBrowser control in my question.
4) Internet Explorer ???
CHtmlView??? I wasn't referring to CHtmlView... I was referring to CMainFrame::GetStatusBar(). Remember in C++ that you may have functions with the same name... Try out my original code and see that it will work. It is the same as that proposed by kenghwang.

Good Luck,
AnswerTheManAuthor Commented:
Ok, kenghwang. it was all my mistake.
what you suggested is exactly what i did before i put the question here, but
i was sure that the CMainFrame header is called that's
why my #include raised errors.....
only in your answer i've noticed that the file name is MainFrm.h... and then
my privius code worked fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.