How to hide scrollbars when client area is large enough? 
Author Message
 How to hide scrollbars when client area is large enough?

        Hi everyone,
                              In a Win98 dialog app., using VC5.0, I have
scroll-bars on a dialog which I show only when the client area is too small
to see all of the controls etc. If the window is then enlarged or maximised
but the thumb is not at the top, I keep the scroll-bars visible until the
thumb is moved back to the top, then automatically hide them. This works
great with the 'SB_THUMBTRACK' code, but if press the top scrollbar button,
('SB_LINEUP'), after the window has finished scrolling the scrollbar
disappears as it should, but the line-up scrollbar button, (which was still
pressed when 'CWnd::ShowScrollBar(SB_VERT, FALSE)' was called), reappears
the instant the mouse-button is released. I was originally calling
'ShowScrollBar()' from inside the 'CWnd::OnVScroll()' handler, but I thought
this could be causing the problem and moved the call to the 'OnPaint()'
handler. No change.
        I hope I've described the problem well enough. Any suggestions on
how to overcome it will be most welcome.
Thanks in advance,
 Steve C.

I've pasted my 'Do_ShowScrollBars()' and 'OnVScroll()' functions below:-
('Do_ShowScrollBars()' is now called from 'OnPaint()'.)
////////////////////////
void CDeviceTemplateDlg::Do_ShowScrollBars()
{
    CRect rectMainClient, rectDeviceWindow;
    GetClientRect(rectMainClient);
    m_pLampController[0]->GetWindowRect(&rectDeviceWindow);

    if( rectMainClient.Width() < (2 * rectDeviceWindow.Width()) )
        ShowScrollBar(SB_HORZ, TRUE);
    else
        ShowScrollBar(SB_HORZ, FALSE);

    if( rectMainClient.Height() < (2 * rectDeviceWindow.Height()) )
        ShowScrollBar(SB_VERT, TRUE);
    else if(m_iVScrollPos == 0)
        ShowScrollBar(SB_VERT, FALSE);

Quote:
}

void CDeviceTemplateDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{
    int iAdjust, iPos = (int)nPos;
    CRect rectMainClient, rectDeviceWindow;

    if(pScrollBar == NULL)
    {
        switch(nSBCode)
        {
        case SB_THUMBTRACK:
            iAdjust = m_iVScrollPos - iPos;
            if(iAdjust != 0)
            {
                ScrollWindow(0, iAdjust, NULL, NULL);
                SetScrollPos(SB_VERT, iPos, TRUE);
                m_iVScrollPos = iPos;
            }
//          Do_ShowScrollBars();    // Moved to 'OnPaint()'.
            break;

        case SB_LINEUP:
            if(m_iVScrollPos > 0)
            {
                if(m_iVScrollPos > 9)
                    iAdjust = 10;
                else
                    iAdjust = m_iVScrollPos;
                ScrollWindow(0, iAdjust, NULL, NULL);
                m_iVScrollPos -= iAdjust;
                SetScrollPos(SB_VERT, m_iVScrollPos, TRUE);
//              Do_ShowScrollBars();    // Moved to 'OnPaint()'.
            }
            break;

        default:
            ;
        }
    }
    CDialog::OnVScroll(nSBCode, nPos, pScrollBar);

Quote:
}

////////////////////////


Sat, 05 Jun 2004 20:04:55 GMT  
 How to hide scrollbars when client area is large enough?
        With persistence and a little bit of good, old-fashioned
trial-and-error, I found the answer to this one myself. (And the solution is
much simpler than the problem.)
        For anyone interested, I moved the 'Do_ShowScrollBars()' calls back
into the 'OnVScroll()' handler, then I handled the scrollbar's
'SB_ENDSCROLL' code by calling 'CWnd::Invalidate()'. It causes a single
flicker when the mouse-button is released after scrolling, but that's not a
problem.

... Steve C.


