问题描述:在CTabView派生类中添加多个CFormView类的试图页,在处理消息时需要获得接收消息的窗口的句柄,为了得到不同CFormView派生类的句柄,在网上查了好久才找到的点提示;现将解决方案描述如下,以供参考。
I have an MFC SDI app using a view derived from the feature pack CTabView. My tabs are derived from CFormView and have various controls on them.
To add tabs to my view during creation, I just do this in the OnCreate of my CTabView-derived class:
int AddView( CRuntimeClass* pViewClass, const CString& strViewLabel, int iIndex=-1, CCreateContext* pContext=NULL );
eg:AddView(RUNTIME_CLASS(CChartView), “chart”,101);
CChartView * p = dynamic_cast<CChartView *>(GetTabView()->GetTabControl().GetTabWndNoWrapper(inspos));//
Note:
GetTabView()//得到CTabView派生类的指针
{
CView * pView = GetActiveView();
CMFCTabView *pParent = (CMFCTabView *)pView->GetParent();
CTabView *pTabView = (CTabView *)pParent ->GetParent();
return pTabView ;
}
方案中用到一个关键的函数,看看MSDN对该函数的解释:
Returns a pointer to the control that resides on a tab, even if the control has a wrapper.
The zero-based index of a tab.
CView *pCurrentView = GetActiveView();//得到当前活动TabView的指针
int tabIndex = GetTabView()->FindTab(pCurrentView->m_hWnd); //得到当前活动TabView的index
if(tabIndex ?= 欲打开的TabView) 可以判断某个特定的TabView是否active