Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
Windows Controls
Control Library
Scroll Bar
 ScrollWindowEx function
ScrollWindowEx function

Applies to: desktop apps only

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

Syntax

int ScrollWindowEx(
  __in   HWND hWnd,
  __in   int dx,
  __in   int dy,
  __in   const RECT *prcScroll,
  __in   const RECT *prcClip,
  __in   HRGN hrgnUpdate,
  __out  LPRECT prcUpdate,
  __in   UINT flags
);

Parameters

hWnd [in]

Type: HWND

Handle to the window where the client area is to be scrolled.

dx [in]

Type: int

Specifies the amount, in device units, of horizontal scrolling. This parameter must be a negative value to scroll to the left.

dy [in]

Type: int

Specifies the amount, in device units, of vertical scrolling. This parameter must be a negative value to scroll up.

prcScroll [in]

Type: const RECT*

Pointer to a RECT structure that specifies the portion of the client area to be scrolled. If this parameter is NULL, the entire client area is scrolled.

prcClip [in]

Type: const RECT*

Pointer to a RECT structure that contains the coordinates of the clipping rectangle. Only device bits within the clipping rectangle are affected. Bits scrolled from the outside of the rectangle to the inside are painted; bits scrolled from the inside of the rectangle to the outside are not painted. This parameter may be NULL.

hrgnUpdate [in]

Type: HRGN

Handle to the region that is modified to hold the region invalidated by scrolling. This parameter may be NULL.

prcUpdate [out]

Type: LPRECT

Pointer to a RECT structure that receives the boundaries of the rectangle invalidated by scrolling. This parameter may be NULL.

flags [in]

Type: UINT

Specifies flags that control scrolling. This parameter can be a combination of the following values.

ValueMeaning
SW_ERASE

Erases the newly invalidated region by sending a WM_ERASEBKGND message to the window when specified with the SW_INVALIDATE flag.

SW_INVALIDATE

Invalidates the region identified by the hrgnUpdate parameter after scrolling.

SW_SCROLLCHILDREN

Scrolls all child windows that intersect the rectangle pointed to by the prcScroll parameter. The child windows are scrolled by the number of pixels specified by the dx and dy parameters. The system sends a WM_MOVE message to all child windows that intersect the prcScroll rectangle, even if they do not move.

SW_SMOOTHSCROLL

Windows 98/Me, Windows 2000/XP: Scrolls using smooth scrolling. Use the HIWORD portion of the flags parameter to indicate how much time, in milliseconds, the smooth-scrolling operation should take.

 

Return value

Type: int

If the function succeeds, the return value is SIMPLEREGION (rectangular invalidated region), COMPLEXREGION (nonrectangular invalidated region; overlapping rectangles), or NULLREGION (no invalidated region).

If the function fails, the return value is ERROR. To get extended error information, call GetLastError.

Remarks

If the SW_INVALIDATE and SW_ERASE flags are not specified, ScrollWindowEx does not invalidate the area that is scrolled from. If either of these flags is set, ScrollWindowEx invalidates this area. The area is not updated until the application calls the UpdateWindow function, calls the RedrawWindow function (specifying the RDW_UPDATENOW or RDW_ERASENOW flag), or retrieves the WM_PAINT message from the application queue.

If the window has the WS_CLIPCHILDREN style, the returned areas specified by hrgnUpdate and prcUpdate represent the total area of the scrolled window that must be updated, including any areas in child windows that need updating.

If the SW_SCROLLCHILDREN flag is specified, the system does not properly update the screen if part of a child window is scrolled. The part of the scrolled child window that lies outside the source rectangle is not erased and is not properly redrawn in its new destination. To move child windows that do not lie completely within the rectangle specified by prcScroll, use the DeferWindowPos function. The cursor is repositioned if the SW_SCROLLCHILDREN flag is set and the caret rectangle intersects the scroll rectangle.

All input and output coordinates (for prcScroll, prcClip, prcUpdate, and hrgnUpdate) are determined as client coordinates, regardless of whether the window has the CS_OWNDC or CS_CLASSDC class style. Use the LPtoDP and DPtoLP functions to convert to and from logical coordinates, if necessary.

Examples

For an example, see Scrolling Text with the WM_PAINT Message.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Other Resources
DeferWindowPos
DPtoLP
LPtoDP
RECT
RedrawWindow
UpdateWindow

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Earlier comment about invalidation is wrong      Ifeanyi. Echeruo   |   Edit   |   Show History
In the example given ScrollWindowEx is not passed the SW_INVALIDATE flag so it, correctly, does not invalidate the region.
Tags What's this?: Add a tag
Flag as ContentBug
Painting bits scrolled from the outside to the inside      Mityador   |   Edit   |   Show History
Description of the parameter prcClip says: "Bits scrolled from the outside of the rectangle to the inside are painted."
That's not true. You have to paint them or (preferably) invalidate the area manually.
If scrolling just horizontally or vertically (but not both), you can easily use the parameter prcUpdate for that purpose.

For example:
void ScrollHorizontally(HWND hWnd, int dx, RECT* prcScroll)
{
RECT rcUpdate;

ScrollWindowEx(hWnd, dx, 0, &;;prcScroll, &;;prcScroll, NULL, &;;rcUpdate, 0);
InvalidateRect(hWnd, &;;rcUpdate, TRUE);
}
									
Tags What's this?: Add a tag
Flag as ContentBug
SW_SMOOTHSCROLL and WM_PRINTCLIENT      Trevor Fellman   |   Edit   |   Show History

SW_SMOOTHSCROLL flag results that the scroll is animated, and thus requres the target window to handle WM_PRINTCLIENT. See http://msdn.microsoft.com/en-us/library/ms534913(VS.85).aspx

Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker