From: Piranha on
I have a multiline edit control, and I´m trying to scroll it to its
bottom after each content update.
For that I´m using:

SetWindowText(MyEdit,"SomeContent");
SendMessage(MyEdit,WM_VSCROLL,SB_BOTTOM,0);

This seems to work fine most of the time, but there are a few users
telling me that this will scroll not to the last line of the content,
but below the last line, so that only the last line remains visible.

I.e. if the edit control has 5 lines of text and the text is 10 lines
in total, this should scroll down to the 6th line and display the last
5 lines of the content, but in some cases this will scroll up to the
10th line and display only the 10th line plus 4 blank lines.

I wasn´t able to figure out under which circumstances this happens,
whether it depends on OS or font or what else, I can´t reproduce the
effect, all I can say is, 90% of the users get the correct display,
10% get it wrong.

Does anyone know, what the problem is and how to fix it?
From: r_z_aret on
On Mon, 22 Mar 2010 08:20:24 -0700 (PDT), Piranha <eu_piranha(a)gmx.net>
wrote:

>I have a multiline edit control, and I�m trying to scroll it to its
>bottom after each content update.
>For that I�m using:
>
>SetWindowText(MyEdit,"SomeContent");
>SendMessage(MyEdit,WM_VSCROLL,SB_BOTTOM,0);

WM_VSCROLL is for a scroll bar, not an edit control.

>
>This seems to work fine most of the time, but there are a few users
>telling me that this will scroll not to the last line of the content,
>but below the last line, so that only the last line remains visible.
>
>I.e. if the edit control has 5 lines of text and the text is 10 lines
>in total, this should scroll down to the 6th line and display the last
>5 lines of the content, but in some cases this will scroll up to the
>10th line and display only the 10th line plus 4 blank lines.
>
>I wasn�t able to figure out under which circumstances this happens,
>whether it depends on OS or font or what else, I can�t reproduce the
>effect, all I can say is, 90% of the users get the correct display,
>10% get it wrong.

You can use an EM_GETLINECOUNT message to get the number of lines, and
then an EM_LINESCROLL message to scroll as you wish. This snippet from
the description of EM_LINESCROLL should entice you:

"The control does not scroll vertically past the last line of text in
the edit control. If the current line plus the number of lines
specified by the lParam parameter exceeds the total number of lines in
the edit control, the value is adjusted so that the last line of the
edit control is scrolled to the top of the edit-control window. "

>
>Does anyone know, what the problem is and how to fix it?

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
http://catb.org/~esr/faqs/smart-questions.html
From: Piranha on
....

> You can use an EM_GETLINECOUNT message to get the number of lines, and
> then an EM_LINESCROLL message to scroll as you wish. This snippet from
> the description of EM_LINESCROLL should entice you:
>

....

Neither the edit control nor the font in the edit control have a fixed
size, meaning depending on the height of the control and the height of
the characters there may be anything between 3 and 25 lines visible.
I would have to calculate all those variables, from the controls
height over font dimensions up to line height, to determine how many
lines it should scroll.

SendMessage(MyEdit,WM_VSCROLL,SB_BOTTOM,0);

seemed to be so nice and easy, but if you´re saying

> WM_VSCROLL is for a scroll bar, not an edit control.

then I obviously need another solution.
If nothing else, I have to go through that calculation, but I would
prefer, if there was an easier, but still reliable way.
From: Paul N on
On 22 Mar, 20:59, Piranha <eu_pira...(a)gmx.net> wrote:
> ...
>
> > You can use an EM_GETLINECOUNT message to get the number of lines, and
> > then an EM_LINESCROLL message to scroll as you wish. This snippet from
> > the description of EM_LINESCROLL should entice you:
>
> ...
>
> Neither the edit control nor the font in the edit control have a fixed
> size, meaning depending on the height of the control and the height of
> the characters there may be anything between 3 and 25 lines visible.
> I would have to calculate all those variables, from the controls
> height over font dimensions up to line height, to determine how many
> lines it should scroll.
>
> SendMessage(MyEdit,WM_VSCROLL,SB_BOTTOM,0);
>
> seemed to be so nice and easy, but if you´re saying
>
> > WM_VSCROLL is for a scroll bar, not an edit control.
>
> then I obviously need another solution.
> If nothing else, I have to go through that calculation, but I would
> prefer, if there was an easier, but still reliable way.

How about the following? It moves the cursor to the end of the text by
setting the selection to be there. I think it will scroll so the
cursor is on, so you're done...

int ndx = GetWindowTextLength(GetDlgItem(hDlg, editbox));
SendDlgItemMessage(hDlg, editbox, EM_SETSEL, ndx, ndx);

If (as appears to be the case) your edit box is free standing rather
than being part of a dialog box, this will simplify to something like:

int ndx = GetWindowTextLength(MyEdit);
SendMessage(MyEdit, EM_SETSEL, ndx, ndx);

Hope that helps.
Paul.
From: Piranha on
On 22 Mrz., 22:50, Paul N <gw7...(a)aol.com> wrote:
> On 22 Mar, 20:59, Piranha <eu_pira...(a)gmx.net> wrote:
>
>
>
>
>
> > ...
>
> > > You can use an EM_GETLINECOUNT message to get the number of lines, and
> > > then an EM_LINESCROLL message to scroll as you wish. This snippet from
> > > the description of EM_LINESCROLL should entice you:
>
> > ...
>
> > Neither the edit control nor the font in the edit control have a fixed
> > size, meaning depending on the height of the control and the height of
> > the characters there may be anything between 3 and 25 lines visible.
> > I would have to calculate all those variables, from the controls
> > height over font dimensions up to line height, to determine how many
> > lines it should scroll.
>
> > SendMessage(MyEdit,WM_VSCROLL,SB_BOTTOM,0);
>
> > seemed to be so nice and easy, but if you´re saying
>
> > > WM_VSCROLL is for a scroll bar, not an edit control.
>
> > then I obviously need another solution.
> > If nothing else, I have to go through that calculation, but I would
> > prefer, if there was an easier, but still reliable way.
>
> How about the following? It moves the cursor to the end of the text by
> setting the selection to be there. I think it will scroll so the
> cursor is on, so you're done...
>
> int ndx = GetWindowTextLength(GetDlgItem(hDlg, editbox));
> SendDlgItemMessage(hDlg, editbox, EM_SETSEL, ndx, ndx);
>
> If (as appears to be the case) your edit box is free standing rather
> than being part of a dialog box, this will simplify to something like:
>
> int ndx = GetWindowTextLength(MyEdit);
> SendMessage(MyEdit, EM_SETSEL, ndx, ndx);
>
> Hope that helps.
> Paul.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Good one, thanks.
It didn´t scroll right away, I had to add an EM_SCROLLCARET
but your idea got me there.
thanks again.
 | 
Pages: 1
Prev: BilBlt and SRCPAINT
Next: C++ Win32 forum?