单文档中怎么调用View类的成员函数
求教:单文档中如何调用View类的成员函数?
比如,我建立了一个叫Test的单文档工程,然后在CTestView类里添加了一个成员函数A,然后我在工程新添加了一个CMyTest的c++类,怎么样才能在CMyTest里调用CTestView类里的成员函数A?希望大牛回帖的时候讲的详细一点,以前从来没接触过这样的问题,就把我当成小白好了.......
------解决方案--------------------
比如,我建立了一个叫Test的单文档工程,然后在CTestView类里添加了一个成员函数A,然后我在工程新添加了一个CMyTest的c++类,怎么样才能在CMyTest里调用CTestView类里的成员函数A?希望大牛回帖的时候讲的详细一点,以前从来没接触过这样的问题,就把我当成小白好了.......
------解决方案--------------------
- C/C++ code
class CTestView { private: int a; public: //方法1 int *Geta() { return &a; } //方法2 int Get_a() { return a; } int Set_a(int a_temp) { a = a_temp; return a; } }test; class CMyTest { public: //方法1用法 void testNo1() { *(test.Geta()) = 10; printf("%d\n",*(test.Geta())); } //方法2用法 void testNo2() { test.Set_a(10); printf("%d\n",test.Get_a()); } };
------解决方案--------------------
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
CTestView* pView = (CTestView*)pFrm->GetActiveView();
pView->A();
------解决方案--------------------
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
CYourDoc* pDoc = (CYourDoc*)pMainFrame->GetActiveDocument();
CView *pView = NULL;
CTestView* pTestView = NULL;
POSITION posi = pDoc->GetFirstViewPosition();
while(posi!=NULL)
{
pView = pDoc->GetNextView(posi);
if(!pView)
{
return;
}
if(pView->IsKindOf(RUNTIME_CLASS(CTestView)) )
{
pTestView = (CTestView*)pView;//获取视类CTestView指针
break;
}
}
pTestView->A();