in reply to How can I reset the vertical scroll position in Perl using Win32::GUI?

Once you've scrolled with ScrollPos (or Scroll and the SB_TOP keyword, see GUI.xs:1319), then I think you need to call ScrollCaret (see Textfield.xs:591). From msdn: "Scrolls the caret into view in an edit control."

Replies are listed 'Best First'.
Re^2: How can I reset the vertical scroll position in Perl using Win32::GUI?
by Anonymous Monk on Dec 31, 2009 at 10:26 UTC

    I just noticed another thing: in the text field Scroll method (Textfield.xs:524), the last thing the method does is to send EM_SCROLLCARET (Textfield.xs:586), which is the only thing that ScrollCaret does.

    On the other hand, ScrollPos only acts on the scrollbar, so it doesn't know what attached fields to update.

    If simply calling ScrollCaret doesn't work (I haven't tested it), passing SB_TOP to Scroll might.

      Anonymous Monk, Thanks a lot for taking the time to asnwer my question.

      Your explanation about ScrollPos makes very good sense. Thanks :) Now I understand when the scrollbar seems to be reset,why the textfield content isn't updated.

      With your suggestion, I tried adding
      $Object->Birthchart->Scroll(1,SB_TOP); $Object->Birthchart->ScrollCaret(); $Object->Birthchart->ScrollPos(1,0);
      But the problem persists. Where might I be doing wrong here? Thanks :)

        I think I found a satisfactory technique. After (re)discovering it, I actually recall using it when I putzed around in VB6 I learned C or Perl. (Tested code follows.)

        my @sel = $textfield->GetSel(); $textfield->Append($content); $textfield->SetSel(@sel); $textfield->ScrollCaret(); $textfield->SetFocus();

        Here, you save the current selection, add text which move the caret and scrollbar, then reset the caret to the former position, and then scroll to the caret (the focus is optional). Each operation is extremely fast, so it looks seamless: the scrollbar grows to indicate the new document size, but the viewport of the text field is unchanged.

        You could use ->SetSel(0,0) to force the caret to the top, and then ->ScrollCaret to scroll there, but if you want the user to be able to look around the data while it's filling, saving and resetting caret position is optimal. (I've encountered apps in the wild which don't do that, and waiting for the data to stop coming in so you can read it is annoying).

        If there's a simpler way to prevent moving the caret or scroll position while changing the text field's contents, it isn't obvious either in the Win32::GUI XS code or in the MSDN docs realting to EM_* messages.