Quote:
>         Hi everyone,
>                               In a Win98 dialog app., using VC5.0, I have
> scroll-bars on a dialog which I show only when the client area is too
> small to see all of the controls etc. If the window is then enlarged or
> maximised but the thumb is not at the top, I keep the scroll-bars
> visible until the thumb is moved back to the top, then automatically
> hide them. This works great with the 'SB_THUMBTRACK' code,
> but if press the top scrollbar button, ('SB_LINEUP'), after the
> window has finished scrolling the scrollbar disappears as it should,
> but the line-up scrollbar button, (which was still pressed when
> 'CWnd::ShowScrollBar(SB_VERT, FALSE)' was called), reappears
> the instant the mouse-button is released. I was originally calling
> 'ShowScrollBar()' from inside the 'CWnd::OnVScroll()' handler, but
>I thought this could be causing the problem and moved the call to the
> 'OnPaint()' handler. No change.
>         I hope I've described the problem well enough. Any suggestions
> on how to overcome it will be most welcome.
> Thanks in advance,
>  Steve C.

> I've pasted my 'Do_ShowScrollBars()' and 'OnVScroll()' functions below:-
> ('Do_ShowScrollBars()' is now called from 'OnPaint()'.)
> ////////////////////////
> void CDeviceTemplateDlg::Do_ShowScrollBars()
> {
>     CRect rectMainClient, rectDeviceWindow;
>     GetClientRect(rectMainClient);
>     m_pLampController[0]->GetWindowRect(&rectDeviceWindow);

>     if( rectMainClient.Width() < (2 * rectDeviceWindow.Width()) )
>         ShowScrollBar(SB_HORZ, TRUE);
>     else
>         ShowScrollBar(SB_HORZ, FALSE);

>     if( rectMainClient.Height() < (2 * rectDeviceWindow.Height()) )
>         ShowScrollBar(SB_VERT, TRUE);
>     else if(m_iVScrollPos == 0)
>         ShowScrollBar(SB_VERT, FALSE);
> }

> void CDeviceTemplateDlg::OnVScroll(
> UINT nSBCode,
> UINT nPos,
> CScrollBar* pScrollBar)
> {
>     int iAdjust, iPos = (int)nPos;
>     CRect rectMainClient, rectDeviceWindow;

>     if(pScrollBar == NULL)
>     {
>         switch(nSBCode)
>         {
>         case SB_THUMBTRACK:
>             iAdjust = m_iVScrollPos - iPos;
>             if(iAdjust != 0)
>             {
>                 ScrollWindow(0, iAdjust, NULL, NULL);
>                 SetScrollPos(SB_VERT, iPos, TRUE);
>                 m_iVScrollPos = iPos;
>             }
> //          Do_ShowScrollBars();    // Moved to 'OnPaint()'.
>             break;

>         case SB_LINEUP:
>             if(m_iVScrollPos > 0)
>             {
>                 if(m_iVScrollPos > 9)
>                     iAdjust = 10;
>                 else
>                     iAdjust = m_iVScrollPos;
>                 ScrollWindow(0, iAdjust, NULL, NULL);
>                 m_iVScrollPos -= iAdjust;
>                 SetScrollPos(SB_VERT, m_iVScrollPos, TRUE);
> //              Do_ShowScrollBars();    // Moved to 'OnPaint()'.
>             }
>             break;

>         default:
>             ;
>         }
>     }
>     CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
> }
> ////////////////////////



Sat, 05 Jun 2004 23:19:04 GMT  
 How to hide scrollbars when client area is large enough?
After you hide the scrollbar, if you invalidate the area where the scrollbar was (but not
the rest of the client area), it may eliminate the perceived flicker.
                        joe

Quote:

>        With persistence and a little bit of good, old-fashioned
>trial-and-error, I found the answer to this one myself. (And the solution is
>much simpler than the problem.)
>        For anyone interested, I moved the 'Do_ShowScrollBars()' calls back
>into the 'OnVScroll()' handler, then I handled the scrollbar's
>'SB_ENDSCROLL' code by calling 'CWnd::Invalidate()'. It causes a single
>flicker when the mouse-button is released after scrolling, but that's not a
>problem.

>... Steve C.



