Accessing MFC MDI View Class data members from a different MFC MDI view class ?

This is a discussion on Accessing MFC MDI View Class data members from a different MFC MDI view class ? within the Windows Programming forums, part of the Platform Specific Boards category; I have data members i.e, int, CString etc. in my MFC MDI View class, That I need to access from ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    26

    Accessing MFC MDI View Class data members from a different MFC MDI view class ?

    I have data members i.e, int, CString etc. in my MFC MDI View class,
    That I need to access from a different view class
    e.g.
    Code:
    class CMFCApplication1View : public CView
    {
    Public:
       CString myString;
       int a;
    
    etc...
    ...
    };
    
    I need to access the above variables from a different MDI view, etc...
    e.g.
    class CPropertiesWnd : public CDockablePane
    {
    ...
    };
    This is a properties window, I know how to display variables.
    But I do not know how to access these variables from a different class

    I cant show the variables that change in the View because I don't know how to access them.

    How do I do that ?

    Please help,
    Thank you.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    26
    Do this...

    CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->GetMainWnd();

    // Get the active MDI child window.
    CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();

    // or CMDIChildWnd *pChild = pFrame->MDIGetActive();

    // Get the active view attached to the active MDI child window.
    yourMDIView *pView = (yourMDIView*)pChild->GetActiveView();

    Now use this to access any member in scope of yourMDIView class...
    pView->a = 1;

    That how to do it.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    26
    NO...

    This will not work, you cannot include the view's header file in the PropertiesWnd.cpp or .h file.
    Therefore this code will not compile.

    Also, This forum area seems dead

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    MFC is not very popular now (or when it was at it's peak) and so not many people are left that coded in MFC.

    I have not coded MDI MFC for at least a decade and have forgotten how to do this....

    You say you can not add the required header, have you tried a forward declaration?

    Have you tried passing the data into the Property page using the CREATESTRUCT?

    Have you tried a global pointer to the view and get/set member functions?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing protected class members
    By Korhedron in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2010, 08:12 AM
  2. Accessing members of parent class
    By Snip in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2006, 01:28 PM
  3. Class members accessing problems
    By HumbuckeR in forum C++ Programming
    Replies: 5
    Last Post: 05-17-2006, 05:29 PM
  4. How to rebuild class view data
    By VirtualAce in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2005, 12:28 PM
  5. accessing Class members
    By fizisyen in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2004, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21