Link to home
Start Free TrialLog in
Avatar of markgooding
markgooding

asked on

How to get the runtime class?

I've created a Doc/View architecture application using MFC. I have a number of view class types derived from a parent view class, which itself is derived from CView. During the program execution I get the currently active view using line 1 below.  I want to then call a function on that view, but at the child class level not the parent, or CView, level. Is there a way to do that without repeating lines 3-5 below for each class?
CView* testview = ((CFrameWnd*) AfxGetApp()->m_pMainWnd))->GetActiveView();
 
if(testview->IsKindOf(RUNTIME_CLASS(CMyChildView))){
 ((CMyChildView*)testview)->DoSomething();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markgooding
markgooding

ASKER

I'd always wondered what virtual did. Never got around to looking that up. Thanks!