>>         Hi everyone,
>>                               In a Win98 dialog app., using VC5.0, I have
>> scroll-bars on a dialog which I show only when the client area is too
>> small to see all of the controls etc. If the window is then enlarged or
>> maximised but the thumb is not at the top, I keep the scroll-bars
>> visible until the thumb is moved back to the top, then automatically
>> hide them. This works great with the 'SB_THUMBTRACK' code,
>> but if press the top scrollbar button, ('SB_LINEUP'), after the
>> window has finished scrolling the scrollbar disappears as it should,
>> but the line-up scrollbar button, (which was still pressed when
>> 'CWnd::ShowScrollBar(SB_VERT, FALSE)' was called), reappears
>> the instant the mouse-button is released. I was originally calling
>> 'ShowScrollBar()' from inside the 'CWnd::OnVScroll()' handler, but
>>I thought this could be causing the problem and moved the call to the
>> 'OnPaint()' handler. No change.
>>         I hope I've described the problem well enough. Any suggestions
>> on how to overcome it will be most welcome.
>> Thanks in advance,
>>  Steve C.

>> I've pasted my 'Do_ShowScrollBars()' and 'OnVScroll()' functions below:-
>> ('Do_ShowScrollBars()' is now called from 'OnPaint()'.)
>> ////////////////////////
>> void CDeviceTemplateDlg::Do_ShowScrollBars()
>> {
>>     CRect rectMainClient, rectDeviceWindow;
>>     GetClientRect(rectMainClient);
>>     m_pLampController[0]->GetWindowRect(&rectDeviceWindow);

>>     if( rectMainClient.Width() < (2 * rectDeviceWindow.Width()) )
>>         ShowScrollBar(SB_HORZ, TRUE);
>>     else
>>         ShowScrollBar(SB_HORZ, FALSE);

>>     if( rectMainClient.Height() < (2 * rectDeviceWindow.Height()) )
>>         ShowScrollBar(SB_VERT, TRUE);
>>     else if(m_iVScrollPos == 0)
>>         ShowScrollBar(SB_VERT, FALSE);
>> }

>> void CDeviceTemplateDlg::OnVScroll(
>> UINT nSBCode,
>> UINT nPos,
>> CScrollBar* pScrollBar)
>> {
>>     int iAdjust, iPos = (int)nPos;
>>     CRect rectMainClient, rectDeviceWindow;

>>     if(pScrollBar == NULL)
>>     {
>>         switch(nSBCode)
>>         {
>>         case SB_THUMBTRACK:
>>             iAdjust = m_iVScrollPos - iPos;
>>             if(iAdjust != 0)
>>             {
>>                 ScrollWindow(0, iAdjust, NULL, NULL);
>>                 SetScrollPos(SB_VERT, iPos, TRUE);
>>                 m_iVScrollPos = iPos;
>>             }
>> //          Do_ShowScrollBars();    // Moved to 'OnPaint()'.
>>             break;

>>         case SB_LINEUP:
>>             if(m_iVScrollPos > 0)
>>             {
>>                 if(m_iVScrollPos > 9)
>>                     iAdjust = 10;
>>                 else
>>                     iAdjust = m_iVScrollPos;
>>                 ScrollWindow(0, iAdjust, NULL, NULL);
>>                 m_iVScrollPos -= iAdjust;
>>                 SetScrollPos(SB_VERT, m_iVScrollPos, TRUE);
>> //              Do_ShowScrollBars();    // Moved to 'OnPaint()'.
>>             }
>>             break;

>>         default:
>>             ;
>>         }
>>     }
>>     CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
>> }
>> ////////////////////////

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sun, 06 Jun 2004 03:24:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Window Dragging & Large NON Client area problems

2. hiding cursor only in client area

3. show or hide scrollbars?

4. hiding scrollbars of scrollview

5. how to hide scrollbars

6. How can I hide scrollbars in FormView?

7. Hiding scrollbars in a formview

8. How to hide ScrollBars of TreeCtrl ?

9. hiding the scrollbars in a CEditView

10. CScrollView - Hide Scrollbars

11. How can I hide scrollbars in FormView?

12. Hiding scrollbars in a formview

 

 
Powered by phpBB® Forum Software