How can I get access to CXXView variables from a Parent Class in MFC
-
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
-
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
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:
-
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:
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
-
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
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).
-
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).
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