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. ATL / WTL / STL
  4. How can I get access to CXXView variables from a Parent Class in MFC

How can I get access to CXXView variables from a Parent Class in MFC

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++help
5 Posts 2 Posters 41 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 Offline
    M Offline
    Member 15033704
    wrote on last edited by
    #1

    Hello everybody I have an SDI solution in MFC. I have created a class with the name of "CLASS A" and class CXXView : public CView, public CLASS A How can I get access to CXXView variables from CLASS A in MFC? Indeed; DOSE NOT WORK ==> CXXView * pCurrentView = static_cast(GetActiveView()); Because of this error: GetActiveView() is undifined (XXView.h is included in CLASS A) Best Regads

    V 1 Reply Last reply
    0
    • M Member 15033704

      Hello everybody I have an SDI solution in MFC. I have created a class with the name of "CLASS A" and class CXXView : public CView, public CLASS A How can I get access to CXXView variables from CLASS A in MFC? Indeed; DOSE NOT WORK ==> CXXView * pCurrentView = static_cast(GetActiveView()); Because of this error: GetActiveView() is undifined (XXView.h is included in CLASS A) Best Regads

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Member 15033704 wrote:

      ndeed; DOSE NOT WORK ==> CXXView * pCurrentView = static_cast<cxxview*>(GetActiveView()); Because of this error: GetActiveView() is undifined

      Of course it does not work! GetActiveView is a method of CFrameWnd class, but your "CLASS A" has nothing to do with the CFrameWnd! BTW, why do you think you need to "get access to CXXView variables from CLASS A"? :confused:

      M 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Member 15033704 wrote:

        ndeed; DOSE NOT WORK ==> CXXView * pCurrentView = static_cast<cxxview*>(GetActiveView()); Because of this error: GetActiveView() is undifined

        Of course it does not work! GetActiveView is a method of CFrameWnd class, but your "CLASS A" has nothing to do with the CFrameWnd! BTW, why do you think you need to "get access to CXXView variables from CLASS A"? :confused:

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

        Many thanks for your help. In fact, I do some calculations in CLASS A, then I want to show the results of those calculations in CXXView class by using pDC->Textout(........). I use InvalidateRect(NULL,NULL,FALSE) to redraw the view, but as you know it is not a good idea. I have defined a CRect in CXXView class that I know those texts are going to be shown in that rect and I want to Invalidate just that rect from CLASS A. On the other hand, while I am in CLASS A and using InvalidateRect function, this function needs 2 parameters of CXXView class to be done that are HWND and CRect is defined in class CXXView. Best Regads

        V 1 Reply Last reply
        0
        • M Member 15033704

          Many thanks for your help. In fact, I do some calculations in CLASS A, then I want to show the results of those calculations in CXXView class by using pDC->Textout(........). I use InvalidateRect(NULL,NULL,FALSE) to redraw the view, but as you know it is not a good idea. I have defined a CRect in CXXView class that I know those texts are going to be shown in that rect and I want to Invalidate just that rect from CLASS A. On the other hand, while I am in CLASS A and using InvalidateRect function, this function needs 2 parameters of CXXView class to be done that are HWND and CRect is defined in class CXXView. Best Regads

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Why are you trying to do it from the "CLASS A" instance? Just implement it in the CXXView class. Or, if your "CLASS A" already has a method that does what you need then just call it from within the instance of CXXView class (of course, this method must be declared as public or protected, not as private).

          M 1 Reply Last reply
          0
          • V Victor Nijegorodov

            Why are you trying to do it from the "CLASS A" instance? Just implement it in the CXXView class. Or, if your "CLASS A" already has a method that does what you need then just call it from within the instance of CXXView class (of course, this method must be declared as public or protected, not as private).

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

            Dear Victor Nijegorodov Before of all, many thanks for your advice. The structure of solution is as follows: Calculations are to be done in CLASS A; and class CXXView : public CView, public CALSS A CXXView dose not know when these Calculations are done; When CLASS A send a message to CXXView, then CXXView execute other methods; The message is InvalidateRect; The problem is that CXXView dose not know when these Calculations are done. On the ther hand, I don't want to define a flag and check it continuously if Calculations are done or not? so CXXView has to await receiving InvalidateRect message from CLASS A I tried to define an instance of CXXView class within the CLASS A: CXXView* pCurrentView; CRect rect = pCurrentView->m_Rect_zone; HWND pWnd = pCurrentView->GetSafeHwnd(); InvalidateRect(NULL, NULL, FALSE); but I was not succeeded because of this compiler error: Uninitialized variable pCurrentView One macro or something like that is missing here (CXXView* pCurrentView;) which I am not familiar with that. Best Regards

            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