MFC:从大型机访问视图

MFC: Accessing Views from Mainframe

本文关键字:访问 视图 大型机 MFC      更新时间:2023-10-16

我正试图从大型机访问拆分器内部的视图。目前我有这个:

CWnd*pView=m_wndSplitter.GetPane(0,0);

然而,这为我提供了一个指向CWnd的指针,而不是CMyViewClass对象。

有人能向我解释我需要做什么才能访问视图对象本身吗?这样我就可以访问pView->ViewFunction(…)形式的成员函数;

只需投射:

// using MFC's dynamic cast macro
CMyViewClass* pMyView = 
   DYNAMIC_DOWNCAST(CMyViewClass, m_wndSplitter.GetPane(0,0));
if ( NULL != pMyView )
   // whatever you want to do with it...

或:

// standard C++ 
CMyViewClass* pMyView = 
   dynamic_cast<CMyViewClass*>(m_wndSplitter.GetPane(0,0));
if ( NULL != pMyView )
   // whatever you want to do with it...

如果知道窗格0,0中的视图将始终为CMyViewClass类型,则可以使用static_cast。。。但我建议你不要——如果你改变布局,冒着问题的风险毫无意义。