HansElsen
HansElsen

Reputation: 1753

Can't access CChildView in CWinAppEx

I have an Single document MFC application in C++ and I'm wondering if I can call a function declared in the CChildView from my CWinAppEx class.

CChildView is of type CWnd.

So far I tried:

CChildView* view = (CChildView*)m_pActiveWnd;

And

CWnd* pWndMain = AfxGetMainWnd();
CChildView* view = (CChildView*) pWndMain;

I'm relatively new in this type of architectures so I hope someone can give me some advice.

Upvotes: 0

Views: 270

Answers (1)

Mark Taylor
Mark Taylor

Reputation: 1851

Casting doesn't help, because the main window is not a CChildView class nor is it inherited from one. It is a CFrameWnd, which is the class that manages views in the Doc/View Architecture.

You can get a pointer to a view windows like this.

 CView* pActiveView = ((CFrameWnd*) AfxGetMainWnd())->GetActiveView();

Upvotes: 1

Related Questions