FrameWnd中多个view切换

响应TreeView中Item点击然后动态切换FrameWnd中的view.

在FrameWnd中加上响应消息函数然后新建view,例:

LRESULT CRightFrm::OnAddOutMessage(WPARAM wParam, LPARAM lParam)
{
     m_AddOutView = new CAddOut();//CAddOut是事先建好的view类,基于FormView,放几个控件在上面
    CRect cr;
    this->GetWindowRect(&cr);
    m_AddOutView->Create(NULL, NULL,WS_CHILD,CRect(0,0,cr.Width(),cr.Height()),this,1001);
    m_AddOutView->ShowWindow(SW_SHOW);
    return 0;

然 后编译运行,点击对应树的Item,可以看到CAddOut显示出来了,可是点击此view上的任何东西(控件等)都没反应,可见这样写还是不够的,分析 原因,此view现在是FrameWnd的Client区,也就是现在Client区是无效的,所以没响应,因此,再加上一个函数,使Client区变得 有效:

BOOL CRightFrm::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    // TODO: Add your specialized code here and/or call the base class
    
    return TRUE;//CFrameWnd::OnCreateClient(lpcs, pContext);
}

再编译运行,CAddOut上的东西终于有反应啦

原文地址:https://www.cnblogs.com/jayceli/p/2428651.html