ScrollBar & ScrollWindow

来源:互联网 发布:设置软件管理员权限 编辑:程序博客网 时间:2024/05/02 01:59

windows创建的window是默认提供scrollbar功能的.在CreateWindow的时候就可以制定window的属性.WS_VSCROLL 和 WM_HSCROLL.另外windows提供了一些api用于操作scrollbar.

 

主要就是这些API

 

EnableScrollBar

The EnableScrollBar function enables or disables one or both scroll bar arrows.

GetScrollBarInfo

The GetScrollBarInfo function retrieves information about the specified scroll bar.

GetScrollInfo

The GetScrollInfo function retrieves the parameters of a scroll bar, including the minimum and maximum scrolling positions, the page size, and the position of the scroll box (thumb).

GetScrollPos

The GetScrollPos function retrieves the current position of the scroll box (thumb) in the specified scroll bar. The current position is a relative value that depends on the current scrolling range. For example, if the scrolling range is 0 through 100 and the scroll box is in the middle of the bar, the current position is 50.

Note   The GetScrollPos function is provided for backward compatibility. New applications should use the GetScrollInfo function.

 

GetScrollRange

The GetScrollRange function retrieves the current minimum and maximum scroll box (thumb) positions for the specified scroll bar.

Note  The GetScrollRange function is provided for compatibility only. New applications should use the GetScrollInfo function.

 

ScrollDC

The ScrollDC function scrolls a rectangle of bits horizontally and vertically.

ScrollWindow

The ScrollWindow function scrolls the contents of the specified window's client area.

Note  The ScrollWindow function is provided for backward compatibility. New applications should use the ScrollWindowEx function.

 

ScrollWindowEx

The ScrollWindowEx function scrolls the contents of the specified window's client area.

SetScrollInfo

The SetScrollInfo function sets the parameters of a scroll bar, including the minimum and maximum scrolling positions, the page size, and the position of the scroll box (thumb). The function also redraws the scroll bar, if requested.

SetScrollPos

The SetScrollPos function sets the position of the scroll box (thumb) in the specified scroll bar and, if requested, redraws the scroll bar to reflect the new position of the scroll box.

Note  The SetScrollPos function is provided for backward compatibility. New applications should use the SetScrollInfo function.

 

SetScrollRange

The SetScrollRange function sets the minimum and maximum scroll box positions for the specified scroll bar.

Note  The SetScrollRange function is provided for backward compatibility. New applications should use the SetScrollInfo function.

 

ShowScrollBar

The ShowScrollBar function shows or hides the specified scroll bar.

 

MFC中的CWnd是提供了一些函数封装了scrollbar的api的.

如果你不想使用系统提供的api的话,你可以重载CScrollBar,并替换.

 

 

上面的api中,有一个是可以拿出来讲一讲到. 

ScrollWindow和ScrollWindowEx这两个函数是把滚动当前的窗口.分两种情况讨论这个函数.
当你的窗口是一个有资源中创建的窗口.OnPaint中使用默认的处理.这时候,当你滚动了滚动条,你可以调用ScrollWindow,系统会默认把窗口上移动,或者下移.
当你的窗口是一个自绘的呢? 你需求在OnPaint中做所有的界面处理的话.这时候,调用ScrollWindow帮不了你多少忙.
你还是要在OnPaint中小心的处理关于滚动后才一些位置信息.
OnPaint的时候,你获取的DC是相对于窗口的绘制区域的.当窗口滚动后,你应该把滚动后的区域绘制在client rect中.
至于ScrollWindow到底做了啥东西的话.这个不是很清楚.试了一下,自绘的情况,不调用Scroolwindow一样可以.不过你要手动调用RedrawWindow强制重绘,否则不会触发绘制.也就是说ScroolWindow起码会计算需要重绘的区域,然后触发重绘.

 

原创粉丝点击