Re: CScrollView::SetScrollSizes()
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 09 Jul 2005 01:54:27 -0400
Yes, it is the responsibility of the view to set the scroll sizes, because it controls the
display of the information. For example, changing the font size is a view responsibility,
and this changes the amount of scrolling required.
Changing these in OnDraw has its own risks. For example, you can end up in endless cycles
as the OnDraw decides that the scroll sizes change, which changes the amount of
information displayed, which requires OnDraw be called, which then, as a consequence of
the change, changes the scrolling sizes, which then means that information has to be
redisplayed. I've see this happen several times. So you have to make sure that when you
assess the size based on the OnDraw layout that you don't do something that can cause you
to enter this kind of loop. (It is sometimes easy to avoid, sometimes hard. In all cases,
however, where I encountered it, exercising a small amount of care made the problem go
away. A classic example: a new line scrolled onto the screen. It was wider than the
display area. So horizontal scrolling was needed. OnDraw enabled the horizontal scrollbar.
When it popped up, it hid the line, which meant that all remaining lines were now shorter,
so the scrollbar wasn't required. So it was removed. This then caused the long line to be
displayed, which meant that a horizontal scrollbar was required...and so on. I fixed this
one by simply changing the code to always leave the horizontal scrollbar displayed.
joe
On Fri, 8 Jul 2005 23:36:20 -0400, "George B" <ghbennett@xxxxxxxxxxx> wrote:
>I am confused about how to obtain the parameters for this function call.
>I'm using VC6, trying to display some text in the view window. The help
>documentation suggests that the appropriate size for this function call
>should be obtained from a Document function: GetMyDocSize(). But the
>document doesn't know how many pixels will be generated in the display.
>GetMyDocSize() could furnish the total number of lines in the document, but
>only the View can determine how many pixels will be required. The help
>documentation suggests putting the call to SetScrollSizes in either
>OnInitialUpdate or OnUpdate, but it seems that a better way to do this would
>be to call SetScrollSizes from OnDraw(), after using GetTextExtent() to
>determine the exact size needed to display the current text.
>
>How do experienced MFC programmers handle this situation?
>
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- CScrollView::SetScrollSizes()
- From: George B
- CScrollView::SetScrollSizes()
- Prev by Date: Re: new ...delete not working
- Next by Date: Re: new ...delete not working
- Previous by thread: CScrollView::SetScrollSizes()
- Next by thread: Re: CScrollView::SetScrollSizes()
- Index(es):
Relevant Pages
|