Jump to content
  • Advertisement
Sign in to follow this  
ApolloCay

Need pointer to view class (MFC)

This topic is 4827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My MDI application opens 4 custom windows with its own frame and view classes. These windows stay open all the time. Now I want to be able to access the functions in these views from my main app class. How can I point to one of the windows (CView) from my app class? I need something like this: // From main app class CWnd* mainFrame = AfxGetMainWnd(); CRightWindow* rightView =(CRightWindow*)mainFrame->GetWindow("Window ID of some sort to pick the right window"); CRightWindow->CallFunction(); I need to be able to call any one of the 4 child windows.

Share this post


Link to post
Share on other sites
Advertisement
Store four pointers of your wanted CView-derived type in CMainFrame and set these in the constructors of your view classes.

Alternative:

Use your CDocument and enumerate your views to retrieve the view pointers (GetFirstViewPosition,GetNextView).

Share this post


Link to post
Share on other sites
Can you give me a basic dummy example of what you mean. I'm not quite following how this would work (I'm new to MFC). Thanks

Share this post


Link to post
Share on other sites
For the first case:

In your mainfrm.h:

CYourView* m_pMyView1;
CYourSecondView* m_pMyView2;
CYourThirdView* m_pMyView3;
CYourFourthView* m_pMyView4;



In your YourView.cpp:

CYourView::CYourView( ... )
{

( (CMainFrame*)theApp.m_pMainWnd )->m_pMyView1 = this;

}


and so on for the other view types.

It's not exactly elegant or nice, but then again, MFC ain't either.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!