Re: Listbox selected line mostly just below bottom of window



You might want to look at my essay "The n habits of highly unsuccessful Windows programs"
to see my favorite hot-buttons of poor programming. It's on my MVP Tips site.

While a global handle variable is extremely poor style, it is not the reason for the
failure; and the SendMessage is ugly beyond belief, but is not the reason for the failure,
and the RedrawWindow is completely irrelevant to the solution of the problem; you could
replace it with the assignment statement
a = a;
which will be about as useful.

The reason for the failure is that you need to SetTopIndex, and I gave the algorithm in an
earlier message.
joe

On Wed, 28 Nov 2007 23:26:18 -0800, David Deley <deleyd@xxxxxxx> wrote:

Thank you. The code is CMAC, which is a home-grown language for writing
text editors in, and this code was written about a decade ago, so I'm
not surprised to learn the programming methods aren't great.
Unfortunately it's my primary source of real life examples of how to do
things. That and your wonderful book. I really need more documentation
and real life examples of how to do it right.
-D.D.

Joseph M. Newcomer wrote:
This is an MFC forum. Therefore, I assume MFC. On the other hand, if this is in pure C,
(a) you would not store its handle in a global variable
(b) you would use windowsx.h macros, specifically, ListBox_SetCurSel
(c) you would not use RedrawWindow to cause an update

so the same three bugs apply.
joe

On Tue, 27 Nov 2007 15:06:21 +0100, "Serge Wautier"
<serge_dontusethisaddress@xxxxxxxxxxxxxx> wrote:


I'd rather bet the OP doesn't use MFC.

Serge.
http://www.apptranslator.com

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:56jnk3h2ikesb2bcqnv74t5rkre1b40d0q@xxxxxxxxxx

There's something very, very, very wrong with this code. If you are
manipulating a
listbox,

(a) you would not store its handle in a global variable
(b) you would not use SendMessage to make a selection
(c) you would not use redrawwindow to cause an update

You would
(a) update it only from the dialog class, and ONLY from within the dialog
class, and
therefore its variable would be a member of that dialog class
(b) you would use c_VariableName.SetCurSel(C_LINE-1); not SendMessage
(c) the second line would never, ever exist for any reason.

Three bugs in two lines of code is not good odds.

If line is partially displayed and you want it to be fully displayed, one
solution is:

CRect r;
c_MyListBox.GetClientRect(&r);
while(TRUE)
{ /* shift up */
CRect item;
c_MyListBox.GetItemRect(&item);
if(item.bottom > r.bottom)
{ /* it is off the screen */
int n = c_MyListBox.GetTopIndex();
c_MyListBox.SetTopIndex(n + 1);
} /* it is off the screen */
else
break;
} /* shift up */

There is no reason to suspect that RedrawWindow would have anything to do
with listbox
item alignment.
joe

On Mon, 26 Nov 2007 23:52:06 -0800, David Deley <deleyd@xxxxxxx> wrote:


I think I'm just missing a call of some sort. I have a listbox. Then I
sort the lines, select the line I want and redisplay the listbox using:

sendmessage( g_TagBrowse_HDlg, LB_SETCURSEL, C_LINE-1, 0);
RedrawWindow( window, 0, 0, rdw_Invalidate );

But sometimes my selected line is mostly just below the bottom of the
window. (see image http://members.cox.net/deleyd2/misc/listbox.gif )

I'm relatively new to this so I assume the problem is I just need to
make another call of some sort to get the line fully in view?

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.