richedit设置滚动条的位置和更新内容

需要txt发现读者richedit的scrollbar位置(为了便于下一次读,直接访问与上次读取下一个读取位置)不值得治疗,采用GetScrollPos、SetScrollPos你可以设置scorllbar位置值。可是!

SetScorllPos调用后仅仅更新了scorllbar的位置richedit的内容没得到更新,google一下没有个现成的解决。仅仅得msdn。

WM_VSCROLL重点标记一下:

SB_THUMBPOSITION

The user has dragged the scroll box (thumb) and released the mouse button. The HIWORD indicates the position of the scroll box at the end of the drag operation.

However, because the  SetScrollInfo SetScrollPos SetScrollRange GetScrollInfo , GetScrollPos , and  GetScrollRange  functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the  WM_HSCROLL  and  WM_VSCROLL  messages. See GetScrollInfo  for a description of the technique.


GetScrollInfo重点标记一下:

SIF_TRACKPOS

Copies the current scroll box tracking position to the nTrackPosmember of the SCROLLINFO structure pointed to by lpsi.

 

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 theWM_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.

SCROLLINFO si;
case WM_HSCROLL:
    switch(LOWORD(wparam)) {
        case SB_THUMBTRACK:
          // Initialize SCROLLINFO structure
 
            ZeroMemory(&si, sizeof(si));
            si.cbSize = sizeof(si);
            si.fMask = SIF_TRACKPOS;
 
          // Call GetScrollInfo to get current tracking 
          //    position in si.nTrackPos
 
            if (!GetScrollInfo(hwnd, SB_HORZ, &si) )
                return 1; // GetScrollInfo failed
            break;
        .
        .
        .
    }


实现本文功能:
//保存scrollbar位置
  SCROLLINFO Info={0};
  Info.cbSize=sizeof Info;
  Info.fMask=SIF_TRACKPOS;
  GetScrollInfo(RichEdit1->Handle,SB_VERT,&Info);
  std::auto_ptr<TIniFile> ptrIni(new TIniFile(ExtractFilePath(Application->ExeName)+"Config"));
  ptrIni->WriteInteger("Reader","ScorllPos",Info.nTrackPos);




//设置scrollbar位置
    std::auto_ptr<TIniFile> ptrIni(new TIniFile(ExtractFilePath(Application->ExeName)+"Config"));
    int pos=ptrIni->ReadInteger("Reader","ScorllPos",0);
    SendMessage(RichEdit1->Handle,WM_VSCROLL,MAKEWPARAM(SB_THUMBPOSITION,pos),0);


版权声明:本文博主原创文章,博客,未经同意不得转载。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值