Thursday, May 13, 2004


Some notes on Scrollbar

Recently, I need to measure the width and height of a scollbar, then I read the interesting blog from Raymond Chen


There are two types of scrollbars
Remember that there are two types of scrollbars.

One is the standalone scrollbar control. This one has its own window handle, and consequently can be given focus and all those other fun things you can do with window handles. To manipulate them, pass the handle to the scrollbar control to the appropriate scrollbar function (SetScrollInfo, for example) and pass SB_CTL as the nBar parameter to indicate that you have a scrollbar control.

The other type is the horizontal or vertical scrollbar (or both) attached to a window by virtue of having the WS_HSCROLL and/or WS_VSCROLL style. These are nonclient scrollbars and are not controls. They are just decorations added to some other window. You can't give them focus since they aren't windows in their own right. To manipulate them, pass the handle to the containing window to the appropriate scrollbar function and pass SB_HORZ or SB_VERT as the nBar parameter to indicate that you want to manipulate the nonclient horizontal or vertical scrollbar.

I'm writing this down since some people seem to miss the distinction between these two cases.

Raymond wrote a funny series on how to implement scrollbar from 6/2003-9/2003. However, I still did not know how to measure the things we need. After a tired searching, finally I found that

System.Windows.Forms has a class SystemInformation and it has two properties as

Using Reflector, I know that this word can be easily done by two lines of code

scrollbar_width = ::GetSystemMetrics(2);
scrollbar_height = ::GetSystemMetrics(3);

Thanks a lot for Lutz Roeder!

<< Home

This page is powered by Blogger. Isn't yours?