简体   繁体   中英

Scroll bar hide after SetScrollInfo() call

I have a problem with scrollbar. I'm trying to save scrollbar position before refresh scrollbar and then set saved position again. I use the following code:

SCROLLINFO si;
GetScrollInfo(SB_VERT, &si);
//Then I do stuff related with refresh
SetItemCountEx((int)moElements.GetSize(), LVSICF_NOINVALIDATEALL);
// Then stuff that sort elements...
Invalidate();
SetScrollInfo(SB_VERT,&si);

After this, CListCtrl shown without scrollbar (scrollbar just hide somewhere) and it shows after I select and with down button move thru the list. What may cause this behavior? PS: Nothing change if I call SetScrollInfo(SB_VERT,&si) before Invalidate() .

Way with EnsureVisible works partially. I can use EnsureVisible , but GetTopIndex always returns 0 .

Hope your SetScrollInfo and GetScrollInfo are not windows api since windows api takes HWND as your first argument.

Hi, I guess you should be doing this.

SCROLLINFO si = {};
si.cbSize = sizeof(SCROLLINFO);//This step is always required for backward compatibility
si.fMask = SIF_POS;
GetScrollInfo(Window,SB_VERT,&si);
//Do your stuff.
UINT scrollBarPos = si.nPos;//Save currentPos
SetScrollInfo(Window,SB_VERT,&si,true);
//true parameter will tell Windows to invalidate the screen and redraw.
//No need to call InvalidateRect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM