参考书上的例子做了一下,窗口分割开了,可是分割的大小却总变,本来我是打算把窗口分成5:1的两个,运行以后开始没有小窗口,最大化以后出来两个差不多大的,这是我的代码,能帮忙看看有什么问题吗?谢谢 (CSplitterWnd m_wndSplitter;)
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
CRect rcClient(0, 0, 0, 0);
GetClientRect(rcClient);
if(m_wndSplitter.CreateStatic(this,2,1)==NULL)
return FALSE;
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyWorkView),CSize(rcClient.Width(), rcClient.Height()*5/6),pContext);
m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(COperateView),CSize(rcClient.Width(), rcClient.Height()/6),pContext);
return TRUE;
}
能说的详细点吗?OnSize是自己加上去的吧?主要处理什么呢?
运行以后开始没有小窗口//不会的,会有窗口的。
确实没有小窗口,最大化以后才出线两个窗口
添加了OnSize,效果和原来的一样
CSize Up;
CSize Down;
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
CRect rcClient(0, 0, 0, 0);
GetClientRect(rcClient);
Up.cx=rcClient.Width();
Up.cy=rcClient.Height()*5/6;
Down.cx=rcClient.Width();
Down.cy=rcClient.Height()*5/6;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
if(m_wndSplitter.CreateStatic(this,2,1)==NULL)
return FALSE;
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyWorkView),Up,pContext);
m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(COperateView),Down,pContext);
return TRUE;
}
你的意思是在OnSize函数里添加分割窗口的代码?每次改变边框大小产生WM_SIZE消息,相应OnSize函数,重新分割窗口?
我试了试,编译没问题,但是运行不了
我是这样理解的:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CRect rcClient(0, 0, 0, 0);
GetClientRect(rcClient);
Up.cx=rcClient.Width();
Up.cy=rcClient.Height()*5/6;
Down.cx=rcClient.Width();
Down.cy=rcClient.Height()*1/6;
CCreateContext context;
CDocument *pDoc = GetActiveView()->GetDocument();
context.m_pCurrentDoc=pDoc;
if(m_wndSplitter.CreateStatic(this,2,1)==NULL)
return;
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyWorkView),Up,&context);
m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(COperateView),Down,&context);
}
[此贴子已经被作者于2006-10-9 12:56:34编辑过]