smakadia
May 12th, 1999, 02:18 PM
I have a modeless dialog that gets populated with multiple controls. The total height, from the first control to the last is stored in a CRect object. I want to be able to implement scrolling such that it always stops scrolling at the end of my last control. Below is how I'm trying to implement it but it doesn't work correctly. It won't scroll to the last control when the height is longer than a certain size and it scrolls past the last control when the height is less than a certain size.
If you have any questions, let me know.
I've been at this for days now and any help will be greatly appreciated!
void CPGF::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
static bool BottomLimitReached = false;
static bool UpperLimitReached = false;
int nWndInc = 20; // The length my doc (modeless view) scrolls
int nScrollPos = GetScrollPos( SB_VERT );
int nScrollBoxInc = ( m_rect.bottom ) / (( m_id - 2000 ) * 2 ); // Equation to implement the scroll box movement.
switch( nSBCode )
{
case SB_LINEDOWN:
if(( nScrollPos + nScrollBoxInc ) <= m_rect.bottom )
{
nScrollPos += nScrollBoxInc;
BottomLimitReached = false;
}
else
{
nScrollPos = m_rect.bottom;
BottomLimitReached = true;
}
SetScrollPos(SB_VERT, nScrollPos );
if(!BottomLimitReached)
{
ScrollWindow( 0, (-1) * nWndInc );
}
break;
case SB_LINEUP:
if(( nScrollPos - nScrollBoxInc ) >= 0 )
{
nScrollPos -= nScrollBoxInc;
UpperLimitReached = false;
}
else
{
nScrollPos = 0;
UpperLimitReached = true;
}
SetScrollPos(SB_VERT, nScrollPos );
if(!UpperLimitReached)
{
ScrollWindow( 0, nWndInc );
}
break;
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
If you have any questions, let me know.
I've been at this for days now and any help will be greatly appreciated!
void CPGF::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
static bool BottomLimitReached = false;
static bool UpperLimitReached = false;
int nWndInc = 20; // The length my doc (modeless view) scrolls
int nScrollPos = GetScrollPos( SB_VERT );
int nScrollBoxInc = ( m_rect.bottom ) / (( m_id - 2000 ) * 2 ); // Equation to implement the scroll box movement.
switch( nSBCode )
{
case SB_LINEDOWN:
if(( nScrollPos + nScrollBoxInc ) <= m_rect.bottom )
{
nScrollPos += nScrollBoxInc;
BottomLimitReached = false;
}
else
{
nScrollPos = m_rect.bottom;
BottomLimitReached = true;
}
SetScrollPos(SB_VERT, nScrollPos );
if(!BottomLimitReached)
{
ScrollWindow( 0, (-1) * nWndInc );
}
break;
case SB_LINEUP:
if(( nScrollPos - nScrollBoxInc ) >= 0 )
{
nScrollPos -= nScrollBoxInc;
UpperLimitReached = false;
}
else
{
nScrollPos = 0;
UpperLimitReached = true;
}
SetScrollPos(SB_VERT, nScrollPos );
if(!UpperLimitReached)
{
ScrollWindow( 0, nWndInc );
}
break;
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}