Scroll Bar Requests

The user makes scrolling requests by clicking various parts of a scroll bar. Windows CE sends the request to the specified window in the form of a WM_HSCROLL or WM_VSCROLL message for horizontal and vertical scroll bars, respectively. Each message includes a notification code that corresponds to the user's action to the handle of the scroll bar, for scroll bar controls only, and, in some cases, to the position of the scroll box.

Usually an application scrolls the content of a window in the direction opposite that indicated by the scroll bar. For example, when the user clicks the gray area below the scroll box, an application scrolls the object in the window upward to reveal a portion of the object that is below the visible portion. An application can also scroll a rectangular region using the ScrollDC function.

When you process the WM_CREATE message you can set scrolling units. It is convenient to base the scrolling units on the dimensions of the font associated with the window's display context (DC). To retrieve the font dimensions for a specific DC, use the GetTextMetrics function. When you process the WM_SIZE message, you can adjust the scrolling range and scrolling position to reflect the dimensions of the client area as well as the number of lines of text that will be displayed.

The scroll bar sends WM_HSCROLL and WM_VSCROLL messages to the window procedure whenever the user clicks the scroll bar or drags the scroll box. The low-order words of WM_VSCROLL and WM_HSCROLL each contain a notification message that indicates the direction and magnitude of the scrolling action.

When you process the WM_HSCROLL and WM_VSCROLL messages, you should examine the scroll bar notification message and calculate the scrolling increment. After you apply the increment to the current scrolling position, you can scroll the window to the new position by using the ScrollWindowEx function. You can use the SetScrollInfo function to adjust the position of the scroll box.

After you scroll a window, it makes part of the window's client area invalid. To ensure that the invalid region is updated, you use the UpdateWindow function to generate a WM_PAINT message.