jmartins71
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
..B ekiM
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... ;-)
(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... ;-)
ASKER
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.
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
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 ;-)
>>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
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
Then, the purpose of your comment is even more unclear to me.
..B ekiM
CMainFrame* pFrame = ( CMainFrame*) AfxGetMainWnd( );
?