补充一点,如果你是用静态分割产生的分割视图,可以充分利用CSplitterWnd的GetPane函数,比如,在CmylView中去获取CmyView的窗口句柄(假设CmyView在分割的0行0列):
CSplitterWnd *ps = (CSplitterWnd *)GetParent();
CmyView *pView = (CmyView *)(ps->GetPane(0,0));
pView - >m_hWnd即可获得该视图窗体的句柄
简单的很:因为你的view类不止一个,只有当你的view类活动时获取View视图(CmyView类实例产生的窗口)窗口的句柄才有意义!只要一个函数就可以解决。
CView* GetActiveView( ) const;
GetActiveView( )获得当前活动view类窗口句柄.
通过App类来获取.
头文件定义:CmyView *GetmyView();
实现:
CmyView *CmyApp::GetmyView()
{
if(m_pDocManager)
{
POSITION pos1 = m_pDocManager->GetFirstDocTemplatePosition();
while (pos1)
{
CDocTemplate *pDocTemplate = m_pDocManager->GetNextDocTemplate(pos1);
if(pDocTemplate)
{
POSITION pos2 = pDocTemplate->GetFirstDocPosition();
while (pos2)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(pos2);
if(pDoc)
{
POSITION pos3 = pDoc->GetFirstViewPosition();
while (pos3)
{
CView *pView = pDoc->GetNextView(pos3);
if(pView)
{
if(pView->IsKindOf(RUNTIME_CLASS(CmyView)))
return (CmyView*)pView;
}
}
}
}
}
}
}
return NULL;
}