-
April 10th, 2013, 11:00 AM
#1
Could use some help with this interface
I have been working with a MDI 3-way child splitter that works pretty well - but I cannot figure out how to precisely control the split windows.
The basic idea is to split each child window as shown below.
IOW, I want A and B to be split equally, and I want to be able to toggle (show/hide) C.
My problem is that in order to get the initial split that I want with each new child, I have used CChildFrm::OnSize to set up the split sizes such that every resize or new child or update reproduces the original split, making it impossible for the user to hide C as it keeps reappearing. While admittedly this is largely an aesthetic issue, it has bothered me for months, so I thought I would ask you all for help.
A sample demonstrating the problem is attached.
Thanks for any help you might provide.
Last edited by Mike Pliam; April 10th, 2013 at 11:29 AM.
mpliam
-
April 10th, 2013, 12:45 PM
#2
Re: Could use some help with this interface
You are losing state in the OnSize function because you don't handle the view 3 window state there.
You can clean this up a bit, but here it is quick and dirty:
Code:
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWndEx::OnSize(nType, cx, cy);
CRect cr;
GetWindowRect(&cr);
if (m_bInitSplitter && nType != SIZE_MINIMIZED)
{
//m_wndSplitter.SetRowInfo( 0, cy, 0 );
m_wndSplitter.SetRowInfo( 0, 0.75*cy, 0 ); // adjust row 1 height here
//m_wndSplitter.SetColumnInfo(0, cr.Width()*0.25 / 2, 50);
//m_wndSplitter.SetColumnInfo(1, cr.Width()*0.75 / 2, 50);
m_wndSplitter2.SetColumnInfo(0, cr.Width() / 2, 50);
m_wndSplitter2.SetColumnInfo(1, cr.Width()/ 2, 50);
m_wndSplitter.SetColumnInfo(0, cr.Width(), 50);
m_wndSplitter.SetRowInfo(1, cr.Height()/4, 30);
m_wndSplitter.RecalcLayout();
}
DisplayViewThreeWindow();
}
void CChildFrame::DisplayViewThreeWindow()
{
// get the debug view text
CString csViewThreeText;
//CChildFrame * pChildFrm = (CChildFrame*)GetActiveFrame();
//CSplitterWnd * pWndSplitter = pChildFrm->GetWndSplitter();
//pWndSplitter->GetPane(1, 0)->GetWindowText(csDebugText);
TRACE0("csViewThreeText = "); OutputDebugString(csViewThreeText); TRACE0("\n");
// MessageBox(csDebugText);
//CSplitterWnd * pWndSplitter2 = pChildFrm->GetWndSplitter2();
int cx, cy;
CRect r;
GetClientRect(&r);
if(!m_bViewThree)
{
//pWndSplitter->EnableWindow();
//pWndSplitter->SetRowInfo(0, r.Height(), r.Height());
//pWndSplitter->SetColumnInfo(0,r.Width()/2,0);
//pWndSplitter->SetColumnInfo(0,r.Width()/2,0);
m_wndSplitter.EnableWindow();
m_wndSplitter.SetRowInfo(0, r.Height(), r.Height());
m_wndSplitter.SetColumnInfo(0,r.Width()/2,0);
m_wndSplitter.SetColumnInfo(0,r.Width()/2,0);
}
if(m_bViewThree)
{
m_wndSplitter.EnableWindow();
cx = r.Width();
cy = 0.70 * r.Height();
m_wndSplitter.EnableWindow();
m_wndSplitter.SetRowInfo(0,cy,30);
m_wndSplitter.SetColumnInfo(0,cx,30);
}
m_wndSplitter.RecalcLayout();
}
void CChildFrame::OnViewThreeWindow()
{
m_bViewThree = !m_bViewThree;
DisplayViewThreeWindow();
}
-
April 11th, 2013, 01:27 PM
#3
Re: Could use some help with this interface
Thanks alot Arjay,
This works after making some minor changes. It is somewhat confusing which panes belong to which CSplitterWnd because there is only 1 column with 2 rows and the upper right hand pane is nested within column 1 which is misleadingly associated with m_wndSplitter2 while row 2 is associated with m_wndSplitter.
CSplitterWnd m_wndSplitter; // the bottom pane (1, 0)
CSplitterWnd m_wndSplitter2; // the top left hand pane (0, 0) and the top right hand pane (0, 1)
Code:
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWndEx::OnSize(nType, cx, cy);
CRect cr;
GetWindowRect(&cr);
if (m_bInitSplitter && nType != SIZE_MINIMIZED)
{
m_wndSplitter.SetRowInfo( 0, 0.75*cy, 0 ); // adjust row 1 height here
m_wndSplitter2.SetColumnInfo(0, cr.Width() / 2, 50);
m_wndSplitter2.SetColumnInfo(1, cr.Width()/ 2, 50);
m_wndSplitter.SetColumnInfo(0, cr.Width(), 50);
m_wndSplitter.SetRowInfo(1, cr.Height()/4, 30);
m_wndSplitter.RecalcLayout();
DisplayViewThreeWindow();
}
//DisplayViewThreeWindow(); // crashes if here
}
void CChildFrame::DisplayViewThreeWindow()
{
// get the debug view text
CString csViewThreeText;
TRACE0("csViewThreeText = "); OutputDebugString(csViewThreeText); TRACE0("\n");
int cx, cy;
CRect r;
GetClientRect(&r);
if(!m_bViewThree)
{
m_wndSplitter2.EnableWindow();
m_wndSplitter2.SetRowInfo(0, r.Height(), r.Height());
m_wndSplitter2.SetColumnInfo(0,r.Width()/2,0);
m_wndSplitter2.SetColumnInfo(1,r.Width()/2,0);
cx = r.Width();
cy = r.Height();
m_wndSplitter.EnableWindow();
m_wndSplitter.SetRowInfo(0,cy,30);
m_wndSplitter.SetColumnInfo(0,cx,30);
}
if(m_bViewThree)
{
m_wndSplitter.EnableWindow();
cx = r.Width();
cy = 0.70 * r.Height();
m_wndSplitter.EnableWindow();
m_wndSplitter.SetRowInfo(0,cy,30);
m_wndSplitter.SetColumnInfo(0,cx,30);
}
m_wndSplitter.RecalcLayout();
}
Last edited by Mike Pliam; April 11th, 2013 at 01:36 PM.
mpliam
-
April 11th, 2013, 02:58 PM
#4
Re: Could use some help with this interface
Great. The problem was simply that the OnSize() method didn't take the bVieewThree state into account.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|