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

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.

Replies are listed 'Best First'.
Re^5: How can I reset the vertical scroll position in Perl using Win32::GUI?
by ZJ_Mike (Initiate) on Dec 31, 2009 at 14:00 UTC
    Haha, this pesky problem is finally gone! LOL :D Thanks a lot, Anonymous Monk!! I really appreciate your help!! Thanks! The code works great and the explanation makes perfect sense ! Thanks!