Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get access to CMyView variables from CMainFrame in MFC

How to get access to CMyView variables from CMainFrame in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++learning
14 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member 15033704

    Dear David I meant: I have some public variables in CMyView class.These variables must be updated from INSIDE the CMyMainFrame class. How can I get access from CMyMainFrame to public variables in CMyView class? In fact,how can I update public variables I have in CMyView class from CMyMainFrame class? Best Regads

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #5

    Member 15033704 wrote:

    How can I get access from CMyMainFrame to public variables in CMyView class?

    Have you tried calling GetActiveView()?

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    M 1 Reply Last reply
    0
    • L Lost User

      Your CMyView object should be a member of the CMainFrame, so you just need to add a public method to CMyView that does what you want.

      M Offline
      M Offline
      Member 15033704
      wrote on last edited by
      #6

      Dear Friend I did it,Because it seemed very easy, but then I get CDocument ERROR! After adding #include "CMyView.h" into CMyMainFrame, I get CDocument ERROR! I searched a lot on the internet, all say use GetActiveView() but it does not work! Best Regards

      L 1 Reply Last reply
      0
      • M Member 15033704

        Dear Friend I did it,Because it seemed very easy, but then I get CDocument ERROR! After adding #include "CMyView.h" into CMyMainFrame, I get CDocument ERROR! I searched a lot on the internet, all say use GetActiveView() but it does not work! Best Regards

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        Sorry, we cannot guess what you are doing. You need to show the code that that you are running, and explain exactly what error(s) you see and where it happens.

        M 1 Reply Last reply
        0
        • D David Crow

          Member 15033704 wrote:

          How can I get access from CMyMainFrame to public variables in CMyView class?

          Have you tried calling GetActiveView()?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          M Offline
          M Offline
          Member 15033704
          wrote on last edited by
          #8

          Yes, dear friend I write the following code inside MyCMainFrame file : MyCView*pView = static_cast (GetActiveWindow()); then when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR!!!

          1 Reply Last reply
          0
          • L Lost User

            Sorry, we cannot guess what you are doing. You need to show the code that that you are running, and explain exactly what error(s) you see and where it happens.

            M Offline
            M Offline
            Member 15033704
            wrote on last edited by
            #9

            Dear friend I write the following code inside MyCMainFrame.cpp file : MyCView*pView = static_cast (GetActiveWindow()); pView->m_CMyView_Pulic_Variable; To get access to public variables inside CMyview class. But when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR! In fact, I just want to change a public variable inside CMyView class from MyCMainFrame. How can I get access to CMyView class public variables, from MyCMainFrame? Best Regards

            L 1 Reply Last reply
            0
            • M Member 15033704

              Dear friend I write the following code inside MyCMainFrame.cpp file : MyCView*pView = static_cast (GetActiveWindow()); pView->m_CMyView_Pulic_Variable; To get access to public variables inside CMyview class. But when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR! In fact, I just want to change a public variable inside CMyView class from MyCMainFrame. How can I get access to CMyView class public variables, from MyCMainFrame? Best Regards

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              Why are you using GetActiveWindow rather than GetActiveView? And what is the exact text of the error you receive and where does it occur?

              M 1 Reply Last reply
              0
              • L Lost User

                Why are you using GetActiveWindow rather than GetActiveView? And what is the exact text of the error you receive and where does it occur?

                M Offline
                M Offline
                Member 15033704
                wrote on last edited by
                #11

                Dear Richard Firstly "HAPPY NEW YEAR" Many thanks for your help, I was engaged with the CMyDoc error, finally I found it, simply it was redefinition of CMyDoc header in 2 different classes that I never guessed such mistake. Best Regards

                L 1 Reply Last reply
                0
                • M Member 15033704

                  Dear Richard Firstly "HAPPY NEW YEAR" Many thanks for your help, I was engaged with the CMyDoc error, finally I found it, simply it was redefinition of CMyDoc header in 2 different classes that I never guessed such mistake. Best Regards

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  Glad you found it. Happy New Year (as much as it can be) to you also.

                  1 Reply Last reply
                  0
                  • M Member 15033704

                    Hi Everybody I have a SDI project. I have created some dynamics ComboBoxes in my toolbar by ".Create" in my CMainFrame Class. My ComboBoxes are working properly in CMainFrame but I want to set some of my variables in CMyView class by void CMainFrame::OnSelchange_My_Dynamics_Combo_1(). I did my best but I was not successful to send/set data to/at CMyView class. I am beginner in MFC, Please guide me. Best Regards

                    1 Offline
                    1 Offline
                    11917640 Member
                    wrote on last edited by
                    #13

                    For future use: MFC Doc/View: How to obtain a pointer to various objects?[^]

                    M 1 Reply Last reply
                    0
                    • 1 11917640 Member

                      For future use: MFC Doc/View: How to obtain a pointer to various objects?[^]

                      M Offline
                      M Offline
                      Member 15033704
                      wrote on last edited by
                      #14

                      Excellent, Thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups