Getting Frame Window from my document class

I need to update the status bar and one combo box control in a rebar after loading one document or creating one.

Both the status bar and the combo box are in my CFrameWin derived class.

How can i make the update?
My application is SDI.
Is it some virutal function in CFrameWin that is called like the OnUpdate of CView?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CMainFrame* pFrame=(CMAinFrame*)AfxGetApp()->m_pMainWnd;
      CStatusBar* pStatus=&pFrame->m_wndStatusBar;
      pStatus->SetPaneText(0,"my text");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What about simply using

CMainFrame* pFrame = ( CMainFrame*) AfxGetMainWnd( );

Please use the DYNAMIC_DOWNCAST() macro to make sure you really got a pointer to what you thought you got a pointer to.

..B ekiM
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

CFrameWnd* pFrameWnd = (CFrameWnd*)pMainWnd;

(source code of appui.cpp, line 85, date 20-Sep-95, VC4.0 - I know it's not fair to cite 'ancient' MFC code, but... ;-)
jmartins71Author Commented:
Thank you all.
I will prefer shay code with the DYNAMIC_DOWNCAST.

I must say that the second comment from jkr is interesting. pMainWnd is global?!

Also since I have theApp global I do not need AfxGetMainWnd.

I will give the points to shay since the answer is from him.

> pMainWnd is global?!

No, it isn't.  I'm not sure what jkr is trying to say by posting that reference. Perhaps he could be more specific.

..B ekiM
>>I'm not sure what jkr is trying to
>>say by posting that reference

Just wanted to throw in that the MFC code shipped with VC4 also used to work with 'C'-style casts ;-)
jkr> Just wanted to throw in that the MFC code shipped
 jkr> with VC4 also used to work with 'C'-style casts ;-)

What was the point of your observation? I can't figure it out, because:

1) MFC has never used ANSI RTTI and never will. It's built with it so users of the library can use ANSI RTTI against MFC and MFC-derived classes. But ANSI RTTI is useless for MFC's purposes. I thought this was a well-known fact, but I guess you're showing it isn't.

2) The line previous to the line you quote is

      ASSERT_KINDOF(CFrameWnd, pMainWnd)

so, we already know that pFrameWnd is a CFrameWnd.  (Assuming, of course, the user has bothered to build and test a DEBUG build--which they almost always do, since it's the default target.)

3) I was suggesting use of MFC's DYNAMIC_DOWNCAST() macro, not the dynamic_downcast<> operator. That is, I was suggesting the use of CObject type inforamtion, not ANSI C++ RTTI.

4) MFC calls IsFrameWnd() on the pMainWnd pointer about four lines before the bit of code you cite. If pMainWnd is not a frame window, MFC returns from that function without doing anything to the pMainWnd.

..B ekiM
Mike, you're absolutely right - I don't want to start an argument about this issue. To boil it down: If you *know* what you're doing, a 'C'-style cast is OK, if you don't know, it's just hazardous at best...
jkr> I don't want to start an argument about this issue

Then, the purpose of your comment is even more unclear to me.

..B ekiM
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.