CSplitterWnd对象ShowWindow的问题.

calabash_b 2005-12-01 10:34:45
我在CMainFrame有两个CSplitterWnd对象,
CSplitterWnd *m_wndSplitter2,*m_wndSplitter3;

然后在CMainFrame::OnCreateClient中
m_wndSplitter2=new CSplitterWnd();
this->m_wndSplitter2->CreateStatic(this,2,1);
this->m_wndSplitter2->CreateView(0,0,RUNTIME_CLASS(View1),CSize(0,300),pContext);
this->m_wndSplitter2->CreateView(1,0,RUNTIME_CLASS(View2),CSize(0,0),pContext);

m_wndSplitter3=new CSplitterWnd();
this->m_wndSplitter3->CreateStatic(this,2,1);
this->m_wndSplitter3->CreateView(0,0,RUNTIME_CLASS(View3),CSize(0,300),pContext);
this->m_wndSplitter3->CreateView(1,0,RUNTIME_CLASS(View2),CSize(0,0),pContext);

m_wndSplitter3->ShowWindow(SW_SHOW);
m_wndSplitter2->ShowWindow(SW_HIDE);


然后在CMainFrame别的地方,
m_wndSplitter2->ShowWindow(SW_SHOW);
m_wndSplitter3->ShowWindow(SW_HIDE);
就是把m_wndSplitter2,m_wndSplitter3的显示状态交换一下,结果这样调用后窗口中间是透明的,什么都没有,请问如何解决?谢谢.是不是要重画CMainFrame之类的?
...全文
170 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
laofang 2005-12-01
  • 打赏
  • 举报
回复
按你的情况,只需用一个splitter,划分两行,第一行放一个FrameWnd管理View1和View3进行动态切换,每二行放View2,参考一段goodboyws的代码(根据你的情况稍改一下即可):
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{

CRect rect;
GetClientRect(&rect);
//第一层
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
return FALSE;
}
if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),
CSize(60, rect.Height()), pContext))
{
return FALSE;
}

if (!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CSubFrame), CSize(rect.Width()-PANEL_WIDTH, 150), pContext))
{
return FALSE;
}

m_pLeftView= (CLeftView* )m_wndSplitter.GetPane(0,0);
m_pSubFrame = (CSubFrame* )m_wndSplitter.GetPane(0,1);
return TRUE;

}
......
subFrame.h
class CSubFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CSubFrame)
protected:
CSubFrame(); // protected constructor used by dynamic creation

// Attributes
public:

CMyFormView1 *m_pView1;
CMyFormView2 *m_pView2;
UINT m_nCurrentViewID; //手工标记的活动视图
void SwitchToView(UINT nView);

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSubFrame)
protected:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
//}}AFX_VIRTUAL

// Implementation
protected:
virtual ~CSubFrame();

// Generated message map functions
//{{AFX_MSG(CSubFrame)

//}}AFX_MSG
public:

DECLARE_MESSAGE_MAP()
};
sbuframe.cpp
......

MPLEMENT_DYNCREATE(CSubFrame, CFrameWnd)

CSubFrame::CSubFrame()
{

}

CSubFrame::~CSubFrame()
{
}


BEGIN_MESSAGE_MAP(CSubFrame, CFrameWnd)
//{{AFX_MSG_MAP(CSubFrame)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSubFrame message handlers

BOOL CSubFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{

m_pView1 = new CMyFormView1;
((CView*)m_pView1)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, 1, pContext);
SetActiveView(m_pView1);
m_pView1->ShowWindow(SW_SHOW);
m_pView1->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_nCurrentViewID = 1;

m_pView2 = new CMyFormView2;
((CView*) m_pView2)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, 2, pContext);
m_pView2->ShowWindow(SW_HIDE);


RecalcLayout();

return TRUE;
}

void CSubFrame::SwitchToView(UINT nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
CMainFrame* pFrame = (CMainFrame* )AfxGetMainWnd();
switch (nView)
{
case 1:
pNewActiveView = (CView*)m_pView1;
break;
case 2:
pNewActiveView = (CView*)mm_pView2;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView != pNewActiveView)
{
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
if (pOldActiveView)
{
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
}
m_nCurrentViewID = nView;
}
RecalcLayout();
}
}
calabash_b 2005-12-01
  • 打赏
  • 举报
回复
那要实现这样的功能应该怎么做呢?给点思路.
若是m_wndSplitter2不存在那么,m_wndSplitter2是先于m_wndSplitter3创建的,而我刚开始是让m_wndSplitter2隐藏,m_wndSplitter3显示,这样做没问题.怎么解释呢?
我也想过,在切换CSplitterWnd时这样
delete m_wndSplitter2;//先删除原来那个
m_wndSplitter3=new CSplitterWnd();//再创建新的
this->m_wndSplitter3->CreateStatic(this,2,1);
this->m_wndSplitter3->CreateView(0,0,RUNTIME_CLASS(View1),CSize(0,300),&context);
this->m_wndSplitter3->CreateView(1,0,RUNTIME_CLASS(View2),CSize(0,0),&context);


但却出断言的错误,不解,难道是context有问题?
菜牛 2005-12-01
  • 打赏
  • 举报
回复
同时只能有一个CSplitterWnd作为框架的子窗口。所以m_wndSplitter2其实不存在。
laofang 2005-12-01
  • 打赏
  • 举报
回复
那你可以先分成多行多列(考虑可能的情况),隐藏一些不需要的窗口,需要显示时关闭另外一些窗口,显示你要显示的,再RecalcLayout显示出来。视图一般动态创建
calabash_b 2005-12-01
  • 打赏
  • 举报
回复
谢谢楼上的,你给的代码让我有了一些思路.其实我是想实现CSplitterWnd的互换,就是第一次是分成两行,第二次是分成两列,或者是分成别的样式,而不是简单的视图交换.不知道你有什么好的思路呢?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