Getting Frame Window from my document class

Hi,
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?

Thanks.
jmartins71Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Shay050799Connect With a Mentor Commented:
CMainFrame* pFrame=(CMAinFrame*)AfxGetApp()->m_pMainWnd;
      CStatusBar* pStatus=&pFrame->m_wndStatusBar;
      pStatus->SetPaneText(0,"my text");
0
 
jkrCommented:
What about simply using

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

?
0
 
mikeblasCommented:
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
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
jkrCommented:
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... ;-)
0
 
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.

0
 
mikeblasCommented:
> 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
0
 
jkrCommented:
>>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 ;-)
0
 
mikeblasCommented:
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
0
 
jkrCommented:
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...
0
 
mikeblasCommented:
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
0
All Courses

From novice to tech pro — start learning today.