| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8754 人关注过本帖
标题:求setscrollrange 和setscrollsizes的区别
只看楼主 加入收藏
cumtzdhlx
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2007-7-8
收藏
 问题点数:0 回复次数:3 
求setscrollrange 和setscrollsizes的区别
setscrollrange 和setscrollsizes的区别
在WINDOWS程序设计书的第四章介绍了滚动条的用法,他用setscrollrange来设置滚动条的范围
BOOL SetScrollRange(
  HWND hWnd,    // handle to window
  int nBar,     // scroll bar
  int nMinPos,  // minimum scrolling position
  int nMaxPos,  // maximum scrolling position
  BOOL bRedraw  // redraw flag
);
在书中的程序中,在WM_CREATE消息响应函数中设置了滚动条的范围和初始化位置,setscrollrange(hwnd,SB_VERT,0,NUMLINES-1,TRUE),NUMLINES为75
然后在WM_VSCROLL消息中,当WPARAM的低字节为SB_LINEDOWN时,使当前位置+1,但总的范围不超过75,这是WIN32中滚动条操作.

在MFC中,C**View类派生于CScrollView,则应该在
void C**View::OnInitialUpdate()
{
    CScrollView::OnInitialUpdate();

    CSize sizeTotal;
    // TODO: calculate the total size of this view
    sizeTotal.cx = 0;
    sizeTotal.cy = 1900;
    SetScrollSizes(MM_TEXT, sizeTotal);
}
对滚动VIEW窗口设置大小,SetScrollSizes的作用就是如此,此时候我们会发现生成的程序是一个带有垂直滚动条的窗口,为了弄清楚setscrollrange 和setscrollsizes的区别,我在
void C**View::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    SetScrollRange(SB_VERT,0,75,TRUE);
        CScrollView::OnLButtonDown(nFlags, point);
}
中设置了滚动条滚动范围,和WINDOWS程序设计中的一样,我将其设置为75.
然后在
void CVscrollView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: Add your message handler code here and/or call default
    static int i=0;
         if(i<=74)
         {     
      if(nChar==VK_DOWN)
      {
        SetScrollPos(SB_VERT,++i,TRUE);
      }
         }
    CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
按我的理解,滚动条范围被设置为75,而滚动窗口被设置为1900,那么当我按下下移箭头键时,窗口应该滚动1900/75个设备单位,而滚动条下移1,但是,实际运行结果为按下下移箭头键时,滚动条的确移动了1,而窗口也只是移动了1个设备单位,并且滚动条的范围好象不是75那么长,而是有1900的长度,所以每次下移的时候,移动很少的位置.
应该是我对其理解有问题请大家告诉我他们俩的区别,及其用法

[[it] 本帖最后由 cumtzdhlx 于 2008-3-23 17:45 编辑 [/it]]
搜索更多相关主题的帖子: int BOOL position scrolling VERT 
2008-03-23 17:44
余来
Rank: 6Rank: 6
等 级:贵宾
威 望:26
帖 子:956
专家分:18
注 册:2006-8-13
收藏
得分:0 
SetScroolRange是设置滚动的范围值,如0~100,而SetScroolSizes是设置参数,如画出进度时的采用比例等,具体意思可参见MSDN,MSDN原解释如下:


void SetScrollSizes( int nMapMode, SIZE sizeTotal, const SIZE& sizePage = sizeDefault, const SIZE& sizeLine = sizeDefault );

Parameters

nMapMode

The mapping mode to set for this view. Possible values include:

Mapping Mode Logical Unit Positive y-axis Extends...
MM_TEXT 1 pixel Downward
MM_HIMETRIC 0.01 mm Upward
MM_TWIPS 1/1440 in Upward
MM_HIENGLISH 0.001 in Upward
MM_LOMETRIC 0.1 mm Upward
MM_LOENGLISH 0.01 in Upward


All of these modes are defined by Windows. Two standard mapping modes, MM_ISOTROPIC and MM_ANISOTROPIC, are not used for CScrollView. The class library provides the SetScaleToFitSize member function for scaling the view to window size. Column three in the table above describes the coordinate orientation.

sizeTotal

The total size of the scroll view. The cx member contains the horizontal extent. The cy member contains the vertical extent. Sizes are in logical units. Both cx and cy must be greater than or equal to 0.

sizePage

The horizontal and vertical amounts to scroll in each direction in response to a mouse click in a scroll-bar shaft. The cx member contains the horizontal amount. The cy member contains the vertical amount.

sizeLine

The horizontal and vertical amounts to scroll in each direction in response to a mouse click in a scroll arrow. The cx member contains the horizontal amount. The cy member contains the vertical amount.

Remarks

Call SetScrollSizes when the view is about to be updated. Call it in your override of the OnUpdate member function to adjust scrolling characteristics when, for example, the document is initially displayed or when it changes size.

You will typically obtain size information from the view’s associated document by calling a document member function, perhaps called GetMyDocSize, that you supply with your derived document class. The following code shows this approach:

SetScrollSizes( nMapMode, GetDocument( )->GetMyDocSize( ) );

Alternatively, you might sometimes need to set a fixed size, as in the following code:

SetScrollSizes( nMapMode, CSize(100, 100) );

You must set the mapping mode to any of the Windows mapping modes except MM_ISOTROPIC or MM_ANISOTROPIC. If you want to use an unconstrained mapping mode, call the SetScaleToFitSize member function instead of SetScrollSizes.

Example

void CScaleView::OnUpdate( )
{
   // ...
   // Implement a GetDocSize( ) member function in
   // your document class; it returns a CSize.
   SetScrollSizes( MM_LOENGLISH, GetDocument( )->GetDocSize( ) );
   ResizeParentToFit( );   // Default bShrinkOnly argument
   // ...
}

2008-03-23 19:22
cumtzdhlx
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2007-7-8
收藏
得分:0 
还是不懂啊 ,,,那我在上面的程序中调用一次SetScrollRange(SB_VERT,0,75,TRUE);的作用是什么..
难道说到74的地方滚动条就不能移动了吗
2008-03-23 19:29
余来
Rank: 6Rank: 6
等 级:贵宾
威 望:26
帖 子:956
专家分:18
注 册:2006-8-13
收藏
得分:0 
也可以这么说,如果设置74为最大值,那么滚动到最右边,其值就是74了(假设是横向滚动)

2008-03-24 12:14
快速回复:求setscrollrange 和setscrollsizes的区别
数据加载中...
 
   



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

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