Auto Scroll a ListBox
I have a program with a listbox that has alot of stuff added to it. My problem is that I want the window to automatically scroll so that the newest item is visible at the bottom, currently the user has to scroll down to see any new items added.
I'm using Visual C++ 6.0 and the default listboxes, I've tried changing the various choices under properties for it but none have worked so far. Hopefully this is something simple I'm missing, heh, thanks in advance for any replies.
Send the LB_SELECTSTRING message to the control.
wParam = (WPARAM) indexStart; // item before start of search
lParam = (LPARAM)(LPCTSTR)lpszFind; // address of search string
Value of wParam. Specifies the zero-based index of the item before the first item to be searched. When the search reaches the bottom of the list box, it continues from the top of the list box back to the item specified by the indexStart parameter. If indexStart is –1, the entire list box is searched from the beginning.
Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory.
Value of lParam. Pointer to the null-terminated string that contains the prefix to search for. The search is case independent, so this string can contain any combination of uppercase and lowercase letters.
If the search is successful, the return value is the index of the selected item. If the search is unsuccessful, the return value is LB_ERR and the current selection is not changed.
You may also want to use LB_FINDSTRING to find the last inserted item to use as the index if there can be multiple instances of the same string.
Thank you for the reply, I used that function and now it's almost working perfectly heh. My problem now is that, I'm using the listbox for a chat area, the program is Tic Tac Toe and you can connect to another computer to play it. The listbox now scrolls down if a new message comes in, unless the message is the same as the previous one. That's a pretty minor bug I can live with, but do you know how to fix that?
Heh, you updated on me while I was posting! I'll give that a try and see if I can get it to work.
:D Yeah, I gathered that you might have that problem so I put in the extra info. :)
Woo! I got it working, I had to use GetCount instead of FindString because FindString did the same thing as SelectString pretty much. Thank you for your help, this has been driving me nuts for a long time.
alos look at ENSUREVISIBLE