用MFC文档视图结构 如何在分割窗口的各个视图之间传递消息

急求在今天给一个详细代码范例!!!有急用,谢谢.
2025-05-11 00:53:45
推荐回答(3个)
回答1:

通过下述代码可以完成两个分割窗口视图间的消息传递,其中CLeft为左侧视图,CSplitView为右侧视图。
void CLeft::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
CSplitView* FindView=(CSplitView*)MainFrame->m_wndSplitter.GetPane(0,1);
//FindView->point=point;
FindView->DrawPoint(point);
CView::OnLButtonDown(nFlags, point);
}
DrawPoint函数为画点函数,如下:
void CSplitView::DrawPoint(CPoint Point)
{
HDC hDC=::GetDC(m_hWnd);
SetPixel(hDC,Point.x,Point.y,RGB(255,0,0));
}
CMainFrame类中的OnCreateClient函数代码如下:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// CG: The following block was added by the Splitter Bar component.
{
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeft),CSize(200,600),pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CSplitView),CSize(100,0),pContext);
return true;

}
}
我这有源代码,可以加我qq:113035171

回答2:

可以试试通过文档通信
CRightView* CXXDoc::GetView()
{
// find the first view - if there are no views
// we must return NULL

POSITION pos = GetFirstViewPosition();
if (pos == NULL)
return NULL;

// find the first view that is a CRichEditView

CView* pView;
while (pos != NULL)
{
pView = GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CRightView)))
return (CRightView*) pView;
}

// can't find one--return NULL

return NULL;
}

回答3:

建议好好看看这篇文章,http://hi.baidu.com/xibin/blog/item/9ce6f224812f61388744f985.html