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 access C..Doc var. from any class ?

how to access C..Doc var. from any class ?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 3 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.
  • F Offline
    F Offline
    Fred D
    wrote on last edited by
    #1

    hi all, does anybody know a way to access to C..Doc (or C..View) variables from ANY class in a project ? I've tried : // in a constructor of another class CMtsBaseDoc* pDocument = ((CMtsBaseView*)(AfxGetApp()->m_pMainWnd))->pDoc; // and even this one.. CMtsBaseApp* pApp = (CMtsBaseApp*)AfxGetApp(); CMtsBaseDoc* pDocument = (pApp->GetMyView())->pDoc; // using GetMyView() from one article in codeproject but nothing ! I just cannot get the right @ for my pDocument !? 'cos pDoc and pDocument should have the same @... and i get 2 different @ any help thanx Fred

    H 1 Reply Last reply
    0
    • F Fred D

      hi all, does anybody know a way to access to C..Doc (or C..View) variables from ANY class in a project ? I've tried : // in a constructor of another class CMtsBaseDoc* pDocument = ((CMtsBaseView*)(AfxGetApp()->m_pMainWnd))->pDoc; // and even this one.. CMtsBaseApp* pApp = (CMtsBaseApp*)AfxGetApp(); CMtsBaseDoc* pDocument = (pApp->GetMyView())->pDoc; // using GetMyView() from one article in codeproject but nothing ! I just cannot get the right @ for my pDocument !? 'cos pDoc and pDocument should have the same @... and i get 2 different @ any help thanx Fred

      H Offline
      H Offline
      Hydralisk
      wrote on last edited by
      #2

      CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveDocument();

      J 2 Replies Last reply
      0
      • H Hydralisk

        CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveDocument();

        J Offline
        J Offline
        JennyP
        wrote on last edited by
        #3

        Hello, I tried using this in a DialogBar function to point back to the Document function to get some UINT values. When calling the function from the Document, it works fine. However, when calling it from the DialogBar using the pDoc pointer, the Document function cannot access any of the Document's members--even the debugger cannot "evaluate" the member variables. Both function and members are public in my case. So it appears that this pointer is not a full-feature pointer....? I'm interested both in a solution to get Document function (data) from 'remote' classes such as my DialogBar AND (academically) what is going on in this case--why doesn't it work from a nuts & bolts standpoint. Thanks! :) JennyP

        1 Reply Last reply
        0
        • H Hydralisk

          CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveDocument();

          J Offline
          J Offline
          JennyP
          wrote on last edited by
          #4

          After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks! CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); JennyP

          F H 2 Replies Last reply
          0
          • J JennyP

            After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks! CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); JennyP

            F Offline
            F Offline
            Fred D
            wrote on last edited by
            #5

            even by doind so, i've got a descent value of pDoc but the values it holds are all set to 0 ? :confused: i keep looking....

            J 2 Replies Last reply
            0
            • F Fred D

              even by doind so, i've got a descent value of pDoc but the values it holds are all set to 0 ? :confused: i keep looking....

              J Offline
              J Offline
              JennyP
              wrote on last edited by
              #6

              Now that I think of it, my values were zero, but I expected them to be zero. I'll have to set my values to be some non-zero value and see what happens. If they remain zero, then it's likely pointing to a new and separate instance of CDoc that was just created.... hmmm... JennyP

              1 Reply Last reply
              0
              • F Fred D

                even by doind so, i've got a descent value of pDoc but the values it holds are all set to 0 ? :confused: i keep looking....

                J Offline
                J Offline
                JennyP
                wrote on last edited by
                #7

                I found that I have the exact same problem. I'm going to cludge around it by passing the other class's pointer to CDoc and doing it in reversed. It's worked for me before. If you find a solution, I'd be VERY interested! Thanks! JennyP

                J 1 Reply Last reply
                0
                • J JennyP

                  I found that I have the exact same problem. I'm going to cludge around it by passing the other class's pointer to CDoc and doing it in reversed. It's worked for me before. If you find a solution, I'd be VERY interested! Thanks! JennyP

                  J Offline
                  J Offline
                  JennyP
                  wrote on last edited by
                  #8

                  Actually, I found that my pDoc (attained as shown in previous messages above) DOES WORK. I had another problem with my pDoc->Function that returned 0s. Anyway,..... works for me.... maybe you should double check your document values? I saw the values were good in the debugger and simply was being returned incorrectly from a function. Good luck. JennyP

                  F 1 Reply Last reply
                  0
                  • J JennyP

                    After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks! CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); JennyP

                    H Offline
                    H Offline
                    Hydralisk
                    wrote on last edited by
                    #9

                    I think your applcation is a base on MDI,so you must invoke GetActiveFrame.and mine is base on SDI,so....

                    1 Reply Last reply
                    0
                    • J JennyP

                      Actually, I found that my pDoc (attained as shown in previous messages above) DOES WORK. I had another problem with my pDoc->Function that returned 0s. Anyway,..... works for me.... maybe you should double check your document values? I saw the values were good in the debugger and simply was being returned incorrectly from a function. Good luck. JennyP

                      F Offline
                      F Offline
                      Fred D
                      wrote on last edited by
                      #10

                      it's alright i found my mistake : a problem of where i declared the pDocument ! so now this part of code works fine, and i get access to the real values, all good. PgGPS::PgGPS() : CPropertyPage(PgGPS::IDD) { pDocument = NULL; pDocument = (CMtsBaseDoc*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); //{{AFX_DATA_INIT(PgGPS) //}}AFX_DATA_INIT } by doing so in the constructor pDocument, accessible anywhere within the class, allows you to access to all the variables and methods in C..Doc. :cool: Fred

                      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