Re: Why does CSplitterWnd::GetRowInfo() return -1 for a window size?
On Mon, 15 Oct 2007 06:42:52 -0700, Rob Richardson <CedricCicada@gmail.com>
wrote:
Greetings!
I am trying to create a derivative of CSplitterWnd that will keep the
ratio of its two panes constant when the window size changes. I
create my splitter window with its two panes, one on top of the other,
and then I call my derived class's RememberRatio() method, which is:
void CHTSplitter::RememberRatio()
{
int current0, current1, min0, min1;
int rowCount, columnCount;
this->GetRowInfo(0, current0, min0);
this->GetRowInfo(1, current1, min1);
m_ratio = (double)current0 / (double)(current0 + current1);
}
You may get off-by-one errors when you later use m_ratio to compute row
heights, so be careful that your procedure is invertible if need be. That
is, if you've ever used a program that changes the pane size when you click
a splitter, even though you haven't moved the mouse, you could end up with
a similar defect if you were to save the ratio and later use it to
recompute heights.
I was surprised that the ratio was 0.5 when it should have been 0.75,
since the top pane is created to be three times the size of the bottom
one. Stepping into this, I saw that GetRowInfo() was returning -1 for
both panes. Stepping into the GetRowInfo() method, I saw that the
m_pRowInfo structure for my rows contained -1 for current size, the
actual size for ideal size, and 0 for minimum size.
So, this leads to a series of questions:
1. Why is the current size -1 instead of the current size?
2. What do I have to do to ensure that current size gives me the
current size?
3. If the current size is actually stored in the ideal size, how am I
supposed to read the ideal size? I don't see a method for it.
4. Is it safe to assume that if the current size returns -1 then the
ideal size value will contain the window's actual size?
Thank you very much.
When are you calling this function? The CSplitterWnd::CreateCommon function
contains the following:
m_pRowInfo[row].nMinSize = m_pRowInfo[row].nIdealSize = sizeMin.cy;
m_pRowInfo[row].nCurSize = -1; // will be set in RecalcLayout
It does not go on to call RecalcLayout, but that function is called in many
other places, such as the OnSize handler. Thus, I'd guess you're calling it
sometime in between.
RobR, who will add a version of GetRowInfo() based on an answer of
"Yes" to question 4 to his derived class while waiting for an answer
to this
As GetRowInfo isn't virtual, I would give the function in the derived class
a different name, but I don't think the answer to (4) is "yes" anyway.
--
Doug Harrison
Visual C++ MVP