---------------------
| | |
| | |
| | |
---------------------
其中左面是一个象QQ一样的抽屉视图,
右边是框架窗口的子类,
我已经做了几个这样的框架子类。
想实现的就是:
当点击左面的选项时,右面可以在不同的框架子类之间切换。
我只知道静态分割,但是好象不行,静态分割不能实现右面的切换。
请指点!
15 个解决方案
#1
http://www.codeguru.com/Cpp/W-D/splitter/article.php/c1529/
#2
你这样的功能完全可以使用Dialog界面来完成。
然后创建一个ChildDialog.然后不进行显示,在合适的时候(左边被点击)的时候,显示就可以了。
创建步骤可以象这样,生成一个Dialog Base的应用程序,左边放上OutLook Bar,右边在正确的位置上放上一个Static控件,大小调整好(用来表示将来我们要显示的Dialog大小和位置)
然后创建子Dialog,关联变量,在初始化代码中创建他,Visible设为FALSE,在合适的时候ShowWindow(SW_SHOW)就可以了。
实现起来比单文档界面容易。
然后创建一个ChildDialog.然后不进行显示,在合适的时候(左边被点击)的时候,显示就可以了。
创建步骤可以象这样,生成一个Dialog Base的应用程序,左边放上OutLook Bar,右边在正确的位置上放上一个Static控件,大小调整好(用来表示将来我们要显示的Dialog大小和位置)
然后创建子Dialog,关联变量,在初始化代码中创建他,Visible设为FALSE,在合适的时候ShowWindow(SW_SHOW)就可以了。
实现起来比单文档界面容易。
#3
http://community.csdn.net/Expert/topic/3857/3857680.xml?temp=.225506
#4
有下载吗
#5
动态创建、切换、销毁视图
#6
to :vcleaner
//你的网站我打不开
to :Daniel22_cn
//因为我要用数据库,所以想用文档和视图
to: laiyiling
怎么得到 pContext?
//你的网站我打不开
to :Daniel22_cn
//因为我要用数据库,所以想用文档和视图
to: laiyiling
怎么得到 pContext?
#7
一段代码供参考:
void CMainFrame::SwitchView(VIEWTYPE vwType)
{
CRect rect;
GetClientRect(&rect);
CSize right(rect.Width()*3/4, rect.Height());
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveView()->GetDocument();
Context.m_pCurrentFrame = this;
Context.m_pLastView = (CView*)m_wndSplitter.GetPane(0,1);
Context.m_pNewDocTemplate = Context.m_pCurrentDoc->GetDocTemplate();
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,Context.m_pNewViewClass,right, &Context);
CView* pView =(CView*) m_wndSplitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();
pView->OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}
void CMainFrame::SwitchView(VIEWTYPE vwType)
{
CRect rect;
GetClientRect(&rect);
CSize right(rect.Width()*3/4, rect.Height());
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveView()->GetDocument();
Context.m_pCurrentFrame = this;
Context.m_pLastView = (CView*)m_wndSplitter.GetPane(0,1);
Context.m_pNewDocTemplate = Context.m_pCurrentDoc->GetDocTemplate();
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,Context.m_pNewViewClass,right, &Context);
CView* pView =(CView*) m_wndSplitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();
pView->OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}
#8
www.vckbase.com
#9
我的建议是:直接对CJLib60里的Demo_Outlook进行修改,那里面基本实现了你说的要求。另外,静态分割是可以的,右边的视图是可以切换的,切换过程是创建不同形式的视图对象,调用SwithView()显示新试图,隐藏久的视图。
贴一段例子:
CView * CRightFrame::SwitchView(int vnViewId)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
switch (vnViewId)
{
case VIEW_OUTLOOKDESC:
pNewActiveView = (CView*) m_pDescView;
break;
case VIEW_OUTLOOKLIST:
pNewActiveView = (CView*) m_pListView;
break;
case VIEW_DAYPLAN:
pNewActiveView = (CView *)m_pDayPlanView;
break;
case VIEW_LEFT:
pNewActiveView = (CView*) m_pLeftView;
break;
case VIEW_HTML:
pNewActiveView = (CView*) m_pHtmlView;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return pNewActiveView;
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = vnViewId;
RecalcLayout();
}
return pNewActiveView;
贴一段例子:
CView * CRightFrame::SwitchView(int vnViewId)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
switch (vnViewId)
{
case VIEW_OUTLOOKDESC:
pNewActiveView = (CView*) m_pDescView;
break;
case VIEW_OUTLOOKLIST:
pNewActiveView = (CView*) m_pListView;
break;
case VIEW_DAYPLAN:
pNewActiveView = (CView *)m_pDayPlanView;
break;
case VIEW_LEFT:
pNewActiveView = (CView*) m_pLeftView;
break;
case VIEW_HTML:
pNewActiveView = (CView*) m_pHtmlView;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return pNewActiveView;
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = vnViewId;
RecalcLayout();
}
return pNewActiveView;
#10
谢谢大家热心的解答。
我看你们都用到了m_wndSplitter.DeleteView(0,1);
但是我在使用时总是在这一句出现错误,
弹出(终止,重试,忽略警告框),
如果选择忽略可以实现切换,
但为什么会出现这个框,怎么解决?
我在OnCreateClient中创建视图时语句如下:
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200), pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFrame1),CSize(200,200), pContext);
我看你们都用到了m_wndSplitter.DeleteView(0,1);
但是我在使用时总是在这一句出现错误,
弹出(终止,重试,忽略警告框),
如果选择忽略可以实现切换,
但为什么会出现这个框,怎么解决?
我在OnCreateClient中创建视图时语句如下:
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200), pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFrame1),CSize(200,200), pContext);
#11
DeleteView删除动态分割创建的视图,CreateStatic是创建的静态分割视图
#12
那应怎么解决呢?
#13
mousefj说清楚了啊,DeleteView是删除动态分割的视图的,创建动态分割的视图用CSplitterWnd::Create函数。
用CreateStatic是静态分割,用ShowWindow隐藏、显示子视图
用CreateStatic是静态分割,用ShowWindow隐藏、显示子视图
#14
参考下面两篇文章:
“TN029: Splitter Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn029.asp
“Multiple Document Types, Views, and Frame Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Multiple_Document_Types.2c_.Views.2c_.and_Frame_Windows.asp
“TN029: Splitter Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn029.asp
“Multiple Document Types, Views, and Frame Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Multiple_Document_Types.2c_.Views.2c_.and_Frame_Windows.asp
#15
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRegLeftView), CSize(100, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRegExplorerView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
m_wndSplitter.SetColumnInfo(0, 200, 100);
return TRUE;
}
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRegLeftView), CSize(100, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRegExplorerView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
m_wndSplitter.SetColumnInfo(0, 200, 100);
return TRUE;
}
#1
http://www.codeguru.com/Cpp/W-D/splitter/article.php/c1529/
#2
你这样的功能完全可以使用Dialog界面来完成。
然后创建一个ChildDialog.然后不进行显示,在合适的时候(左边被点击)的时候,显示就可以了。
创建步骤可以象这样,生成一个Dialog Base的应用程序,左边放上OutLook Bar,右边在正确的位置上放上一个Static控件,大小调整好(用来表示将来我们要显示的Dialog大小和位置)
然后创建子Dialog,关联变量,在初始化代码中创建他,Visible设为FALSE,在合适的时候ShowWindow(SW_SHOW)就可以了。
实现起来比单文档界面容易。
然后创建一个ChildDialog.然后不进行显示,在合适的时候(左边被点击)的时候,显示就可以了。
创建步骤可以象这样,生成一个Dialog Base的应用程序,左边放上OutLook Bar,右边在正确的位置上放上一个Static控件,大小调整好(用来表示将来我们要显示的Dialog大小和位置)
然后创建子Dialog,关联变量,在初始化代码中创建他,Visible设为FALSE,在合适的时候ShowWindow(SW_SHOW)就可以了。
实现起来比单文档界面容易。
#3
http://community.csdn.net/Expert/topic/3857/3857680.xml?temp=.225506
#4
有下载吗
#5
动态创建、切换、销毁视图
#6
to :vcleaner
//你的网站我打不开
to :Daniel22_cn
//因为我要用数据库,所以想用文档和视图
to: laiyiling
怎么得到 pContext?
//你的网站我打不开
to :Daniel22_cn
//因为我要用数据库,所以想用文档和视图
to: laiyiling
怎么得到 pContext?
#7
一段代码供参考:
void CMainFrame::SwitchView(VIEWTYPE vwType)
{
CRect rect;
GetClientRect(&rect);
CSize right(rect.Width()*3/4, rect.Height());
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveView()->GetDocument();
Context.m_pCurrentFrame = this;
Context.m_pLastView = (CView*)m_wndSplitter.GetPane(0,1);
Context.m_pNewDocTemplate = Context.m_pCurrentDoc->GetDocTemplate();
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,Context.m_pNewViewClass,right, &Context);
CView* pView =(CView*) m_wndSplitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();
pView->OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}
void CMainFrame::SwitchView(VIEWTYPE vwType)
{
CRect rect;
GetClientRect(&rect);
CSize right(rect.Width()*3/4, rect.Height());
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveView()->GetDocument();
Context.m_pCurrentFrame = this;
Context.m_pLastView = (CView*)m_wndSplitter.GetPane(0,1);
Context.m_pNewDocTemplate = Context.m_pCurrentDoc->GetDocTemplate();
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,Context.m_pNewViewClass,right, &Context);
CView* pView =(CView*) m_wndSplitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();
pView->OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}
#8
www.vckbase.com
#9
我的建议是:直接对CJLib60里的Demo_Outlook进行修改,那里面基本实现了你说的要求。另外,静态分割是可以的,右边的视图是可以切换的,切换过程是创建不同形式的视图对象,调用SwithView()显示新试图,隐藏久的视图。
贴一段例子:
CView * CRightFrame::SwitchView(int vnViewId)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
switch (vnViewId)
{
case VIEW_OUTLOOKDESC:
pNewActiveView = (CView*) m_pDescView;
break;
case VIEW_OUTLOOKLIST:
pNewActiveView = (CView*) m_pListView;
break;
case VIEW_DAYPLAN:
pNewActiveView = (CView *)m_pDayPlanView;
break;
case VIEW_LEFT:
pNewActiveView = (CView*) m_pLeftView;
break;
case VIEW_HTML:
pNewActiveView = (CView*) m_pHtmlView;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return pNewActiveView;
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = vnViewId;
RecalcLayout();
}
return pNewActiveView;
贴一段例子:
CView * CRightFrame::SwitchView(int vnViewId)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
switch (vnViewId)
{
case VIEW_OUTLOOKDESC:
pNewActiveView = (CView*) m_pDescView;
break;
case VIEW_OUTLOOKLIST:
pNewActiveView = (CView*) m_pListView;
break;
case VIEW_DAYPLAN:
pNewActiveView = (CView *)m_pDayPlanView;
break;
case VIEW_LEFT:
pNewActiveView = (CView*) m_pLeftView;
break;
case VIEW_HTML:
pNewActiveView = (CView*) m_pHtmlView;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return pNewActiveView;
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = vnViewId;
RecalcLayout();
}
return pNewActiveView;
#10
谢谢大家热心的解答。
我看你们都用到了m_wndSplitter.DeleteView(0,1);
但是我在使用时总是在这一句出现错误,
弹出(终止,重试,忽略警告框),
如果选择忽略可以实现切换,
但为什么会出现这个框,怎么解决?
我在OnCreateClient中创建视图时语句如下:
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200), pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFrame1),CSize(200,200), pContext);
我看你们都用到了m_wndSplitter.DeleteView(0,1);
但是我在使用时总是在这一句出现错误,
弹出(终止,重试,忽略警告框),
如果选择忽略可以实现切换,
但为什么会出现这个框,怎么解决?
我在OnCreateClient中创建视图时语句如下:
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200), pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFrame1),CSize(200,200), pContext);
#11
DeleteView删除动态分割创建的视图,CreateStatic是创建的静态分割视图
#12
那应怎么解决呢?
#13
mousefj说清楚了啊,DeleteView是删除动态分割的视图的,创建动态分割的视图用CSplitterWnd::Create函数。
用CreateStatic是静态分割,用ShowWindow隐藏、显示子视图
用CreateStatic是静态分割,用ShowWindow隐藏、显示子视图
#14
参考下面两篇文章:
“TN029: Splitter Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn029.asp
“Multiple Document Types, Views, and Frame Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Multiple_Document_Types.2c_.Views.2c_.and_Frame_Windows.asp
“TN029: Splitter Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn029.asp
“Multiple Document Types, Views, and Frame Windows”
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Multiple_Document_Types.2c_.Views.2c_.and_Frame_Windows.asp
#15
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRegLeftView), CSize(100, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRegExplorerView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
m_wndSplitter.SetColumnInfo(0, 200, 100);
return TRUE;
}
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRegLeftView), CSize(100, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRegExplorerView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
m_wndSplitter.SetColumnInfo(0, 200, 100);
return TRUE;
}