pates
June 14th, 2005, 06:34 PM
I have a dialog with a fixed height, variable width. It is made up of vertical panes and we do not want to show a partial pane - so when it's being horizontally resized we want to snap the side of the dialog to the edge of the nearest pane.
Resizing from the right works perfectly. But when it's resized from the left, the left side will temporarily snap to the correct position, then the entire dialog will shift so its left side is back at the original position. Below is the code for narrowing the dialog. Why would resizing from the left work any differently than resizing from the right?
One more curious point is that if I break in the "left" code (e.g. at the second m_bResizeOk), then re-activate the app, the dialog is placed correctly.
void MyDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
static int iRight = 0;
static int iLeft = 0;
static int iExpandCount = 0;
static POINT pt;
// when we move within triggerWidth we "jump" to the next panel
const int triggerWidth = 20;
m_wResizeSide = ((fwSide == WMSZ_RIGHT) || (fwSide == WMSZ_LEFT)) ? fwSide : -1;
char cMsg[128];
::GetCursorPos(&pt);
if (!m_bSizing && (m_wResizeSide != -1))
{
//set initial starting point...
if (m_wResizeSide == WMSZ_RIGHT)
iRight = pt.x;
else
iLeft = pt.x;
iExpandCount = 0;
}
if (m_wResizeSide == WMSZ_RIGHT)
{
if (pt.x < (iRight - (m_pPanel->m_iWidth - triggerWidth)))
{
if (m_iVisible > 1)
{
iExpandCount--;
iRight -= m_pPanel->m_iWidth;
m_rectWnd = *pRect;
m_rectWnd.right -= m_pPanel->m_iWidth * -iExpandCount;
pRect->right -= (m_pPanel->m_iWidth+2);
m_bResizeOk = true;
}
}
}
else if (m_wResizeSide == WMSZ_LEFT)
{
if ( pt.x > iLeft + m_pPanel->m_iWidth - triggerWidth )
{
if (m_iVisible > 1)
{
iExpandCount--;
iLeft += m_pPanel->m_iWidth;
m_rectWnd = *pRect;
m_rectWnd.left += m_pPanel->m_iWidth * -iExpandCount;
pRect->left += m_pPanel->m_iWidth - 2;
m_bResizeOk = true;
}
}
}
m_bSizing = true;
return;
}
Resizing from the right works perfectly. But when it's resized from the left, the left side will temporarily snap to the correct position, then the entire dialog will shift so its left side is back at the original position. Below is the code for narrowing the dialog. Why would resizing from the left work any differently than resizing from the right?
One more curious point is that if I break in the "left" code (e.g. at the second m_bResizeOk), then re-activate the app, the dialog is placed correctly.
void MyDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
static int iRight = 0;
static int iLeft = 0;
static int iExpandCount = 0;
static POINT pt;
// when we move within triggerWidth we "jump" to the next panel
const int triggerWidth = 20;
m_wResizeSide = ((fwSide == WMSZ_RIGHT) || (fwSide == WMSZ_LEFT)) ? fwSide : -1;
char cMsg[128];
::GetCursorPos(&pt);
if (!m_bSizing && (m_wResizeSide != -1))
{
//set initial starting point...
if (m_wResizeSide == WMSZ_RIGHT)
iRight = pt.x;
else
iLeft = pt.x;
iExpandCount = 0;
}
if (m_wResizeSide == WMSZ_RIGHT)
{
if (pt.x < (iRight - (m_pPanel->m_iWidth - triggerWidth)))
{
if (m_iVisible > 1)
{
iExpandCount--;
iRight -= m_pPanel->m_iWidth;
m_rectWnd = *pRect;
m_rectWnd.right -= m_pPanel->m_iWidth * -iExpandCount;
pRect->right -= (m_pPanel->m_iWidth+2);
m_bResizeOk = true;
}
}
}
else if (m_wResizeSide == WMSZ_LEFT)
{
if ( pt.x > iLeft + m_pPanel->m_iWidth - triggerWidth )
{
if (m_iVisible > 1)
{
iExpandCount--;
iLeft += m_pPanel->m_iWidth;
m_rectWnd = *pRect;
m_rectWnd.left += m_pPanel->m_iWidth * -iExpandCount;
pRect->left += m_pPanel->m_iWidth - 2;
m_bResizeOk = true;
}
}
}
m_bSizing = true;
return;
}