诡异的问题,SetScrollInfo设置滚动条属性无效!!!

凌乱哥 2017-02-13 12:12:37
我从CWnd派生出了一个图片列表类,自己处理滚动条。
现在新增了一个排序模式需求,切换排序方式后滚动条的相关属性需要改变。
但是发现调用SetScrollInfo设置后无效,因为再用GetScrollInfo发现属性还是原来的值,代码如下:

SCROLLINFO info;
ZeroMemory(&info, sizeof(SCROLLINFO));
GetScrollInfo(SB_VERT, &info, SIF_ALL);//获取原来的属性值
info.nMin = 0;
info.nMax = iMaxPos + 15;
info.nPage = m_cyPanel;
info.nPos = 0;
SetScrollInfo(SB_VERT, &info, TRUE);//设置新属性

调试截图如下,获取原来的属性值:


设置新属性:


再次GetScrollInfo:


为什么设置不成功呢?而且SetScrollInfo的返回值是1,GetLastError也为0,属性值就是设置不进去,帮忙看看可能是什么原因
...全文
322 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2017-02-13
  • 打赏
  • 举报
回复
留意下 fMask 参数 fMask Specifies the scroll bar parameters to set or retrieve. This member can be a combination of the following values: Value Meaning SIF_ALL Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS. SIF_DISABLENOSCROLL This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it. SIF_PAGE The nPage member contains the page size for a proportional scroll bar. SIF_POS The nPos member contains the scroll box position, which is not updated while the user drags the scroll box. SIF_RANGE The nMin and nMax members contain the minimum and maximum values for the scrolling range. SIF_TRACKPOS The nTrackPos member contains the current position of the scroll box while the user is dragging it.
schlafenhamster 2017-02-13
  • 打赏
  • 举报
回复
只有 GetDataItemHeight() 才会引起 变化 !!!
凌乱哥 2017-02-13
  • 打赏
  • 举报
回复
引用 4 楼 schlafenhamster 的回复:
“切换排序方式后滚动条的相关属性需要改变” 即选择项 可能 需要 滚动, CListCtrl::EnsureVisible BOOL EnsureVisible( int nItem, BOOL bPartialOK ); Return Value Nonzero if successful; otherwise zero. 与滚动条无关吧
我是从CWnd派生出了一个图片列表类的,自己处理滚动条 也就是说比如有10张图片,本来一开始每行6个,两行就显示完了。现在换了个排序方式,分组显示,每行才一两个,所以有很多行,滚动条也就从无到有,并且要能正常滚动。就出现了我这个问题
schlafenhamster 2017-02-13
  • 打赏
  • 举报
回复
“切换排序方式后滚动条的相关属性需要改变” 即选择项 可能 需要 滚动, CListCtrl::EnsureVisible BOOL EnsureVisible( int nItem, BOOL bPartialOK ); Return Value Nonzero if successful; otherwise zero. 与滚动条无关吧
凌乱哥 2017-02-13
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
留意下 fMask 参数 fMask Specifies the scroll bar parameters to set or retrieve. This member can be a combination of the following values: Value Meaning SIF_ALL Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS. SIF_DISABLENOSCROLL This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it. SIF_PAGE The nPage member contains the page size for a proportional scroll bar. SIF_POS The nPos member contains the scroll box position, which is not updated while the user drags the scroll box. SIF_RANGE The nMin and nMax members contain the minimum and maximum values for the scrolling range. SIF_TRACKPOS The nTrackPos member contains the current position of the scroll box while the user is dragging it.
我发现只要设置nMax大于或等于nPage,就会有问题,否则就是正常的 但是要出现滚动条就必须把nMax大于nPage吧
凌乱哥 2017-02-13
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
留意下 fMask 参数 fMask Specifies the scroll bar parameters to set or retrieve. This member can be a combination of the following values: Value Meaning SIF_ALL Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS. SIF_DISABLENOSCROLL This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it. SIF_PAGE The nPage member contains the page size for a proportional scroll bar. SIF_POS The nPos member contains the scroll box position, which is not updated while the user drags the scroll box. SIF_RANGE The nMin and nMax members contain the minimum and maximum values for the scrolling range. SIF_TRACKPOS The nTrackPos member contains the current position of the scroll box while the user is dragging it.
我把上面那段代码的SIF_ALL改成了SIF_RANGE | SIF_PAGE,并且把info.nPos = 0;这行去掉了,还是一样的问题。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