问题:
子框架已在文档新建时切分好.现要求在不同的操作下,将原来的子框架重新进行分割,并配上相应的视图.(原来的视图内容可以保存到文档中)
比方说,原来是一行两列的,现在要重新切分成一行三列或二行三列.这个应该如何实现.望各位大侠不吝赐教.谢谢.
子框架已在文档新建时切分好.现要求在不同的操作下,将原来的子框架重新进行分割,并配上相应的视图.(原来的视图内容可以保存到文档中)
比方说,原来是一行两列的,现在要重新切分成一行三列或二行三列.这个应该如何实现.望各位大侠不吝赐教.谢谢.
调试欢乐多
这是分割的类,继承于CSplitterWnd。
// QuestSplitterWnd.cpp: implementation of the CQuestSplitterWnd class.
//
//////////////////////////////////////////////////////////////////////#include "stdafx.h"
#include "questviewer.h"
#include "QuestSplitterWnd.h"#include "QuestViewerView.h"#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////IMPLEMENT_DYNAMIC(CQuestSplitterWnd, CSplitterWnd)BEGIN_MESSAGE_MAP(CQuestSplitterWnd, CSplitterWnd)
ON_WM_NCHITTEST()
END_MESSAGE_MAP()CQuestSplitterWnd::CQuestSplitterWnd()
{
this->m_cxBorder = 2;
this->m_cyBorder = 2;
this->m_cxBorderShare = 0;
this->m_cyBorderShare = 0;
this->m_cxSplitter = 0;
this->m_cySplitter = 0; // There will be ASSERT error if we set these variables to 0 in debug mode.
#ifdef _DEBUG
this->m_cxSplitterGap = 1;
this->m_cySplitterGap = 1;
#else
this->m_cxSplitterGap = 0;
this->m_cySplitterGap = 0;
#endif
}CQuestSplitterWnd::~CQuestSplitterWnd()
{}UINT CQuestSplitterWnd::OnNcHitTest(CPoint point)
{
// return CSplitterWnd::OnNcHitTest(point);
return HTNOWHERE;
}void CQuestSplitterWnd::OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rectArg)
{
// Let CSplitterWnd handle everything but the border-drawing
return;
}CView* CQuestSplitterWnd::SwitchView(int nRow, int nCol, CView* pView)
{
UINT nCurrentID = IdFromRowCol(nRow, nCol);
this->EnableWindow(FALSE); CWaitCursor c; CView* pOldView = (CView*)this->GetPane(nRow, nCol); if (pView == pOldView)
{
this->EnableWindow(TRUE);
c.Restore();
return pOldView;
} if (pOldView != NULL)
{
if (((CQuestViewerView*)pOldView)->NeedUpdate())
{
if (!pOldView->UpdateData(true))
{
this->EnableWindow(TRUE);
c.Restore();
return pOldView;
}
} pOldView->ShowWindow(SW_HIDE);
pOldView->SetDlgCtrlID(0);
} if (!((CQuestViewerView*)pView)->IsCreated())
{
((CView*)pView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, 1, NULL);
((CQuestViewerView*)pView)->SetCreated(); pView->OnInitialUpdate();
}
else
{
pView->UpdateData(false);
} if (pView->GetParent() != this)
{
pView->SetParent(this);
}
pView->SetDlgCtrlID(nCurrentID); this->RecalcLayout();
pView->ShowWindow(SW_SHOW); this->EnableWindow(TRUE); c.Restore(); return pOldView;
}
CQuestSplitterWnd m_wndSplitter1;
CQuestSplitterWnd m_wndSplitter2;
CQuestSplitterWnd m_wndSplitter3;
CQuestSplitterWnd m_wndSplitter4;在OnCreate里创建。
int CQuestSaleModeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CQuestViewerView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams; m_wndSplitter1.CreateStatic(this, 2, 1, WS_CHILD | WS_VISIBLE); m_wndSplitter1.CreateView(1, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext);
m_wndSplitter2.CreateStatic(&m_wndSplitter1, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 0)); m_wndSplitter3.CreateStatic(&m_wndSplitter2, 4, 1, WS_CHILD | WS_VISIBLE, m_wndSplitter2.IdFromRowCol(0, 1)); m_wndSplitter3.CreateView(0, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter3.CreateView(1, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter3.CreateView(2, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter3.CreateView(3, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext);
m_wndSplitter4.CreateStatic(&m_wndSplitter2, 4, 1, WS_CHILD | WS_VISIBLE, m_wndSplitter2.IdFromRowCol(0, 0)); m_wndSplitter4.CreateView(0, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter4.CreateView(1, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter4.CreateView(2, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); m_wndSplitter4.CreateView(3, 0, RUNTIME_CLASS(CQuestViewerView), CSize(1, 1), pContext); double dScaleX = this->GetDocument()->GetScaleX();
double dScaleY = this->GetDocument()->GetScaleY(); this->SetSizeValue(dScaleX, dScaleY); return 0;
}在OnSize里定义大小。
void CQuestSaleModeView::OnSize(UINT nType, int cx, int cy)
{
CQuestViewerView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
this->SetSizeValue(cx / 800.0, cy / 600.0); m_wndSplitter1.SetColumnInfo(0, this->m_nWidth, 0);
m_wndSplitter1.SetRowInfo(0, this->m_nHeight - this->m_nMenuHeight, 0);
m_wndSplitter1.SetRowInfo(1, this->m_nMenuHeight, 0);
m_wndSplitter2.SetRowInfo(0, this->m_nHeight - this->m_nMenuHeight, 0);
m_wndSplitter2.SetColumnInfo(0, this->m_nWidth - this->m_nKeyWidth, 0);
m_wndSplitter2.SetColumnInfo(1, this->m_nKeyWidth, 0); m_wndSplitter3.SetColumnInfo(0, this->m_nKeyWidth, 0);
m_wndSplitter3.SetRowInfo(0, this->m_nClockHeight, 0);
m_wndSplitter3.SetRowInfo(1, this->m_nKeyHeight, 0);
m_wndSplitter3.SetRowInfo(2, 0, 0);
m_wndSplitter3.SetRowInfo(3, 0, 0); m_wndSplitter4.SetColumnInfo(0, this->m_nWidth - this->m_nKeyWidth, 0);
m_wndSplitter4.SetRowInfo(0, this->m_nInfoHeight, 0);
m_wndSplitter4.SetRowInfo(1, this->m_nListHeight, 0);
m_wndSplitter4.SetRowInfo(2, this->m_nCurrentHeight, 0);
m_wndSplitter4.SetRowInfo(3, this->m_nTotalHeight, 0);
CRect rect;
GetWindowRect(&rect);
m_wndSplitter1.MoveWindow(rect);
m_wndSplitter1.RecalcLayout();
m_wndSplitter2.RecalcLayout();
m_wndSplitter3.RecalcLayout();
m_wndSplitter4.RecalcLayout();
}当要变化视图结构的时候,如下
CView* CQuestSaleModeView::SwitchMainView(bool bToMainView, CView* pView)
{
CRect rect;
this->GetClientRect(rect); if (this->m_bIsLeftHand != this->GetDocument()->IsLeftHand())
{
ChangeLayout();
this->m_bIsLeftHand = this->GetDocument()->IsLeftHand();
bToMainView = true;
this->m_bIsMainView = false;
}
CQuestSplitterWnd* pSplitter = &m_wndSplitter4;
if (this->GetDocument()->IsLeftHand())
{
pSplitter = &m_wndSplitter3;
} if (bToMainView)
{
if (!this->m_bIsMainView)
{
// Switch to MainView
this->ResetSaleView();
this->SwitchSaleView(0, this->GetMainFrame()->m_pSaleInfoView);
this->SwitchSaleView(1, this->GetMainFrame()->m_pSaleLineView);
this->SwitchSaleView(2, this->GetMainFrame()->m_pSaleCurrentView);
this->SwitchSaleView(3, this->GetMainFrame()->m_pSaleTotalView);
pSplitter->SetRowInfo(0, this->m_nInfoHeight, 0);
pSplitter->SetRowInfo(1, this->m_nListHeight, 0);
pSplitter->SetRowInfo(2, this->m_nCurrentHeight, 0);
pSplitter->SetRowInfo(3, this->m_nTotalHeight, 0);
pSplitter->RecalcLayout(); this->m_bIsMainView = true;
this->m_bIsNoticeView = false;
}
else if (this->m_bIsNoticeView)
{
this->SwitchSaleView(1, this->GetMainFrame()->m_pSaleLineView);
this->m_bIsNoticeView = false;
} return NULL;
}
else
{
if (this->m_bIsMainView)
{
if (pView != NULL)
{
this->ResetSaleView();
this->SwitchSaleView(0, this->GetMainFrame()->m_pSaleTotalView);
this->SwitchSaleView(1, this->GetMainFrame()->m_pSaleCurrentView);
this->SwitchSaleView(2, pView);
this->SwitchSaleView(3, this->GetMainFrame()->m_pSaleInfoView);
pSplitter->SetRowInfo(0, this->m_nTotalHeight, 0);
pSplitter->SetRowInfo(1, this->m_nCurrentHeight, 0);
pSplitter->SetRowInfo(2, this->m_nProductHeight, 0);
pSplitter->SetRowInfo(3, 0, 0);
pSplitter->RecalcLayout();
this->m_bIsMainView = false;
} return NULL;
}
else
{
return this->SwitchSaleView(2, pView);
}
}
}SwitchSaleView的函数是这个:
CView* CQuestSaleModeView::SwitchSaleView(int nPos, CView *pView)
{
try
{
if (this->GetDocument()->IsLeftHand())
return m_wndSplitter3.SwitchView(nPos, 0, pView);
else
return m_wndSplitter4.SwitchView(nPos, 0, pView);
}
catch (...)
{
return NULL;
}
}而ResetSaleView就是先把以前的View都调换出来,否则出错,因为我是交叉引用,如果你不是交叉引用,那就不用了。
创建N个View。在每个VIew里面都有不同的分割方法,然后到时候进行切换。
如果是真正的动态分割,我没有试过,不知道Destroy后重建行不行。。呵。
还是说创建不同的Frame,再去分割Frame啊。
我给你的代码就是分割CView的。呵呵。