Splitter Window
-
I am creating a 2x2 spllitter window in a SDI application. // OnCreateClient of SDI Frame Window ... VERIFY(m_wndSplitter.CreateStatic(this, m_rows, m_cols)); ... I want every pane to be of the same size (plus-minus 1 pixel). In OnSize I do something like: // OnSize of Frame Window ... m_wndSplitter.GetClientRect(rect); int row_height = rect.Height(); int col_width = rect.Width(); row_height /= 2; col_width /= 2; m_wndSplitter.SetRowInfo(0, row_height, 100); m_wndSplitter.SetRowInfo(1, row_height, 100); m_wndSplitter.SetColumnInfo(0, col_width, 100); m_wndSplitter.SetColumnInfo(1, col_width, 100); m_wndSplitter.RecalcLayout(); ... HOWEVER probably due to the "splitting margin" or border between panes, the pane(0, 0) is larger than the other panes with a difference of about 11 pixels in size. Other than "manually" accounting for the border thickness, is there a better way of making the panes same size. Thanks in anticipation.
-
I am creating a 2x2 spllitter window in a SDI application. // OnCreateClient of SDI Frame Window ... VERIFY(m_wndSplitter.CreateStatic(this, m_rows, m_cols)); ... I want every pane to be of the same size (plus-minus 1 pixel). In OnSize I do something like: // OnSize of Frame Window ... m_wndSplitter.GetClientRect(rect); int row_height = rect.Height(); int col_width = rect.Width(); row_height /= 2; col_width /= 2; m_wndSplitter.SetRowInfo(0, row_height, 100); m_wndSplitter.SetRowInfo(1, row_height, 100); m_wndSplitter.SetColumnInfo(0, col_width, 100); m_wndSplitter.SetColumnInfo(1, col_width, 100); m_wndSplitter.RecalcLayout(); ... HOWEVER probably due to the "splitting margin" or border between panes, the pane(0, 0) is larger than the other panes with a difference of about 11 pixels in size. Other than "manually" accounting for the border thickness, is there a better way of making the panes same size. Thanks in anticipation.
There is no way for a frame to get its splitters internal dimensions. But you could write a new class inheriting from CSplitterWnd, and use that instead... Be warned, this not debugged (or even compiled code), so check it out yourself. If omitted *loads* of error checks.
class CSymetricalSplitter : public CSplitterWnd
{
public:
BOOL ArrangeSymmetrically (int nMinX, int nMinY)
{
CRect rcClient;
GetClientRect (&rcClient);
int nCols, nRows, nSize, n;
nCols = GetColumnCount ();
nRows = GetRowCount ();
if (!nRows || !nCount)
return FALSE;// Rows nSize = rcClient.Height (); nSize -= (nRows - 1) \* m\_cySplitterGap; // <-- A protected variable nSize /= nRows; for (n = 0; n < nRows; n++) SetRowInfo (n, nSize, nMinY); // Columns .... RecalcLayout (); }
};
Hopefully that should help! Iain.
-
There is no way for a frame to get its splitters internal dimensions. But you could write a new class inheriting from CSplitterWnd, and use that instead... Be warned, this not debugged (or even compiled code), so check it out yourself. If omitted *loads* of error checks.
class CSymetricalSplitter : public CSplitterWnd
{
public:
BOOL ArrangeSymmetrically (int nMinX, int nMinY)
{
CRect rcClient;
GetClientRect (&rcClient);
int nCols, nRows, nSize, n;
nCols = GetColumnCount ();
nRows = GetRowCount ();
if (!nRows || !nCount)
return FALSE;// Rows nSize = rcClient.Height (); nSize -= (nRows - 1) \* m\_cySplitterGap; // <-- A protected variable nSize /= nRows; for (n = 0; n < nRows; n++) SetRowInfo (n, nSize, nMinY); // Columns .... RecalcLayout (); }
};
Hopefully that should help! Iain.
Thanks. This is probably the only way out. Here is a fragment from Q & A: C++ (Periodicals 1998) from MSDN Library 1999 that does something similar: After calculating the heights of the toolbars, the next troublesome task is calculating the height and width of all the splitter window components: the border with which it surrounds each pane and the splitter bar itself. All these magic numbers are contained within data members in CSplitterWnd, but naturally the data is protected, which means you can’t access it! Sigh. So what do you do? Simple: just derive a new class with public functions to export the protected data, and use it instead of CSplitterWnd in your main frame. class CMySplitterWnd : public CSplitterWnd { public: CSize GetBorderSize() { return CSize(m_cxBorder,m_cyBorder); } CSize GetSplitterSize() { return CSize(m_cxSplitter,m_cySplitter); } };
-
Thanks. This is probably the only way out. Here is a fragment from Q & A: C++ (Periodicals 1998) from MSDN Library 1999 that does something similar: After calculating the heights of the toolbars, the next troublesome task is calculating the height and width of all the splitter window components: the border with which it surrounds each pane and the splitter bar itself. All these magic numbers are contained within data members in CSplitterWnd, but naturally the data is protected, which means you can’t access it! Sigh. So what do you do? Simple: just derive a new class with public functions to export the protected data, and use it instead of CSplitterWnd in your main frame. class CMySplitterWnd : public CSplitterWnd { public: CSize GetBorderSize() { return CSize(m_cxBorder,m_cyBorder); } CSize GetSplitterSize() { return CSize(m_cxSplitter,m_cySplitter); } };
(To be complete) this is what can be done: CRect rect; m_wndSplitter.GetClientRect(rect); CSize splitter_size = m_wndSplitter.GetSplitterSize(); CSize border_size = m_wndSplitter.GetBorderSize(); int row_height = rect.Height() - ((splitter_size.cy * (m_rows - 1)) + (border_size.cy * 2)); int col_width = rect.Width() - ((splitter_size.cx * (m_cols - 1)) + (border_size.cx * 2)); row_height /= m_rows; col_width /= m_cols; for (int i = 0; i < m_rows; i++) { m_wndSplitter.SetRowInfo(i, row_height, 100); } for (int j = 0; j < m_cols; j++) { m_wndSplitter.SetColumnInfo(j, col_width, 100); } m_wndSplitter.RecalcLayout(); Regards Mahendra