CScrollBar的困惑及解决

使用一个CScrollBar后,在增加scrollrange为一个较大的范围之后拖了一段自动返回起始端,百思不得其解。


msdn上有讲产生这个问题的原因以及解决方案,感谢csdn和msdn

以下引用自msdn2002:

Remarks

The GetScrollInfo function enables applications to use 32-bit scroll positions. Although the messages that indicate scroll-bar position, WM_HSCROLL and WM_VSCROLL, provide only 16 bits of position data, the functions SetScrollInfo and GetScrollInfo provide 32 bits of scroll-bar position data. Thus, an application can call GetScrollInfo while processing either the WM_HSCROLL or WM_VSCROLL messages to obtain 32-bit scroll-bar position data.

To get the 32-bit position of the scroll box (thumb) during a SB_THUMBTRACK request code in a WM_HSCROLL or WM_VSCROLL message, call GetScrollInfo with the SIF_TRACKPOS value in the fMask member of the SCROLLINFO structure. The function returns the tracking position of the scroll box in the nTrackPos member of the SCROLLINFO structure. This allows you to get the position of the scroll box as the user moves it. The following sample code illustrates the technique.

 

int    nCurPos;
SCROLLINFO si;

switch()
{
    .
    .
    .

    case SB_THUMBTRACK:

        // Initialize SCROLLINFO structure
        ZeroMemory(&si, sizeof(SCROLLINFO));

        si.cbSize = sizeof(SCROLLINFO);
        si.fMask  = SIF_TRACKPOS;

        // Call GetScrollInfo to get current tracking
        // position in si.nTrackPos
        if (!GetScrollInfo(&si, SIF_TRACKPOS))
            return 1;    // GetScrollInfo failed

        nCurPos = si.nTrackPos;

        break;
        .
        .
        .
}

SetScrollPos(nCurPos);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值