Sign in to follow this  

Retaining Scroll Position

Recommended Posts

Well, this seems like it ought to be quite simple, but in fact it has me stumped. I have a List Box that is Owner Drawn, created like so: AdvWinFeatList = CreateWindowEx(NULL, "LISTBOX", "Feat List", WS_CHILD | WS_VSCROLL | LBS_NOSEL | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_NOTIFY, 615, 215, 280, 240, Parent, (HMENU)MS_ADVWINFEATSLIST, Instance, NULL); If a user drags an icon off this box and drops it in a particular place, the contents of this window get reset. The problem with this is that resetting the content also causes the vscrollbar to reset to the top, which is undesirable. So, all I need to do is grab the position of the scrollbar, reset the box contents, and put the scroll position back. Seems easy, but it's making me nuts :) Here is the code I have to do this:
ScrollInfo.cbSize = sizeof(ScrollInfo);
ScrollInfo.fMask = SIF_ALL;
GetScrollInfo(AdvWinFeatList, SB_VERT, &ScrollInfo);
FillFeatSelectBox();             //this is where the contents get reset
ScrollInfo.fMask = SIF_POS ;
SetScrollInfo(AdvWinFeatList, SB_VERT, &ScrollInfo, true);
ScrollWindow(AdvWinFeatList, 0, -ScrollInfo.nPos, NULL, NULL);

This does put the scrollbar where it's supposed to be, but the contents of the listbox appear as if the scrollbar is a the top. What in the world am I doing wrong here? Thanks -Ron [/source]

Share this post

Link to post
Share on other sites
Nevermind, I ripped all that nonsense out and just used LB_GETTOPINDEX and LB_SETTOPINDEX messages, and it worked just fine. All that was way too complex for such a simple task :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this