[英]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. 在此之后,显示的
CListCtrl
没有滚动条(滚动条只是隐藏在某个地方),并且在我选择并使用向下按钮移动通过列表后显示。 What may cause this behavior? 什么可能导致此行为? PS: Nothing change if I call
SetScrollInfo(SB_VERT,&si)
before Invalidate()
. PS:如果在
Invalidate()
之前调用SetScrollInfo(SB_VERT,&si)
则没有任何改变。
Way with EnsureVisible
works partially. EnsureVisible
方式部分起作用。 I can use EnsureVisible
, but GetTopIndex
always returns 0
. 我可以使用
EnsureVisible
,但GetTopIndex
始终返回0
。
Hope your SetScrollInfo and GetScrollInfo are not windows api since windows api takes HWND as your first argument. 希望您的SetScrollInfo和GetScrollInfo不是Windows api,因为Windows api将HWND作为您的第一个参数。
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.