0

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

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

但是,这让我获得了指向 CWnd 而不是 CMyViewClass 对象的指针。

谁能向我解释我需要做什么才能访问视图对象本身,以便我可以访问 pView->ViewFunction(...); 形式的成员函数;

4

1 回答 1

3

只需投射它:

// 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将始终是 type CMyViewClass,那么您可以使用static_cast... 但我建议您不要使用 - 如果您更改布局,则没有任何风险风险。

于 2008-11-06T18:09:39.150 回答