Re: CScrollView::SetScrollSizes()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: re Rich Text Box
    ... RichTextBox (with vertical scrollbar on) to more than it can display (30 ... > the right line gets selected however the list moves with a selection. ...
    (microsoft.public.vb.general.discussion)
  • Re: Baby Scroller 101 Help Please
    ... You can generally tell how my other programming projects are going by how often I find a need to distract myself with a newsgroup. ... I set the LargeChange ... In the case of displaying lines of text, the "unit" is a single line of text and LargeChange would be set to the number of lines you can display in a window. ... The behavior of the scrollbar when programmatically setting its ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Resizing form at runtime (System Metrics)
    ... contains a list of team members for an account. ... I dynamically resize it ... while still offering the option of a scrollbar once the ... I use this form to display some text and multiple choices to my user for ...
    (microsoft.public.vb.general.discussion)
  • Re: 8 Bytes support in scroll functions
    ... So i'll display data at this offset. ... A scrollbar doesn't ... get is 1 pixel, so on a 1024x768 display, a horizontal scrollbar can ... GetScrollPos and SetScrollRange takes int as input and return an int ...
    (microsoft.public.vc.mfc)