| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:windows滚动条位置设定后又马上重新获取。
只看楼主 加入收藏
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
windows滚动条位置设定后又马上重新获取。
现在本菜鸟再看windows程序设计的第四章,关于滚动条的程序截取部分如下:
   switch (message)
     {
     case WM_CREATE:
          hdc = GetDC (hwnd) ;
         
          GetTextMetrics (hdc, &tm) ;
          cxChar = tm.tmAveCharWidth ;
          cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
          cyChar = tm.tmHeight + tm.tmExternalLeading ;
         
          ReleaseDC (hwnd, hdc) ;

               // Save the width of the three columns
         
          iMaxWidth = 40 * cxChar + 22 * cxCaps ;
          return 0 ;
         
     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;

               // Set vertical scroll bar range and page size

          si.cbSize = sizeof (si) ;
          si.fMask  = SIF_RANGE | SIF_PAGE ;
          si.nMin   = 0 ;
          si.nMax   = NUMLINES - 1 ;
          si.nPage  = cyClient / cyChar ;
          SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;

               // Set horizontal scroll bar range and page size

          si.cbSize = sizeof (si) ;
          si.fMask  = SIF_RANGE | SIF_PAGE ;
          si.nMin   = 0 ;
          si.nMax   = 2 + iMaxWidth / cxChar ;
          si.nPage  = cxClient / cxChar ;
          SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ;
          return 0 ;
         
     case WM_VSCROLL:
               // Get all the vertial scroll bar information

          si.cbSize = sizeof (si) ;
          si.fMask  = SIF_ALL ;
          GetScrollInfo (hwnd, SB_VERT, &si) ;

               // Save the position for comparison later on

          iVertPos = si.nPos ;

          switch (LOWORD (wParam))
          {
          case SB_TOP:
               si.nPos = si.nMin ;
               break ;
               
          case SB_BOTTOM:
               si.nPos = si.nMax ;
               break ;
               
          case SB_LINEUP:
               si.nPos -= 1 ;
               break ;
               
          case SB_LINEDOWN:
               si.nPos += 1 ;
               break ;
               
          case SB_PAGEUP:
               si.nPos -= si.nPage ;
               break ;
               
          case SB_PAGEDOWN:
               si.nPos += si.nPage ;
               break ;
               
          case SB_THUMBTRACK:
               si.nPos = si.nTrackPos ;
               break ;
               
          default:
               break ;         
          }
               // Set the position and then retrieve it.  Due to adjustments
               //   by Windows it may not be the same as the value set.


          si.fMask = SIF_POS ;
          SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
          GetScrollInfo (hwnd, SB_VERT, &si) ;


               // If the position has changed, scroll the window and update it

          if (si.nPos != iVertPos)
          {                    
               ScrollWindow (hwnd, 0, cyChar * (iVertPos - si.nPos),
                                   NULL, NULL) ;
               UpdateWindow (hwnd) ;
          }
          return 0 ;
我不明白的是si.nPos位置已经设定了,为什么还要重新获取,注释说有可能被windows更改,但是为什么会被windows更改,难道windows可以返回实时的滚动条位置?但是如果windows可以返回实时的滚动条位置,那就没有必要计算si.nPos的值了。。
求各位大神解答。
搜索更多相关主题的帖子: 程序设计 message windows 
2015-03-19 20:34
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
收藏
得分:14 
试着学习过win32API来写GUI
最后还是放弃了
正在努力看gtk+中
也是头大如斗……
干脆放弃用C写GUI算了

有这许多的精力 还不如学点轻松些的
比如C#
也好迎接win10的到来

Only the Code Tells the Truth             K.I.S.S
2015-03-19 20:41
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
收藏
得分:0 
回复 2楼 longwu9t
我是业余编程爱好者,手中正好有这本书,就拿来随便看看。。
2015-03-19 21:00
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
收藏
得分:0 
好吧,我好像懂了,是防止滚动条越界。
2015-03-19 21:41
快速回复:windows滚动条位置设定后又马上重新获取。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017986 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved