Major tidy up of Scroll.c to add foundations for flatscroll bars

Andrew M. Johnston johnstonam at logica.com
Fri Oct 4 00:59:49 CDT 2002


So that code is not duplicated when flat scroll bar functionality is introduced,
the large number of draw functions and the somewhat convoluted control path in
scrollbar.c have been cleaned up.

The clean up rewrites the whole scrollbar.c file.  The main changes are that all the 
drawing state data such as thumbpos, thumb size etc has been moved into a single
stucture SCROLL_BAR.

During tracking the scrollbar structure is calculated once and then reused for all
events on this bar until tracking stops.  The bar structure is written so that both
horizontal and vertical bars can appear identical to the draw routines.

In all these changes remove about 25% of the code in scrolbar.c.  The code has been
tested on Win31 and Win95/98 emulation I have not been able to find an example of
an SB_CTL bar so it may still have bugs for these types of scroll bars.

The re-oganisation has allowed bugs with moving off arrows with the mouse button
pressed to be addressed and fixed.

As far as I can tell the implementation does the minimum amount of drawing necessary.
It stops producing timer events and makes mouse move event processing very slick when
off the bar (but still able to come back on to the bar as is allowed with SB_LINEUP
and SB_LINEDOWN hits).

I was not able to get the capture release to work as I hoped when moving way outside the control
but I suspect the bug is not in the scroll bar code but elsewhere (nonclient). 
The code that attempts this is not present here but it is relatively easy to see where it goes.

The functions have been documented in the code.

I have used this code to implement flat scroll bars in two ways however I run into problems
and I am looking for advice.

Solution 1:  Expose the SCROLL_GetScrollInfo function to the comcntl dll.  This does not seem
             wise in terms of Dll separation but means that only two fucntions in flatsb need
             to be written.  This method gets rid of the need for special flatsb structure
             and all the initialisation code etc.
             The problem is how to expose the SCROLL_GetScrollInfo function.

Solution 2:  Make the flatSB functions set and restore all the system properties effecting
             scroll bars at the begining and end of each flatsb call respectively.  This method
             requires all the intialisation code and a flat sb structure. 
             The problem is I cannot find a WINAPI function for setting system parameters.
             There is some indication in MSDN that the SystemInfo function can be usd for this
             but intialial investigations suggest that the orginal cmctrl does not do this

Solution 3:  Send a message to the scroll bar.  This is the method implemented here so that 
             I could test some of the FlatSB properites but I do not think it is how windows
             implements this functionality since I cannot find the message concerned 

Any suggestions on approach will be useful.

Changelog:
            controls.h  - improve the scroll bar nonclient separation
            nonclient.c - remove NC_TrackScrollBar and use scrollbar WINAPI routine
            scrollbar.c - complete rewrite using similar structure and logic
                        - unified drawing code
                        - simpler event processing logic
                        - minimised drawing
                        - better conformance to windows on LINEUP and LINEDOWN events

The patch was deleveloped without CVS access use patch -p1 from within
the top level wine directory to apply

Note: it is possible to split the scroll changes up into three consistent parts if
really necessary

Requires mdi.patch

Licence: X11

Andrew.

--- wine-20020804/dlls/user/controls.h	Sun Mar 10 07:44:30 2002
+++ wine/dlls/user/controls.h	Thu Sep 19 18:22:23 2002
@@ -63,10 +63,8 @@
 extern UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget );
 
 /* scrollbar */
-extern void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar, BOOL arrows, BOOL interior );
-extern void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt );
-extern INT SCROLL_SetNCSbState( HWND hwnd, int vMin, int vMax, int vPos,
-                                int hMin, int hMax, int hPos );
+extern void SCROLL_PaintScrollBar(HWND hwnd, INT nBar);
+extern void SCROLL_HandleScrollEvent(HWND hwnd, INT nBar, UINT msg, LPARAM lParam);
 
 /* combo box */

--- wine-20020804/windows/nonclient.c	Sat Jun  1 07:06:54 2002
+++ wine/windows/nonclient.c	Fri Sep 20 12:22:16 2002
@@ -1459,9 +1459,9 @@
       /* Draw the scroll-bars */
 
     if (dwStyle & WS_VSCROLL)
-        SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
+        SCROLL_PaintScrollBar(hwnd, SB_VERT);
     if (dwStyle & WS_HSCROLL)
-        SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
+        SCROLL_PaintScrollBar(hwnd, SB_HORZ);
 
       /* Draw the "size-box" */
 
@@ -1613,12 +1613,9 @@
 	DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
 
     /* Draw the scroll-bars */
-
-    if (dwStyle & WS_VSCROLL)
-        SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
-    if (dwStyle & WS_HSCROLL)
-        SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
-
+    if (dwStyle & WS_VSCROLL) SCROLL_PaintScrollBar(hwnd, SB_VERT);
+    if (dwStyle & WS_HSCROLL) SCROLL_PaintScrollBar(hwnd, SB_HORZ);
+                                           
     /* Draw the "size-box" */
     if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
     {
@@ -1649,7 +1646,7 @@
 	    WINPOS_RedrawIconTitle( hwnd );
 	else if (TWEAK_WineLook == WIN31_LOOK)
 	    NC_DoNCPaint( hwnd, clip, FALSE );
-	else
+ 	else
 	    NC_DoNCPaint95( hwnd, clip, FALSE );
     }
     return 0;
@@ -1962,29 +1959,6 @@
 
 
 /***********************************************************************
- *           NC_TrackScrollBar
- *
- * Track a mouse button press on the horizontal or vertical scroll-bar.
- */
-static void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt )
-{
-    INT scrollbar;
-
-    if ((wParam & 0xfff0) == SC_HSCROLL)
-    {
-        if ((wParam & 0x0f) != HTHSCROLL) return;
-	scrollbar = SB_HORZ;
-    }
-    else  /* SC_VSCROLL */
-    {
-        if ((wParam & 0x0f) != HTVSCROLL) return;
-	scrollbar = SB_VERT;
-    }
-    SCROLL_TrackScrollBar( hwnd, scrollbar, pt );
-}
-
-
-/***********************************************************************
  *           NC_HandleNCLButtonDown
  *
  * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
@@ -2146,14 +2120,14 @@
 	return SendMessageA( hwnd, WM_CLOSE, 0, 0 );
 
     case SC_VSCROLL:
+    	if ((wParam & 0x0f) == HTVSCROLL)
+    		SCROLL_HandleScrollEvent(hwnd, SB_VERT, WM_LBUTTONDOWN, lParam);
+    	break;
+ 
     case SC_HSCROLL:
-        {
-            POINT pt;
-            pt.x = SLOWORD(lParam);
-            pt.y = SHIWORD(lParam);
-            NC_TrackScrollBar( hwnd, wParam, pt );
-        }
-	break;
+        if ((wParam & 0x0f) == HTHSCROLL)
+        	SCROLL_HandleScrollEvent(hwnd, SB_HORZ, WM_LBUTTONDOWN, lParam);
+       	break;
 
     case SC_MOUSEMENU:
         {
--- wine-20020904/controls/scroll.c	Sat Aug  3 08:13:48 2002
+++ wine/controls/scroll.c	Fri Oct  4 12:31:54 2002
@@ -3,6 +3,7 @@
  *
  * Copyright 1993 Martin Ayotte
  * Copyright 1994, 1996 Alexandre Julliard
+ * Copyright 2002 Andrew Johnston
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,6 +24,7 @@
 #include "wingdi.h"
 #include "wine/winuser16.h"
 #include "controls.h"
+#include "commctrl.h"
 #include "win.h"
 #include "wine/debug.h"
 #include "user.h"
@@ -30,850 +32,948 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
 
+/*********************************************************************
+ *
+ *  Flat scroll bar properties are updated through a message from the 
+ * comctl non all the properties are used properly
+ * thumb, arrow will work but style, backgound and bredth will not
+ * bredth needs the notification to go to the Non client control.
+ * Palette is in the code but not activated as the initial condition
+ * needs to be thought through.
+ * 
+ * There are three ways that could be used for flat scroll bars
+ * 
+ * 1) Expose SCROLL_INFO to the flat scroll bar in some fassion
+ * 2) Work out how to use SystemInfo to set scroll properties
+ *    Manipulate scroll bars poperties before and after each call
+ *    to a scroll function in flatSB
+ * 3) Send a message to the scroll bar.
+ *
+ * Although this solution uses method 3 (which is wrong). 
+ * The windows messages used to comunicate the properties to the scroll
+ * bar are not the ones windows uses and are wrong.
+ *
+ * Windows probably uses something like 2.  However investigations
+ * indicate the it does not use SetSystemProperty. (Based on the fact
+ * that native comctl flatSB when used will call these routines)
+ */
+
+/*********************************************************************
+ * scrollbar state
+ * 
+ *  Lives as long as the scroll bar
+ */
 typedef struct
 {
-    INT   CurVal;   /* Current scroll-bar value */
-    INT   MinVal;   /* Minimum scroll-bar value */
-    INT   MaxVal;   /* Maximum scroll-bar value */
-    INT   Page;     /* Page size of scroll bar (Win32) */
-    UINT  flags;    /* EnableScrollBar flags */
-} SCROLLBAR_INFO;
-
-
-static HBITMAP hUpArrow;
-static HBITMAP hDnArrow;
-static HBITMAP hLfArrow;
-static HBITMAP hRgArrow;
-static HBITMAP hUpArrowD;
-static HBITMAP hDnArrowD;
-static HBITMAP hLfArrowD;
-static HBITMAP hRgArrowD;
-static HBITMAP hUpArrowI;
-static HBITMAP hDnArrowI;
-static HBITMAP hLfArrowI;
-static HBITMAP hRgArrowI;
-
-#define TOP_ARROW(flags,pressed) \
-   (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
-#define BOTTOM_ARROW(flags,pressed) \
-   (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
-#define LEFT_ARROW(flags,pressed) \
-   (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
-#define RIGHT_ARROW(flags,pressed) \
-   (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
-
-
-  /* Minimum size of the rectangle between the arrows */
-#define SCROLL_MIN_RECT  4
-
-  /* Minimum size of the thumb in pixels */
-#define SCROLL_MIN_THUMB 6
-
-  /* Overlap between arrows and thumb */
-#define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
-
-  /* Delay (in ms) before first repetition when holding the button down */
-#define SCROLL_FIRST_DELAY   200
-
-  /* Delay (in ms) between scroll repetitions */
-#define SCROLL_REPEAT_DELAY  50
-
-  /* Scroll timer id */
-#define SCROLL_TIMER   0
-
-  /* Scroll-bar hit testing */
-enum SCROLL_HITTEST
-{
-    SCROLL_NOWHERE,      /* Outside the scroll bar */
-    SCROLL_TOP_ARROW,    /* Top or left arrow */
-    SCROLL_TOP_RECT,     /* Rectangle between the top arrow and the thumb */
-    SCROLL_THUMB,        /* Thumb rectangle */
-    SCROLL_BOTTOM_RECT,  /* Rectangle between the thumb and the bottom arrow */
-    SCROLL_BOTTOM_ARROW  /* Bottom or right arrow */
-};
+	INT curVal;            /* Current scroll-bar value */
+	INT minVal;            /* Minimum scroll-bar value */
+	INT maxVal;            /* Maximum scroll-bar value */
+	INT page;              /* Page size of scroll bar (Win32) */
+	INT bredth;            /* The short dimension of the scroll bar (FlatSB) */
+	INT arrow;             /* Arrow size (FlatSB)*/
+	INT thumb;             /* Thumb size (FlatSB)*/
+	INT style;             /* Scroll bar style (FlatSB)*/
+	UINT flags;            /* EnableScrollBar flags */
+	COLORREF background;   /* Scroll bar background color (FlatSB) */
+	HPALETTE palette;      /* The palette to use (FlatSB) */
+} SCROLL_INFO, *LPSCROLL_INFO;
+
 
- /* What to do after SCROLL_SetScrollInfo() */
-#define SA_SSI_HIDE		0x0001
-#define SA_SSI_SHOW		0x0002
-#define SA_SSI_REFRESH		0x0004
-#define SA_SSI_REPAINT_ARROWS	0x0008
-
- /* Thumb-tracking info */
-static HWND SCROLL_TrackingWin = 0;
-static INT  SCROLL_TrackingBar = 0;
-static INT  SCROLL_TrackingPos = 0;
-static INT  SCROLL_TrackingVal = 0;
- /* Hit test code of the last button-down event */
-static enum SCROLL_HITTEST SCROLL_trackHitTest;
-static BOOL SCROLL_trackVertical;
-
- /* Is the moving thumb being displayed? */
-static BOOL SCROLL_MovingThumb = FALSE;
-
- /* Local functions */
-static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
-				    BOOL fShowH, BOOL fShowV );
-static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
-				   const SCROLLINFO *info, INT *action );
-static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
-				    RECT *rect, INT arrowSize,
-				    INT thumbSize, INT thumbPos,
-				    UINT flags, BOOL vertical,
-				    BOOL top_selected, BOOL bottom_selected );
-static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
+/*********************************************************************
+ * scrollbar arrow states
+ * 
+ *  Used in 3.1 mode for arrow images
+ */
+typedef struct
+{
+	HBITMAP normal;        /* arrow for normal state (unpressed) */
+	HBITMAP pressed;       /* arrow for pressed state */
+	HBITMAP disabled;      /* arrow for disabled state */
+} SCROLL_ARROWS, *LPSCROLL_ARROWS;
 
 
 /*********************************************************************
- * scrollbar class descriptor
+ * scrollbar extermity parameters (one arrow)
+ *
+ *  Contains the arrow and its pressed state and the associated
+ *  limiting cordinate
  */
-const struct builtin_class_descr SCROLL_builtin_class =
+typedef struct
 {
-    "ScrollBar",            /* name */
-    CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style  */
-    NULL,                   /* procA (winproc is Unicode only) */
-    ScrollBarWndProc,       /* procW */
-    sizeof(SCROLLBAR_INFO), /* extra */
-    IDC_ARROWA,             /* cursor */
-    0                       /* brush */
-};
+	INT *coord;            /* coordinate of the limiting extremity */
+	INT flags;             /* pressed state of the extermity */
+	LPSCROLL_ARROWS	arrow; /* arrows collection */
+} SCROLL_EXTEMITY, *LPSCROLL_EXTREMITY;
+
+
+/*********************************************************************
+ * scrollbar (display information for drawing a single scroll bar)
+ * 
+ *  Lives as long as a scroll draw operation
+ */
+typedef struct
+{
+	RECT rect;             /* the bounding rectangle of the control */
+	RECT extended;         /* the bounding rectangle thumb movement */
+	UINT hit;              /* windows message for bar position */
+	INT arrow;             /* the arrow size */
+	INT thumb;             /* the thumb size */
+	INT pos;               /* the thumb postion */
+	INT pixels;            /* length of the long dimension of the bar */
+	INT direction;         /* windows message for bar direction */
+	BOOL drawable;         /* scroll bar is a non empty rect */
+	BOOL inside;           /* event was inside scroll bar */
+	BOOL lastInside;       /* last event was inside scroll bar */
+	POINT offset;          /* offset of the scrollbar in the client window */
+	SCROLL_EXTEMITY start; /* the start of the long extent of the bar */
+	SCROLL_EXTEMITY end;   /* the end of the long extent of the bar */
+	LPSCROLL_INFO info;    /* the info for the scroll bar */
+} SCROLL_BAR, *LPSCROLL_BAR;
+
+#define SCROLL_MIN_RECT       4	/* Minimum size of rectangle between arrows */
+#define SCROLL_MIN_THUMB      6	/* Minimum size of the thumb in pixels */
+#define SCROLL_FIRST_DELAY  200	/* Delay (in ms) before first repetition */
+#define SCROLL_REPEAT_DELAY  50	/* Delay (in ms) between scroll repetitions */
+#define SCROLL_TIMER          0	/* Scroll timer id */
+#define SCROLL_NO_POS (1 << 30)	/* Dummy value for unkown thumb position */
+
+#define SCROLL_HORIZONTAL_MASK (\
+	WSB_PROP_CXHSCROLL | \
+	WSB_PROP_CYHSCROLL | \
+	WSB_PROP_CXHTHUMB | \
+	WSB_PROP_HBKGCOLOR | \
+	WSB_PROP_HSTYLE | \
+	WSB_PROP_PALETTE )
+
+#define SCROLL_VERTICAL_MASK (\
+	WSB_PROP_CYVSCROLL | \
+	WSB_PROP_CXVSCROLL | \
+	WSB_PROP_CYVTHUMB | \
+	WSB_PROP_VBKGCOLOR | \
+	WSB_PROP_VSTYLE | \
+	WSB_PROP_PALETTE )
+
+#define SCROLL_SetProp(prop) \
+	if (prop != newValue) prop = newValue;  break;
+
+/* Determine if the whole bar is disabled */
+#define SCROLL_DISABLED(info) \
+	((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
+
+/* Determine if the bar has been hit inside and in the given position */
+#define SCROLL_HIT(bar, position) \
+	((bar->inside) && (bar->hit == position))
+
+/* Determine the correct pattern for the fill based on pressed state */
+#define SCROLL_PATTERN(bar, position) \
+	((SCROLL_HIT(bar, position)) ? 0x0f0000 : PATCOPY)
+
+/* Determine if the scroll bar has changed */
+#define SCROLL_CHANGED(bar) ((bar)->inside != (bar)->lastInside)
+
+/* Determine if the arrow should be drawn and call to draw it */
+#define SCROLL_DRAW_ARROW(hdc, bar, arr, current, other) \
+	if (bar->info->arrow && SCROLL_CHANGED(bar) && \
+		((bar->inside && bar->hit != other) || (bar->hit == current))) \
+			SCROLL_DrawArrow(hdc, &(bar->rect), arr, SCROLL_HIT(bar, current));
+
+/* Determine if the info is valid */
+#define SCROLL_INFO_INVALID(info) \
+	((info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) || \
+	((info->cbSize != sizeof(*info)) && \
+	(info->cbSize != sizeof(*info) - sizeof(info->nTrackPos))))
+
+
+/*********************************************************************
+ * scrollbar arrow collections (used by Win 31 only)
+ */
+static SCROLL_ARROWS hUp;    /* Arrow images for up arrow */
+static SCROLL_ARROWS hDown;  /* Arrow images for down arrow */
+static SCROLL_ARROWS hLeft;  /* Arrow images for left arrow */
+static SCROLL_ARROWS hRight; /* Arrow images for right arrow */
+
+static SCROLL_BAR trackBar; /* The bar structure used during tracking */
 
 
 /***********************************************************************
- *           SCROLL_LoadBitmaps
+ *           SCROLL_GetInfo
+ *  
+ *  Obtains a valid info pointer for the requested bar
+ *  (creates structure when required)
+ *           
+ * RETURNS
+ *   Pointer to a scroll info structure
  */
-static void SCROLL_LoadBitmaps(void)
+static SCROLL_INFO *SCROLL_GetInfo(
+SCROLL_INFO **info /* [in/out] Potentially the scroll info pointer */)
 {
-    hUpArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
-    hDnArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
-    hLfArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
-    hRgArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
-    hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
-    hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
-    hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
-    hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
-    hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
-    hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
-    hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
-    hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
+	if (!(*info) && (*info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCROLL_INFO))))
+	{
+		(*info)->minVal = (*info)->curVal = (*info)->page = 0;
+		(*info)->maxVal = 100;
+		(*info)->flags  = ESB_ENABLE_BOTH;
+		(*info)->bredth = GetSystemMetrics(SM_CXVSCROLL);
+		(*info)->thumb = GetSystemMetrics(SM_CYHSCROLL);
+		(*info)->arrow = GetSystemMetrics(SM_CYHSCROLL);
+		(*info)->page = 0;
+	}
+	return *info;
 }
 
 
 /***********************************************************************
  *           SCROLL_GetScrollInfo
+ *
+ * Get the scoll info structure for the scroll bar
+ * 
+ * RETURNS
+ *  Scroll info pointer
  */
-static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar )
+LPSCROLL_INFO SCROLL_GetScrollInfo(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */)
 {
-    SCROLLBAR_INFO *infoPtr;
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
+	WND *wnd = WIN_FindWndPtr(hwnd);
+	LPSCROLL_INFO info = 0;
 
-    if (!wndPtr) return NULL;
-    switch(nBar)
-    {
-        case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
-        case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
-        case SB_CTL:  infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
-        default:
-            WIN_ReleaseWndPtr( wndPtr );
-            return NULL;
-    }
-
-    if (!infoPtr)  /* Create the info structure if needed */
-    {
-        if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
-        {
-            infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
-            infoPtr->MaxVal = 100;
-            infoPtr->flags  = ESB_ENABLE_BOTH;
-            if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
-            else wndPtr->pVScroll = infoPtr;
-        }
-        if (!hUpArrow) SCROLL_LoadBitmaps();
-    }
-    WIN_ReleaseWndPtr( wndPtr );
-    return infoPtr;
+	if (wnd)
+	{
+		switch (nBar)
+		{
+		case SB_HORZ: info = SCROLL_GetInfo((SCROLL_INFO **)&(wnd->pHScroll)); break;
+		case SB_VERT: info = SCROLL_GetInfo((SCROLL_INFO **)&(wnd->pVScroll)); break;
+		case SB_CTL:  info = SCROLL_GetInfo((SCROLL_INFO **)&(wnd->wExtra)); break;
+		default: ERR("Unhandled scroll bar type\n"); break;
+		}
+		WIN_ReleasePtr(wnd);
+	}
+
+	return info;
 }
 
 
 /***********************************************************************
- *           SCROLL_GetScrollBarRect
+ *           SCROLL_GetThumb
+ *
+ *  Determine the critical sizes and positions of arrows and thumb given
+ *  the bar properties including sizes desired places etc
+ *  
+ * RETURNS
+ *   bar->arrow size the arrow (width or height depending on orientation)
+ *   bar->thumb size of the thumb
+ *   bar->pos position of the thumb (relative to the left or top arrow)
+ * and
+ *   return the proposed new curVal for the scroll bar
+ */
+static UINT SCROLL_GetThumb(
+INT scrollPos /* [in] current or desired scroll position */,
+LPSCROLL_BAR bar /* [in/out] size and position of the bar components */)
+{
+	INT range = bar->info->maxVal - bar->info->minVal;
+	INT pixels = bar->pixels;
+	UINT curVal = 0;
+
+	/* set the default return values */
+	bar->pos = bar->arrow = bar->thumb = 0;
+	 
+	if (pixels > SCROLL_MIN_RECT + bar->info->arrow * 2)
+	{
+		/* set bar display properties */
+		bar->arrow = bar->info->arrow;
+
+		/* using only the non arrow pixels */
+		pixels -= 2 * bar->arrow;
+
+		/* set thumb size */       
+		if (bar->info->page)
+			bar->thumb = MulDiv(pixels, bar->info->page, range + 1);
+		else
+			bar->thumb = bar->info->thumb;
+
+		/* check thumb not too small */
+		if (bar->thumb < SCROLL_MIN_THUMB)
+			bar->thumb = SCROLL_MIN_THUMB;
+
+		/* scroll bar size ok and enabled */
+		range -= bar->info->page - 1;
+		pixels -= bar->thumb;
+
+		/* move thumb */
+		if ((pixels <= 0) || SCROLL_DISABLED(bar->info))
+			 bar->thumb = 0;
+		else if (scrollPos != SCROLL_NO_POS)
+		{
+			/* make the pos reasonable then calculate curVal */
+			if (scrollPos < 0) scrollPos = 0;
+			else if (scrollPos > pixels) scrollPos = pixels;
+			bar->pos = scrollPos;
+			curVal = MulDiv(range, scrollPos, pixels);
+		}
+		else if (range > 0)
+		{
+			/* use curVal to determine bar position */
+			curVal = bar->info->curVal - bar->info->minVal;
+			bar->pos = MulDiv(pixels, curVal, range);
+		}
+	}
+	else if (pixels > SCROLL_MIN_RECT)
+		bar->arrow = (pixels - SCROLL_MIN_RECT) / 2;
+
+	curVal += bar->info->minVal;
+	TRACE("pixels=%d pos=%d thumb=%d curVal=%d range=%d\n",
+		bar->pixels, bar->pos, bar->thumb, curVal, range);
+
+	return curVal;
+}
+
+
+/***********************************************************************
+ *           SCROLL_GetScrollBar
  *
  * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
  * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
- * 'arrowSize' returns the width or height of an arrow (depending on
- * the orientation of the scrollbar), 'thumbSize' returns the size of
- * the thumb, and 'thumbPos' returns the position of the thumb
- * relative to the left or to the top.
- * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
- */
-static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
-                                       INT *arrowSize, INT *thumbSize,
-                                       INT *thumbPos )
-{
-    INT pixels;
-    BOOL vertical;
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
-
-    switch(nBar)
-    {
-      case SB_HORZ:
-        lprect->left   = wndPtr->rectClient.left - wndPtr->rectWindow.left;
-        lprect->top    = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
-        lprect->right  = wndPtr->rectClient.right - wndPtr->rectWindow.left;
-        lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
-	if(wndPtr->dwStyle & WS_BORDER) {
-	  lprect->left--;
-	  lprect->right++;
-	} else if(wndPtr->dwStyle & WS_VSCROLL)
-	  lprect->right++;
-        vertical = FALSE;
-	break;
-
-      case SB_VERT:
-        lprect->left   = wndPtr->rectClient.right - wndPtr->rectWindow.left;
-        lprect->top    = wndPtr->rectClient.top - wndPtr->rectWindow.top;
-        lprect->right  = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
-        lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
-	if(wndPtr->dwStyle & WS_BORDER) {
-	  lprect->top--;
-	  lprect->bottom++;
-	} else if(wndPtr->dwStyle & WS_HSCROLL)
-	  lprect->bottom++;
-        vertical = TRUE;
-	break;
-
-      case SB_CTL:
-	GetClientRect( hwnd, lprect );
-        vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
-	break;
-
-    default:
-        WIN_ReleaseWndPtr(wndPtr);
-        return FALSE;
-    }
-
-    if (vertical) pixels = lprect->bottom - lprect->top;
-    else pixels = lprect->right - lprect->left;
-
-    if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
-    {
-        if (pixels > SCROLL_MIN_RECT)
-            *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
-        else
-            *arrowSize = 0;
-        *thumbPos = *thumbSize = 0;
-    }
-    else
-    {
-        SCROLLBAR_INFO *info = SCROLL_GetScrollInfo( hwnd, nBar );
-
-        *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
-        pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
-
-        if (info->Page)
-        {
-	    *thumbSize = MulDiv(pixels,info->Page,(info->MaxVal-info->MinVal+1));
-            if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
-        }
-        else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
-
-        if (((pixels -= *thumbSize ) < 0) ||
-            ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
-        {
-            /* Rectangle too small or scrollbar disabled -> no thumb */
-            *thumbPos = *thumbSize = 0;
-        }
-        else
-        {
-            INT max = info->MaxVal - max( info->Page-1, 0 );
-            if (info->MinVal >= max)
-                *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-            else
-                *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
-		  + MulDiv(pixels, (info->CurVal-info->MinVal),(max - info->MinVal));
-        }
-    }
-    WIN_ReleaseWndPtr(wndPtr);
-    return vertical;
+ * 
+ * RETURNS
+ *  The scroll bar structure
+ */
+static BOOL SCROLL_GetScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+LPSCROLL_INFO info /* [in] The place of the thumb */,
+LPSCROLL_BAR bar /* [out] The bar positions and charactersistics */)
+{
+	INT *from, *to;
+	BOOL vertical = FALSE;
+	WND *wnd = WIN_FindWndPtr(hwnd);
+
+	TRACE("hwnd=%04x nBar=%d info=%p bar=%p\n", hwnd, nBar, info, bar);
+
+	/* set common state */
+	bar->info = info;
+	bar->inside = TRUE;
+	bar->lastInside = FALSE;
+	bar->hit = SB_THUMBPOSITION;
+	bar->extended = wnd->rectClient;
+	bar->offset.x = bar->offset.y = 0;
+	bar->start.flags = (info->flags & ESB_DISABLE_LTUP) ? DFCS_INACTIVE : 0;
+	bar->end.flags = (info->flags & ESB_DISABLE_RTDN) ? DFCS_INACTIVE : 0;
+
+	/* Set the orientation */
+	if (!wnd) return vertical;
+	vertical = (nBar == SB_VERT) ||
+		((nBar == SB_CTL) && (wnd->dwStyle & SBS_VERT));
+	if (vertical)
+	{
+		/* Fill in the bar properites for vertical scroll bars */
+		bar->drawable = wnd->dwStyle & WS_VSCROLL;
+		bar->direction = WM_VSCROLL;
+		bar->start.coord = &(bar->rect.top);
+		bar->start.flags |= DFCS_SCROLLUP;
+		bar->start.arrow = &hUp;
+		bar->end.coord = &(bar->rect.bottom);
+		bar->end.flags |= DFCS_SCROLLDOWN;
+		bar->end.arrow = &hDown;
+		from = &(bar->extended.left);
+		to = &(bar->extended.right);
+	}
+	else
+	{
+		/* Fill in the bar properites for horizontal scroll bars */
+		bar->drawable = wnd->dwStyle & WS_HSCROLL;
+		bar->direction = WM_HSCROLL;
+		bar->start.coord = &(bar->rect.left);
+		bar->start.flags |= DFCS_SCROLLLEFT;
+		bar->start.arrow = &hLeft;
+		bar->end.coord = &(bar->rect.right);
+		bar->end.flags |= DFCS_SCROLLRIGHT;
+		bar->end.arrow = &hRight;
+		from = &(bar->extended.top);
+		to = &(bar->extended.bottom);
+	}
+
+	/* Get the client rect */
+	if (nBar != SB_CTL)
+	{
+		/* Set the offset used convert tracking to client coordinates */
+		OffsetRect(&(bar->extended), -wnd->rectWindow.left, -wnd->rectWindow.top);
+		bar->offset.x = bar->extended.left;
+		bar->offset.y = bar->extended.top;
+
+		/* Move rectangle to edge */
+		*from = *to;
+		*to += bar->info->bredth;
+		bar->rect = bar->extended;
+
+		/* Adjust the size based on window style */
+		if (wnd->dwStyle & (WS_BORDER | WS_VSCROLL))
+			(*(bar->end.coord))++;
+		if (wnd->dwStyle & WS_BORDER)
+			(*(bar->start.coord))--;
+	}
+	else
+		bar->rect = bar->extended;
+
+	/* handle the extended rect used in thumb tracking */
+	*from -= bar->info->bredth;
+	*to += bar->info->bredth;
+	WIN_ReleasePtr(wnd);
+
+	/* Get the positions of the pieces and update the draw state */
+	bar->drawable = bar->drawable && !(IsRectEmpty(&(bar->rect)));
+	bar->pixels = *(bar->end.coord) - *(bar->start.coord);
+	SCROLL_GetThumb(SCROLL_NO_POS, bar);
+
+	return vertical;
+}
+
+
+/***********************************************************************
+ *           SCROLL_LoadBitmaps
+ *
+ * Setup the arrow collections.
+ *
+ * NOTE:
+ *   Should be called in a libary set up phase rather than SCROLL_DrawArrow
+ *   Also if the OEM numbers follow a matmatical pattern it can be made neater
+ *   Currently called once in Win31 emulating ifand a scroll bar arrow is draw
+ */
+static void SCROLL_LoadBitmaps(void)
+{
+	hUp.normal      = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_UPARROW));
+	hUp.pressed     = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_UPARROWD));
+	hUp.disabled    = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_UPARROWI));
+
+	hDown.normal    = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_DNARROW));
+	hDown.pressed   = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_DNARROWD));
+	hDown.disabled  = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_DNARROWI));
+
+	hLeft.normal    = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_LFARROW));
+	hLeft.pressed   = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_LFARROWD));
+	hLeft.disabled  = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_LFARROWI));
+
+	hRight.normal   = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RGARROW));
+	hRight.pressed  = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RGARROWD));
+	hRight.disabled = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RGARROWI));
 }
 
 
 /***********************************************************************
- *           SCROLL_GetThumbVal
+ *           SCROLL_DrawArrow
  *
- * Compute the current scroll position based on the thumb position in pixels
- * from the top of the scroll-bar.
+ * Draw a scroll bar arrow in the needed active and pressed state.
  */
-static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
-                                  BOOL vertical, INT pos )
+static void SCROLL_DrawArrow(
+HDC hdc /* [in] the drawing control */,
+LPRECT rect /* [in] the rectangle to contain the arrow */,
+LPSCROLL_EXTREMITY extremity /* [in] the extremity for the arrow */,
+BOOL pushed /* Indicates is the button is to be shown in its pushed state */)
 {
-    INT thumbSize;
-    INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
+	if (extremity->flags & DFCS_TRANSPARENT) return;
 
-    if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
-        return infoPtr->MinVal;
+	TRACE("hdc=%04x rect=%p extremity=%p pushed=%d\n",
+		hdc, rect, extremity, pushed);
 
-    if (infoPtr->Page)
-    {
-        thumbSize = MulDiv(pixels,infoPtr->Page,(infoPtr->MaxVal-infoPtr->MinVal+1));
-        if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
-    }
-    else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
+	/* clear or set pessed states */
+	if (pushed)
+		extremity->flags |= (DFCS_PUSHED | DFCS_FLAT);
+	else
+		extremity->flags &= ~(DFCS_PUSHED | DFCS_FLAT);
 
-    if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
+	if (TWEAK_WineLook != WIN31_LOOK)
+		DrawFrameControl(hdc, rect, DFC_SCROLL, extremity->flags);
+	else
+	{
+		HDC hdcMem = CreateCompatibleDC(hdc);
+		HBITMAP hbmpPrev;
 
-    pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
-    if (pos > pixels) pos = pixels;
+		/* load bitmask if not done yet */
+		if (!hUp.normal) SCROLL_LoadBitmaps();
 
-    if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
-    else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1;
-    return infoPtr->MinVal + ((pos + pixels / 2) / pixels);
+		/* draw the arrow from the image */
+		hbmpPrev = SelectObject(hdcMem, 
+			(extremity->flags & DFCS_INACTIVE) ? extremity->arrow->disabled :
+				((extremity->flags & DFCS_PUSHED) ? extremity->arrow->pressed :
+					extremity->arrow->normal));
+		SetStretchBltMode(hdc, STRETCH_DELETESCANS);
+		StretchBlt(hdc, rect->left, rect->top, rect->right - rect->left,
+			rect->bottom - rect->top, hdcMem, 0, 0,
+				GetSystemMetrics(SM_CXVSCROLL),
+					GetSystemMetrics(SM_CYHSCROLL), SRCCOPY);                  
+		SelectObject(hdcMem, hbmpPrev);
+		DeleteDC(hdcMem);
+	}
 }
 
-/***********************************************************************
- *           SCROLL_PtInRectEx
+
+/*************************************************************************
+ *           SCROLL_DrawScrollBar 
  */
-static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
-{
-    RECT rect = *lpRect;
+static void SCROLL_DrawScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+LPSCROLL_BAR bar /* [in] The place of the thumb */)
+{
+	HPEN hSavePen;
+	HBRUSH hSaveBrush;
+	HPALETTE hSavePalette;
+	INT end = *(bar->end.coord);
+	INT start = *(bar->start.coord);
+	HDC hdc = GetDCEx(hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW)); 
+	if (!hdc) return;
+
+	/* select the correct brush and pen */
+	hSavePen = SelectObject(hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
+	if (TWEAK_WineLook == WIN31_LOOK && SCROLL_DISABLED(bar->info))
+		/* this ought to be the color of the parent window */
+		hSaveBrush = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
+	else if (nBar == SB_CTL) 
+		/* only scrollbar controls send WM_CTLCOLORSCROLLBAR. */
+		hSaveBrush = SelectObject(hdc,(HBRUSH)SendMessageA(GetParent(hwnd), 
+			WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)hwnd));
+	else
+		/* the window-owned scrollbars use DEFWND_ControlColor
+		 * (to set default scroll bar colours) */
+		hSaveBrush = SelectObject(hdc,
+			DEFWND_ControlColor(hdc, CTLCOLOR_SCROLLBAR));
+
+	/* save the palette */
+/*	hSavePalette = SelectObject(hdc, bar->palette); */
+
+	/* draw the end arrow at the end */
+	*(bar->start.coord) = *(bar->end.coord) - bar->arrow;
+	SCROLL_DRAW_ARROW(hdc, bar, &(bar->end), SB_LINEDOWN, SB_LINEUP);
+	*(bar->start.coord) = start;       
+
+	/* draw the start arrow at the start */
+	*(bar->end.coord) = *(bar->start.coord) + bar->arrow;
+	SCROLL_DRAW_ARROW(hdc, bar, &(bar->start), SB_LINEUP, SB_LINEDOWN);
+	*(bar->end.coord) = end;
 
-    if (vertical)
-    {
-	rect.left -= lpRect->right - lpRect->left;
-	rect.right += lpRect->right - lpRect->left;
-    }
-    else
-    {
-	rect.top -= lpRect->bottom - lpRect->top;
-	rect.bottom += lpRect->bottom - lpRect->top;
-    }
-    return PtInRect( &rect, pt );
+	/* draw the interior if needed */
+	if (!SCROLL_CHANGED(bar) || (bar->hit != SB_LINEUP && bar->hit != SB_LINEDOWN))
+	{
+		TRACE("hwnd=%04x nBar=%d\n", hwnd, nBar);
+
+		/* resize the arrows out of the scroll rectangle */
+		*(bar->start.coord) += bar->arrow;
+		*(bar->end.coord) -= bar->arrow;
+ 
+		/* draw outline only if Win 3.1.  Mar 24, 1999 - Ronald B. Cemer */
+		if (TWEAK_WineLook == WIN31_LOOK)
+		{
+			Rectangle(hdc, bar->rect.left, bar->rect.top, 
+				bar->rect.right, bar->rect.bottom);
+
+			/* Confine the drawing rect to inside the previous rectangle */
+			bar->rect.top++, bar->rect.left++, (*(bar->start.coord))--;
+			bar->rect.bottom--, bar->rect.right--, (*(bar->end.coord))++;
+		}
+
+		/* draw a first rect and thumb */
+		if (bar->thumb)
+		{
+			INT temp = *(bar->end.coord);
+			HBRUSH hSaveBrushThumb;
+
+			/* draw first rect */
+			*(bar->end.coord) = *(bar->start.coord) + bar->pos;
+			PatBlt(hdc, bar->rect.left, bar->rect.top,
+				bar->rect.right - bar->rect.left, bar->rect.bottom - bar->rect.top,
+					SCROLL_PATTERN(bar, SB_PAGEUP));
+			*(bar->start.coord) = *(bar->end.coord);
+
+			/* draw thumb */
+			*(bar->end.coord) = *(bar->start.coord) + bar->thumb;
+			hSaveBrushThumb = SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE));
+			Rectangle(hdc, bar->rect.left, bar->rect.top,
+				bar->rect.right, bar->rect.bottom);
+			DrawEdge(hdc, &(bar->rect), EDGE_RAISED , BF_RECT); /* | BF_MIDDLE */
+			SelectObject(hdc, hSaveBrushThumb);
+
+			/* if scroll bar has focus, reposition the caret */
+			if ((hwnd == GetFocus()) && (nBar == SB_CTL))
+				SetCaretPos(bar->rect.left + 1, bar->rect.top + 1);
+
+			/* restore rect for next drawing operation */
+			*(bar->start.coord) = *(bar->end.coord);
+			*(bar->end.coord) = temp;
+		} /* thumb to be drawn */
+
+		/* draw last and only rect when no thumb is to be drawn */
+		PatBlt( hdc, bar->rect.left, bar->rect.top,
+			bar->rect.right - bar->rect.left, bar->rect.bottom - bar->rect.top,
+				SCROLL_PATTERN(bar, SB_PAGEDOWN));
+       
+		/* cleanup */
+		if (TWEAK_WineLook == WIN31_LOOK)
+		{
+			bar->rect.top--, bar->rect.left--, (*(bar->start.coord))++;
+			bar->rect.bottom++, bar->rect.right++, (*(bar->end.coord))--;
+		}
+		*(bar->start.coord) = start;
+		*(bar->end.coord) = end;
+	}
+	ReleaseDC(hwnd, hdc);
+	SelectObject(hdc, hSavePen);
+	SelectObject(hdc, hSaveBrush);
+/*	SelectObject(hdc, hSavePalette);  */
+	bar->lastInside = bar->inside;
 }
 
-/***********************************************************************
- *           SCROLL_ClipPos
+
+/*************************************************************************
+ *           SCROLL_RefreshScrollBar 
  */
-static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
+static void SCROLL_RefreshScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+LPSCROLL_INFO info /* [in] The place of the thumb */)
 {
-    if( pt.x < lpRect->left )
-	pt.x = lpRect->left;
-    else
-    if( pt.x > lpRect->right )
-	pt.x = lpRect->right;
-
-    if( pt.y < lpRect->top )
-	pt.y = lpRect->top;
-    else
-    if( pt.y > lpRect->bottom )
-	pt.y = lpRect->bottom;
+	TRACE("hwnd=%04x nBar=%d info=%p\n", hwnd, nBar, info);
 
-    return pt;
+	/* use the same scroll info structure unless being used by another */
+	if (trackBar.info && trackBar.info == info)
+	{
+		/* currently tracking this bar so use the track structure */
+		SCROLL_GetThumb(trackBar.hit == SB_THUMBPOSITION ? 
+			trackBar.pos : SCROLL_NO_POS, &trackBar);
+		if (trackBar.drawable)
+			SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+	}
+	else if (!(trackBar.info))
+	{
+		/* not tracking but might soon be so use the track structure */
+		SCROLL_GetScrollBar(hwnd, nBar, info, &trackBar);
+		if (trackBar.drawable) 
+			SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+		trackBar.info = 0;
+	}
+	else
+	{
+		/* Event ocurred while tracking a bar so create a bar structure */
+		SCROLL_BAR bar;
+		SCROLL_GetScrollBar(hwnd, nBar, info, &bar);
+		if (bar.drawable) SCROLL_DrawScrollBar(hwnd, nBar, &bar);
+	}
 }
 
 
-/***********************************************************************
- *           SCROLL_HitTest
+/*************************************************************************
+ *           SCROLL_PaintScrollBar 
  *
- * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
+ *  Used by nonclient windows to draw scroll bars in the windows.
+ *  (cleaning up non client would get rid of this)
  */
-static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
-                                           POINT pt, BOOL bDragging )
+void SCROLL_PaintScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */)
 {
-    INT arrowSize, thumbSize, thumbPos;
-    RECT rect;
-
-    BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
-                                           &arrowSize, &thumbSize, &thumbPos );
-
-    if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
-	 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
-
-    if (vertical)
-    {
-        if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
-        if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
-        if (!thumbPos) return SCROLL_TOP_RECT;
-        pt.y -= rect.top;
-        if (pt.y < thumbPos) return SCROLL_TOP_RECT;
-        if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
-    }
-    else  /* horizontal */
-    {
-        if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
-        if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
-        if (!thumbPos) return SCROLL_TOP_RECT;
-        pt.x -= rect.left;
-        if (pt.x < thumbPos) return SCROLL_TOP_RECT;
-        if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
-    }
-    return SCROLL_THUMB;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, nBar);
+
+	TRACE("hwnd=%04x nBar=%d\n", hwnd, nBar);
+
+	if (info && WIN_IsWindowDrawable(hwnd, FALSE))
+		SCROLL_RefreshScrollBar(hwnd, nBar, info);
 }
 
 
-/***********************************************************************
- *           SCROLL_DrawArrows
+/*************************************************************************
+ *           SCROLL_SetFocus   
  *
- * Draw the scroll bar arrows.
+ *  Add focus caret to a CTL scroll bar
  */
-static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
-                                  RECT *rect, INT arrowSize, BOOL vertical,
-                                  BOOL top_pressed, BOOL bottom_pressed )
-{
-  RECT r;
-
-  r = *rect;
-  if( vertical )
-    r.bottom = r.top + arrowSize;
-  else
-    r.right = r.left + arrowSize;
-
-  DrawFrameControl( hdc, &r, DFC_SCROLL,
-		    (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
-		    | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
-		    | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
-
-  r = *rect;
-  if( vertical )
-    r.top = r.bottom-arrowSize;
-  else
-    r.left = r.right-arrowSize;
-
-  DrawFrameControl( hdc, &r, DFC_SCROLL,
-		    (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
-		    | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
-		    | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
-}
-
-static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
-				  RECT *rect, INT arrowSize, BOOL vertical,
-				  BOOL top_pressed, BOOL bottom_pressed )
-{
-    HDC hdcMem = CreateCompatibleDC( hdc );
-    HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
-                                    TOP_ARROW(infoPtr->flags, top_pressed)
-                                    : LEFT_ARROW(infoPtr->flags, top_pressed));
-
-    SetStretchBltMode( hdc, STRETCH_DELETESCANS );
-    StretchBlt( hdc, rect->left, rect->top,
-                  vertical ? rect->right-rect->left : arrowSize,
-                  vertical ? arrowSize : rect->bottom-rect->top,
-                  hdcMem, 0, 0,
-                  GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
-                  SRCCOPY );
-
-    SelectObject( hdcMem, vertical ?
-                    BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
-                    : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
-    if (vertical)
-        StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
-                      rect->right - rect->left, arrowSize,
-                      hdcMem, 0, 0,
-                      GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
-                      SRCCOPY );
-    else
-        StretchBlt( hdc, rect->right - arrowSize, rect->top,
-                      arrowSize, rect->bottom - rect->top,
-                      hdcMem, 0, 0,
-                      GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
-                      SRCCOPY );
-    SelectObject( hdcMem, hbmpPrev );
-    DeleteDC( hdcMem );
-}
-
-static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
-			       RECT *rect, INT arrowSize, BOOL vertical,
-			       BOOL top_pressed, BOOL bottom_pressed )
-{
-  if( TWEAK_WineLook == WIN31_LOOK )
-    SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
-			  vertical, top_pressed,bottom_pressed );
-  else
-    SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
-			  vertical, top_pressed,bottom_pressed );
+static void WINAPI SCROLL_SetFocus(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */)
+{
+	SCROLL_BAR bar;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, SB_CTL);
+	if (!info) return;
+
+	TRACE("hwnd=%04x", hwnd);
+
+	/* Create a caret when a ScrollBar gets focus */
+	if (SCROLL_GetScrollBar(hwnd, SB_CTL, info, &bar))
+	{
+		CreateCaret(hwnd, 1, info->bredth - 2, info->thumb - 2);
+		SetCaretPos(bar.rect.top + 1, bar.pos + 1);
+	}
+	else
+	{
+		CreateCaret(hwnd, 1, info->thumb - 2,  info->bredth - 2);
+		SetCaretPos(bar.pos + 1, bar.rect.top + 1);
+	}
+	ShowCaret(hwnd);
 }
 
 
-/***********************************************************************
- *           SCROLL_DrawMovingThumb
+/*************************************************************************
+ *           SCROLL_KillFocus   
  *
- * Draw the moving thumb rectangle.
+ *  Remove focus caret to a CTL scroll bar
  */
-static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
-				       INT arrowSize, INT thumbSize )
+static void SCROLL_KillFocus(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */)
 {
-    RECT r = *rect;
-    if (vertical)
-    {
-        r.top += SCROLL_TrackingPos;
-        if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
-	    r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        if (r.top + thumbSize >
-	               rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
-            r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
-	                                                          - thumbSize;
-        r.bottom = r.top + thumbSize;
-    }
-    else
-    {
-        r.left += SCROLL_TrackingPos;
-        if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
-	    r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        if (r.left + thumbSize >
-	               rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
-            r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
-	                                                          - thumbSize;
-        r.right = r.left + thumbSize;
-    }
-
-    DrawFocusRect( hdc, &r );
-    SCROLL_MovingThumb = !SCROLL_MovingThumb;
-}
-
-static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
-				       INT arrowSize, INT thumbSize )
-{
-  INT pos = SCROLL_TrackingPos;
-  INT max_size;
-
-  if( vertical )
-    max_size = rect->bottom - rect->top;
-  else
-    max_size = rect->right - rect->left;
-
-  max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
-
-  if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
-    pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
-  else if( pos > max_size )
-    pos = max_size;
-
-  SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
-			  rect, arrowSize, thumbSize, pos,
-			  0, vertical, FALSE, FALSE );
-
-  SCROLL_MovingThumb = !SCROLL_MovingThumb;
-}
-
-static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
-				    INT arrowSize, INT thumbSize )
-{
-  if( TWEAK_WineLook == WIN31_LOOK )
-    SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
-  else
-    SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
+	SCROLL_BAR bar;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, SB_CTL);
+	if (!info) return;
+
+	TRACE("hwnd=%04x", hwnd);
+
+	SCROLL_GetScrollBar(hwnd, SB_CTL, info, &bar); 
+
+	/* move the bar rect */
+	*(bar.start.coord)  = bar.pos + 1;
+	*(bar.end.coord) = *(bar.start.coord) + info->thumb;
+
+	/* Handle the caret display */
+	HideCaret(hwnd);
+	InvalidateRect(hwnd, &(bar.rect), 0);
+	DestroyCaret();
 }
 
+
 /***********************************************************************
- *           SCROLL_DrawInterior
+ *           SCROLL_CreateScrollBar
  *
- * Draw the scroll bar interior (everything except the arrows).
+ *  Create a scroll bar
  */
-static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
-				    RECT *rect, INT arrowSize,
-				    INT thumbSize, INT thumbPos,
-				    UINT flags, BOOL vertical,
-				    BOOL top_selected, BOOL bottom_selected )
-{
-    RECT r;
-    HPEN hSavePen;
-    HBRUSH hSaveBrush,hBrush;
-
-    /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
-     * The window-owned scrollbars need to call DEFWND_ControlColor
-     * to correctly setup default scrollbar colors
-     */
-    if (nBar == SB_CTL)
-    {
-      hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
-				     (WPARAM)hdc,(LPARAM)hwnd);
-    }
-    else
-    {
-      hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
-    }
-
-    hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
-    hSaveBrush = SelectObject( hdc, hBrush );
-
-    /* Calculate the scroll rectangle */
-    r = *rect;
-    if (vertical)
-    {
-        r.top    += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-    }
-    else
-    {
-        r.left  += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-    }
-
-    /* Draw the scroll rectangles and thumb */
-    if (!thumbPos)  /* No thumb to draw */
-    {
-        PatBlt( hdc, r.left, r.top,
-                     r.right - r.left, r.bottom - r.top,
-                     PATCOPY );
-
-        /* cleanup and return */
-        SelectObject( hdc, hSavePen );
-        SelectObject( hdc, hSaveBrush );
-        return;
-    }
-
-    if (vertical)
-    {
-        PatBlt( hdc, r.left, r.top,
-                  r.right - r.left,
-                  thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
-                  top_selected ? 0x0f0000 : PATCOPY );
-        r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-        PatBlt( hdc, r.left, r.top + thumbSize,
-                  r.right - r.left,
-                  r.bottom - r.top - thumbSize,
-                  bottom_selected ? 0x0f0000 : PATCOPY );
-        r.bottom = r.top + thumbSize;
-    }
-    else  /* horizontal */
-    {
-        PatBlt( hdc, r.left, r.top,
-                  thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
-                  r.bottom - r.top,
-                  top_selected ? 0x0f0000 : PATCOPY );
-        r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-        PatBlt( hdc, r.left + thumbSize, r.top,
-                  r.right - r.left - thumbSize,
-                  r.bottom - r.top,
-                  bottom_selected ? 0x0f0000 : PATCOPY );
-        r.right = r.left + thumbSize;
-    }
-
-    /* Draw the thumb */
-    DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE  );
-
-    /* cleanup */
-    SelectObject( hdc, hSavePen );
-    SelectObject( hdc, hSaveBrush );
-}
-
-
-static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
-                                 RECT *rect, INT arrowSize,
-                                 INT thumbSize, INT thumbPos,
-                                 UINT flags, BOOL vertical,
-                                 BOOL top_selected, BOOL bottom_selected )
-{
-    RECT r;
-    HPEN hSavePen;
-    HBRUSH hSaveBrush,hBrush;
-    BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
-
-    if (Save_SCROLL_MovingThumb &&
-        (SCROLL_TrackingWin == hwnd) &&
-        (SCROLL_TrackingBar == nBar))
-        SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
-
-      /* Select the correct brush and pen */
-
-    if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
-    {
-        /* This ought to be the color of the parent window */
-        hBrush = GetSysColorBrush(COLOR_WINDOW);
-    }
-    else
-    {
-        /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
-         * The window-owned scrollbars need to call DEFWND_ControlColor
-         * to correctly setup default scrollbar colors
-         */
-        if (nBar == SB_CTL) {
-            hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
-                                           (WPARAM)hdc,(LPARAM)hwnd);
-        } else {
-            hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
-        }
-    }
-    hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
-    hSaveBrush = SelectObject( hdc, hBrush );
-
-      /* Calculate the scroll rectangle */
-
-    r = *rect;
-    if (vertical)
-    {
-        r.top    += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-    }
-    else
-    {
-        r.left  += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
-        r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-    }
-
-      /* Draw the scroll bar frame */
-
-	/* Only draw outline if Win 3.1.  Mar 24, 1999 - Ronald B. Cemer */
-    if (TWEAK_WineLook == WIN31_LOOK)
-	Rectangle( hdc, r.left, r.top, r.right, r.bottom );
-
-      /* Draw the scroll rectangles and thumb */
-
-    if (!thumbPos)  /* No thumb to draw */
-    {
-        INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
-
-        PatBlt( hdc, r.left+offset, r.top+offset,
-                     r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
-                     PATCOPY );
-
-        /* cleanup and return */
-        SelectObject( hdc, hSavePen );
-        SelectObject( hdc, hSaveBrush );
-        return;
-    }
-
-    if (vertical)
-    {
-        INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
-
-        PatBlt( hdc, r.left + offset, r.top + offset,
-                  r.right - r.left - offset*2,
-                  thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
-                  top_selected ? 0x0f0000 : PATCOPY );
-        r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-        PatBlt( hdc, r.left + offset, r.top + thumbSize,
-                  r.right - r.left - offset*2,
-                  r.bottom - r.top - thumbSize - offset,
-                  bottom_selected ? 0x0f0000 : PATCOPY );
-        r.bottom = r.top + thumbSize;
-    }
-    else  /* horizontal */
-    {
-        INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
-
-        PatBlt( hdc, r.left + offset, r.top + offset,
-                  thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
-                  r.bottom - r.top - offset*2,
-                  top_selected ? 0x0f0000 : PATCOPY );
-        r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
-        PatBlt( hdc, r.left + thumbSize, r.top + offset,
-                  r.right - r.left - thumbSize - offset,
-                  r.bottom - r.top - offset*2,
-                  bottom_selected ? 0x0f0000 : PATCOPY );
-        r.right = r.left + thumbSize;
-    }
-
-      /* Draw the thumb */
-
-    SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
-    if (TWEAK_WineLook == WIN31_LOOK)
-    {
-	Rectangle( hdc, r.left, r.top, r.right, r.bottom );
-	r.top++, r.left++;
-    }
-    else
-    {
-	Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
-    }
-    DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
-
-    if (Save_SCROLL_MovingThumb &&
-        (SCROLL_TrackingWin == hwnd) &&
-        (SCROLL_TrackingBar == nBar))
-        SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
-
-    /* cleanup */
-    SelectObject( hdc, hSavePen );
-    SelectObject( hdc, hSaveBrush );
+static void SCROLL_CreateScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+LPCREATESTRUCTW lpCreate /* [in] The style and place of the scroll bar */)
+{
+	POINT pos, size;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, SB_CTL);
+	if (!info) return;
+
+	TRACE("hwnd=%04x lpCreate=%p\n", hwnd, lpCreate);
+
+	if (lpCreate->style & WS_DISABLED)
+	{
+		info->flags = ESB_DISABLE_BOTH;
+		TRACE("Created WS_DISABLED scrollbar\n");
+	}
+	if (lpCreate->style & SBS_SIZEBOX)
+	{
+		FIXME("Unimplemented style SBS_SIZEBOX.\n" );
+		return;
+	}
+
+	/* copy the desired positions and size */
+	pos.x = lpCreate->x; pos.y = lpCreate->y;
+	size.x = lpCreate->cx; size.y = lpCreate->cy;
+
+	/* move position based on style */
+	if (lpCreate->style & SBS_RIGHTALIGN)
+		pos.x += size.x - info->bredth - 1;
+	else if (lpCreate->style & SBS_BOTTOMALIGN)
+		pos.y += size.y - info->bredth - 1;
+
+	/* change size based on style */
+	if (lpCreate->style & SBS_VERT)
+		size.x = info->bredth + 1;
+	else
+		size.y = info->bredth + 1;
+        
+	MoveWindow(hwnd, pos.x, pos.y, size.x, size.y, FALSE);
 }
 
 
 /***********************************************************************
- *           SCROLL_DrawScrollBar
+ *           SCROLL_GetHit
  *
- * Redraw the whole scrollbar.
+ * Determine in which part of the scroll bar the event happened.
  */
-void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
-			   BOOL arrows, BOOL interior )
-{
-    INT arrowSize, thumbSize, thumbPos;
-    RECT rect;
-    BOOL vertical;
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
-    SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
-    BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
-
-    if (!wndPtr || !infoPtr ||
-        ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
-        ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
-    if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
-    hwnd = wndPtr->hwndSelf;  /* make it a full handle */
-
-    vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
-                                        &arrowSize, &thumbSize, &thumbPos );
-
-    /* do not draw if the scrollbar rectangle is empty */
-    if(IsRectEmpty(&rect))
-      goto END;
-
-    if (Save_SCROLL_MovingThumb &&
-        (SCROLL_TrackingWin == hwnd) &&
-        (SCROLL_TrackingBar == nBar))
-        SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
-
-      /* Draw the arrows */
-
-    if (arrows && arrowSize)
-    {
-	if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
-	    SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
-			       (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
-			       (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
+static UINT SCROLL_GetHit(
+LONG coord /* [in] The the position of the mouse at the event */,
+LPSCROLL_BAR bar /* [in] The containing bar */)
+{
+	if (coord < 0)
+		return SB_LINEUP;
+	else if (coord >= bar->pixels - bar->arrow * 2)
+		return SB_LINEDOWN;
+	else if (coord < bar->pos)
+		return SB_PAGEUP;
+	else if (coord >= bar->pos + bar->thumb)
+		return SB_PAGEDOWN;
 	else
-	    SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
-							       FALSE, FALSE );
-    }
-    if( interior )
-	SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
-                         thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
-
-    if (Save_SCROLL_MovingThumb &&
-        (SCROLL_TrackingWin == hwnd) &&
-        (SCROLL_TrackingBar == nBar))
-        SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
-
-    /* if scroll bar has focus, reposition the caret */
-    if(hwnd==GetFocus() && (nBar==SB_CTL))
-    {
-        if (!vertical)
-        {
-            SetCaretPos(thumbPos+1, rect.top+1);
-        }
-        else
-        {
-            SetCaretPos(rect.top+1, thumbPos+1);
-        }
-    }
-
-END:
-    WIN_ReleaseWndPtr(wndPtr);
+		return SB_THUMBPOSITION;
 }
 
 
 /***********************************************************************
- *           SCROLL_RefreshScrollBar
+ *           SCROLL_HandleScrollEvent
  *
- * Repaint the scroll bar interior after a SetScrollRange() or
- * SetScrollPos() call.
+ * Handle a mouse or timer event for the scrollbar.
  */
-static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
-				     BOOL arrows, BOOL interior )
-{
-    HDC hdc = GetDCEx( hwnd, 0,
-                           DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
-    if (!hdc) return;
+void SCROLL_HandleScrollEvent(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+UINT msg /* [in] The windows message identifier */,
+LPARAM lParam /* [in] The the position of the mouse at the event */)
+{
+	static UINT clickPos;  /* thumb position when tracking started */
+	static INT clickCoord; /* scroll coordinate of last button-down event */
+	static INT lastCoord;  /* scroll coordinate of last thumb move event */
+
+	/* Initialise the client position offset */
+	MSG mesg;              /* message structure used when tracking */
+	POINT pt;              /* location for event in client coordinates */
+	LONG *coordinate;      /* pointer to relevent coordinate in pt */  
+	LONG coord;            /* coordinate of event interior to arrows */
+	UINT curVal;           /* proposed current value during scrolling */
+	INT oldPos;            /* precious pos when handling moves */
+	BOOL tracking = FALSE; /* inicates if the scrol bar is tracking */
+	LPARAM hwndCtl = (nBar == SB_CTL) ? (LPARAM)hwnd : (LPARAM)0;
+	HWND hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
+
+	/* check scroll bar is enabled */
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, nBar);
+	if (!info || SCROLL_DISABLED(info)) return;
+
+	TRACE("hwnd=%04x nBar=%d\n",hwnd, nBar);
+
+	/* set the appropriate scroll coordinate from pt */
+	if (SCROLL_GetScrollBar(hwnd, nBar, info, &trackBar))
+		coordinate = &(pt.y);
+	else
+		coordinate = &(pt.x);
 
-    SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
-    ReleaseDC( hwnd, hdc );
+	/* fill in initial dummy message structure */
+	mesg.message = msg;
+	mesg.lParam = lParam;
+
+	do {
+		/* determine the coordinates in client frame */
+		if (mesg.message == WM_LBUTTONDOWN ||
+			mesg.message == WM_MOUSEMOVE || 
+			mesg.message == WM_LBUTTONUP)
+		{
+			pt.x = LOWORD(mesg.lParam) - trackBar.offset.x;
+			pt.y = HIWORD(mesg.lParam) - trackBar.offset.y;
+		}
+
+		/* mouse down messages are in screen coordinates */
+		if (mesg.message == WM_LBUTTONDOWN && nBar != SB_CTL)
+			ScreenToClient(hwnd, &pt);
+
+		/* determine coordinate in bar after arrow */
+		coord = *coordinate - *(trackBar.start.coord) - trackBar.arrow;
+
+		TRACE("     processing: msg=%s pt=%ld,%ld\n",
+			SPY_GetMsgName(mesg.message, hwnd), pt.x, pt.y);
+
+		/* handle mesage */
+		if (!tracking || !CallMsgFilterW(&mesg, MSGF_SCROLLBAR))
+		switch (mesg.message)
+		{
+		case WM_LBUTTONDOWN:
+			/* handle coords, caret, focus, capture and tracking*/
+			if (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP) SetFocus(hwnd);
+			SetCapture(hwnd);
+			HideCaret(hwnd);
+			tracking = TRUE;
+
+			/* set the hit and tracking parameters */
+			clickPos = trackBar.pos;
+			lastCoord = clickCoord = coord =
+				*coordinate - *(trackBar.start.coord) - trackBar.arrow;
+
+			/* determine the hit position and draw */
+			trackBar.hit = SCROLL_GetHit(coord, &trackBar);
+			if (trackBar.hit == SB_THUMBPOSITION) break;
+			SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+			/* fall through */
+
+		case WM_SYSTIMER:
+			if (trackBar.inside && trackBar.hit != SB_THUMBPOSITION) 
+			{
+				/* send the hit message to the parent */
+				SendMessageA(hwndOwner, trackBar.direction, trackBar.hit, hwndCtl);
+
+				/* don't repeat when at either the end of the bar */
+				if (!((trackBar.hit == SB_LINEUP && info->curVal == info->minVal) ||
+					(trackBar.hit == SB_LINEDOWN &&
+						info->curVal == info->maxVal - info->page + 1)))
+					SetSystemTimer(hwnd, SCROLL_TIMER, (mesg.message == WM_LBUTTONDOWN) ?
+						SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, (TIMERPROC)0);
+				else
+					KillSystemTimer(hwnd, SCROLL_TIMER);
+
+				/* handle thumb moving under cursor in page moves */
+				if (!(trackBar.inside = (trackBar.hit == SCROLL_GetHit(coord, &trackBar))))
+					SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+			}
+			break;
+
+		case WM_MOUSEMOVE:
+			/* deterine if inside the bar and update the scroll position */
+			curVal = info->curVal;
+			if (trackBar.hit == SB_LINEUP || trackBar.hit == SB_LINEDOWN)
+				trackBar.inside = PtInRect(&(trackBar.rect), pt)  &&
+					trackBar.hit == SCROLL_GetHit(coord, &trackBar);
+			else if (!trackBar.inside)
+				; /* once outsidebar always outside for non arrow hits */
+			else if (trackBar.hit != SB_THUMBPOSITION)
+				trackBar.inside = PtInRect(&(trackBar.rect), pt) &&
+					trackBar.hit == SCROLL_GetHit(coord, &trackBar);
+			else if (!(trackBar.inside = PtInRect(&(trackBar.extended), pt)))
+				trackBar.hit = SCROLL_NO_POS, curVal = SCROLL_GetThumb(clickPos, &trackBar);
+			else if (coord != lastCoord)
+			{
+				/* if move is relevent find new curVal */
+				lastCoord = coord;
+				oldPos = trackBar.pos;
+				curVal = SCROLL_GetThumb(clickPos + coord - clickCoord, &trackBar);
+				if (trackBar.pos != oldPos) SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+			}
+
+			/* send SB_THUMBTRACK messages to parent if moved */
+			if (info->curVal != curVal)
+				SendMessageA(hwndOwner, trackBar.direction, 
+					MAKEWPARAM(SB_THUMBPOSITION /*SB_THUMBTRACK*/, curVal), hwndCtl);
+
+			/* redraw if needed */
+			if (SCROLL_CHANGED(&trackBar))
+				SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+			break;
+
+		case WM_LBUTTONUP:
+			/* send messages to control */
+			if (trackBar.hit == SB_THUMBPOSITION)
+				SendMessageA(hwndOwner, trackBar.direction,
+					MAKEWPARAM(trackBar.hit, info->curVal), hwndCtl);
+			else if (trackBar.inside)
+			{
+				trackBar.inside = FALSE;
+				SCROLL_DrawScrollBar(hwnd, nBar, &trackBar);
+			}
+			SendMessageA(hwndOwner, trackBar.direction, SB_ENDSCROLL, hwndCtl);
+
+			/* clean up capture and timer */
+			ReleaseCapture();
+			KillSystemTimer(hwnd, SCROLL_TIMER);
+			if (hwnd == GetFocus()) ShowCaret(hwnd);
+			tracking = FALSE;
+			break;
+
+		default:
+			if (tracking)
+			{
+				TranslateMessage(&mesg);
+				DispatchMessageW(&mesg);
+			}
+			else
+				ERR("Illegal message %s\n", SPY_GetMsgName(msg, hwnd));   
+			break;
+		}
+		/*if (tracking && !IsWindow(hwnd)) ReleaseCapture();*/
+	} while (tracking && GetMessageW(&mesg, 0, 0, 0));
+
+	/* Note: failing GetMessageW(&mesg, 0, 0, 0)
+	 * will not clean up capture or scroll timer properly
+	 */ 
+	trackBar.info = 0;
 }
 
 
@@ -881,533 +981,352 @@
  *           SCROLL_HandleKbdEvent
  *
  * Handle a keyboard event (only for SB_CTL scrollbars).
+ * if key event is received, the scrollbar has the focus
  */
-static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
+static void SCROLL_HandleKbdEvent(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+WPARAM wParam /* [in] Variable input including enable state */,
+LPARAM lParam /* [in] Varialbe input including input point */)
+{
+	TRACE("hwnd=%04x wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
+
+	/* hide caret on first KEYDOWN to prevent flicker */
+	if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0) HideCaret(hwnd);
+	switch(wParam)
+	{
+		case VK_PRIOR: wParam = SB_PAGEUP; break;
+		case VK_NEXT:  wParam = SB_PAGEDOWN; break;
+		case VK_HOME:  wParam = SB_TOP; break;
+		case VK_END:   wParam = SB_BOTTOM; break;
+		case VK_UP:    wParam = SB_LINEUP; break;
+		case VK_DOWN:  wParam = SB_LINEDOWN; break;
+		default: return;
+	}
+	SendMessageW(GetParent(hwnd), 
+		((GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ?
+			WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
+}
+
+
+/*************************************************************************
+ *           SCROLL_SetScrollRange   (USER32.@)
+ *
+ *  Set scroll range returning old value of position if it has changed
+ *
+ * RETURNS
+ *
+ *  The old position if the position has changed
+ */
+static LRESULT SCROLL_SetScrollRange( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT minVal /* [in] New minimum value */,
+INT maxVal /* [in] New maximum value */,
+BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
 {
-    WPARAM msg;
+	INT oldPos = GetScrollPos(hwnd, SB_CTL);
 
-    switch(wParam)
-    {
-    case VK_PRIOR: msg = SB_PAGEUP; break;
-    case VK_NEXT:  msg = SB_PAGEDOWN; break;
-    case VK_HOME:  msg = SB_TOP; break;
-    case VK_END:   msg = SB_BOTTOM; break;
-    case VK_UP:    msg = SB_LINEUP; break;
-    case VK_DOWN:  msg = SB_LINEDOWN; break;
-    default: return;
-    }
-    SendMessageW( GetParent(hwnd),
-                  (GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
-                  msg, (LPARAM)hwnd );
+	SetScrollRange(hwnd, SB_CTL, minVal, maxVal, bRedraw);
+	if (oldPos != GetScrollPos(hwnd, SB_CTL))
+		return oldPos;
+	else
+		return 0;
 }
 
 
 /***********************************************************************
- *           SCROLL_HandleScrollEvent
+ *      FlatSB_GetScrollProp (COMCTL32.@)
+ *
+ * Returns:
+ *  nonzero if successful, or zero otherwise.
+ *
+ *  If index is WSB_PROP_HSTYLE, the return is nonzero if InitializeFlatSB
+ *  has been called for this window, or zero otherwise.
  *
- * Handle a mouse or timer event for the scrollbar.
- * 'pt' is the location of the mouse event in client (for SB_CTL) or
- * windows coordinates.
  */
-static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
+static BOOL SCROLL_GetBarProp(
+LPSCROLL_INFO info/* [in] Handle of window with scrollbar(s) */,
+INT propIndex /* [in] Index of scroll bar property to be obtained */,
+LPINT prop /* [out] Value of scroll bar property */)
 {
-      /* Previous mouse position for timer events */
-    static POINT prevPt;
-      /* Thumb position when tracking started. */
-    static UINT trackThumbPos;
-      /* Position in the scroll-bar of the last button-down event. */
-    static INT lastClickPos;
-      /* Position in the scroll-bar of the last mouse event. */
-    static INT lastMousePos;
-
-    enum SCROLL_HITTEST hittest;
-    HWND hwndOwner, hwndCtl;
-    BOOL vertical;
-    INT arrowSize, thumbSize, thumbPos;
-    RECT rect;
-    HDC hdc;
-
-    SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
-    if (!infoPtr) return;
-    if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
-		  return;
-
-    hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
-    vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
-                                        &arrowSize, &thumbSize, &thumbPos );
-    hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
-    hwndCtl   = (nBar == SB_CTL) ? hwnd : 0;
-
-    switch(msg)
-    {
-      case WM_LBUTTONDOWN:  /* Initialise mouse tracking */
-          HideCaret(hwnd);  /* hide caret while holding down LBUTTON */
-          SCROLL_trackVertical = vertical;
-          SCROLL_trackHitTest  = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
-          lastClickPos  = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
-          lastMousePos  = lastClickPos;
-          trackThumbPos = thumbPos;
-          prevPt = pt;
-          if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
-          SetCapture( hwnd );
-          break;
-
-      case WM_MOUSEMOVE:
-          hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
-          prevPt = pt;
-          break;
-
-      case WM_LBUTTONUP:
-          hittest = SCROLL_NOWHERE;
-          ReleaseCapture();
-          /* if scrollbar has focus, show back caret */
-          if (hwnd==GetFocus()) ShowCaret(hwnd);
-          break;
-
-      case WM_SYSTIMER:
-          pt = prevPt;
-          hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
-          break;
-
-      default:
-          return;  /* Should never happen */
-    }
-
-    TRACE("Event: hwnd=%04x bar=%d msg=%s pt=%ld,%ld hit=%d\n",
-          hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
-
-    switch(SCROLL_trackHitTest)
-    {
-    case SCROLL_NOWHERE:  /* No tracking in progress */
-        break;
-
-    case SCROLL_TOP_ARROW:
-        SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
-                           (hittest == SCROLL_trackHitTest), FALSE );
-        if (hittest == SCROLL_trackHitTest)
-        {
-            if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
-            {
-                SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                                SB_LINEUP, (LPARAM)hwndCtl );
-	    }
-
-	    SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-			    SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-			    (TIMERPROC)0 );
-        }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
-        break;
-
-    case SCROLL_TOP_RECT:
-        SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
-                             thumbPos, infoPtr->flags, vertical,
-                             (hittest == SCROLL_trackHitTest), FALSE );
-        if (hittest == SCROLL_trackHitTest)
-        {
-            if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
-            {
-                SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                                SB_PAGEUP, (LPARAM)hwndCtl );
-            }
-            SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                              SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                              (TIMERPROC)0 );
-        }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
-        break;
-
-    case SCROLL_THUMB:
-        if (msg == WM_LBUTTONDOWN)
-        {
-            SCROLL_TrackingWin = hwnd;
-            SCROLL_TrackingBar = nBar;
-            SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
-	    if (!SCROLL_MovingThumb)
-		SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
-        }
-        else if (msg == WM_LBUTTONUP)
-        {
-	    if (SCROLL_MovingThumb)
-		SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
-            SCROLL_TrackingWin = 0;
-            SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
-                                 thumbPos, infoPtr->flags, vertical,
-                                 FALSE, FALSE );
-        }
-        else  /* WM_MOUSEMOVE */
-        {
-            UINT pos;
-
-            if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
-            else
-	    {
-		pt = SCROLL_ClipPos( &rect, pt );
-		pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
-	    }
-            if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
-            {
-		if (SCROLL_MovingThumb)
-		    SCROLL_DrawMovingThumb( hdc, &rect, vertical,
-                                        arrowSize, thumbSize );
-                lastMousePos = pos;
-                SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
-                SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
-                                                         vertical,
-                                                         SCROLL_TrackingPos );
-                SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                                MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
-                                (LPARAM)hwndCtl );
-		if (!SCROLL_MovingThumb)
-		    SCROLL_DrawMovingThumb( hdc, &rect, vertical,
-                                        arrowSize, thumbSize );
-            }
-        }
-        break;
-
-    case SCROLL_BOTTOM_RECT:
-        SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
-                             thumbPos, infoPtr->flags, vertical,
-                             FALSE, (hittest == SCROLL_trackHitTest) );
-        if (hittest == SCROLL_trackHitTest)
-        {
-            if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
-            {
-                SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                                SB_PAGEDOWN, (LPARAM)hwndCtl );
-            }
-            SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                              SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                              (TIMERPROC)0 );
-        }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
-        break;
-
-    case SCROLL_BOTTOM_ARROW:
-        SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
-                           FALSE, (hittest == SCROLL_trackHitTest) );
-        if (hittest == SCROLL_trackHitTest)
-        {
-            if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
-            {
-                SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                                SB_LINEDOWN, (LPARAM)hwndCtl );
-	    }
-
-	    SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-			    SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-			    (TIMERPROC)0 );
-        }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
-        break;
-    }
-
-    if (msg == WM_LBUTTONDOWN)
-    {
-
-        if (hittest == SCROLL_THUMB)
-        {
-            UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
-                                 trackThumbPos + lastMousePos - lastClickPos );
-            SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                            MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
-        }
-    }
-
-    if (msg == WM_LBUTTONUP)
-    {
-	hittest = SCROLL_trackHitTest;
-	SCROLL_trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */
-
-        if (hittest == SCROLL_THUMB)
-        {
-            UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
-                                 trackThumbPos + lastMousePos - lastClickPos );
-            SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                            MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
-        }
-        SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                          SB_ENDSCROLL, (LPARAM)hwndCtl );
-    }
-
-    ReleaseDC( hwnd, hdc );
+	if (!info) return FALSE;
+	switch (propIndex)
+	{
+		case WSB_PROP_CXHSCROLL: *prop = info->arrow; break;
+		case WSB_PROP_CYHSCROLL: *prop = info->bredth; break;
+		case WSB_PROP_CXHTHUMB: *prop = info->thumb; break;
+		case WSB_PROP_HBKGCOLOR: *prop= info->background; break;
+		case WSB_PROP_HSTYLE: *prop = info->style; break;
+		case WSB_PROP_PALETTE: *prop = info->palette; break;
+	}
+	return TRUE;
 }
 
 
 /***********************************************************************
- *           SCROLL_TrackScrollBar
+ *      FlatSB_GetScrollProp (COMCTL32.@)
+ *
+ * Returns:
+ *  nonzero if successful, or zero otherwise.
+ *
+ *  If index is WSB_PROP_HSTYLE, the return is nonzero if InitializeFlatSB
+ *  has been called for this window, or zero otherwise.
  *
- * Track a mouse button press on a scroll-bar.
- * pt is in screen-coordinates for non-client scroll bars.
  */
-void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
+static BOOL SCROLL_GetScrollProp(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT propIndex /* [in] Index of scroll bar property to be obtained */,
+LPINT prop /* [out] Value of scroll bar property */)
+{
+	TRACE("hwnd=%04x propIndex=%d prop=%p\n", hwnd, propIndex, prop);
+
+	/* ignore invalid indexes */
+	propIndex &= WSB_PROP_MASK;
+
+	/* Handle horizontal properties */
+	if (propIndex & SCROLL_HORIZONTAL_MASK)
+		return SCROLL_GetBarProp(
+			SCROLL_GetScrollInfo(hwnd, SB_HORZ), propIndex, prop);
+	/* handle vertical properties */
+	else if (propIndex & SCROLL_VERTICAL_MASK)
+		return SCROLL_GetBarProp(
+			SCROLL_GetScrollInfo(hwnd, SB_VERT), propIndex, prop);
+	/* handle the windows properties */
+	else if (propIndex == WSB_PROP_WINSTYLE)
+		*prop = GetWindowLongW (hwnd, GWL_STYLE);
+	return TRUE;
+}
+
+
+/***********************************************************************
+ *      FlatSB_SetScrollProp (COMCTL32.@)
+ * 
+ * RETURNS STD
+ */
+static BOOL SCROLL_SetBarProp(
+LPSCROLL_INFO info /* [in] Handle of window with scrollbar(s) */,
+UINT index /* [in]  Index of scroll bar property to be obtained */,
+INT newValue /* [in] Value of property to be set */)
 {
-    MSG msg;
-    INT xoffset = 0, yoffset = 0;
-
-    if (scrollbar != SB_CTL)
-    {
-        WND *wndPtr = WIN_GetPtr( hwnd );
-        if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
-        xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
-        yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
-        WIN_ReleasePtr( wndPtr );
-        ScreenToClient( hwnd, &pt );
-        pt.x += xoffset;
-        pt.y += yoffset;
-    }
-
-    SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
-
-    do
-    {
-        if (!GetMessageW( &msg, 0, 0, 0 )) break;
-        if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
-        switch(msg.message)
-        {
-        case WM_LBUTTONUP:
-        case WM_MOUSEMOVE:
-        case WM_SYSTIMER:
-            pt.x = LOWORD(msg.lParam) + xoffset;
-            pt.y = HIWORD(msg.lParam) + yoffset;
-            SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
-            break;
-        default:
-            TranslateMessage( &msg );
-            DispatchMessageW( &msg );
-            break;
-        }
-        if (!IsWindow( hwnd ))
-        {
-            ReleaseCapture();
-            break;
-        }
-    } while (msg.message != WM_LBUTTONUP);
+	if (!info) return FALSE;
+	switch (index)
+	{
+		case WSB_PROP_CXHSCROLL:
+			if (info->arrow != newValue) info->arrow = newValue;  break;
+		case WSB_PROP_CYHSCROLL:
+			if (info->bredth != newValue) info->bredth = newValue;  break;
+		case WSB_PROP_CXHTHUMB:
+			if (info->thumb != newValue) info->thumb = newValue;  break;
+		case WSB_PROP_HBKGCOLOR:
+			if (info->background != newValue) info->background = newValue;  break;
+		case WSB_PROP_HSTYLE:
+			if (info->style != newValue) info->style = newValue;  break;
+		case WSB_PROP_PALETTE:
+			if (info->palette != newValue) info->palette = newValue;  break;
+	}
+	return TRUE;
+}
+
+
+/***********************************************************************
+ *      FlatSB_SetScrollProp (COMCTL32.@)
+ * 
+ * RETURNS STD
+ */
+static BOOL SCROLL_SetScrollProp(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+UINT index /* [in]  Index of scroll bar property to be obtained */,
+INT newValue /* [in] Value of property to be set */)
+{
+	TRACE("hwnd=%04x index=%u newValue=%d\n", hwnd, index, newValue);
+
+	/* ignore invalid indexes */
+	index &= WSB_PROP_MASK;
+
+	/* Handle horizontal properties */
+	if (index & SCROLL_HORIZONTAL_MASK)
+		return SCROLL_SetBarProp(
+			SCROLL_GetScrollInfo(hwnd, SB_HORZ), index, newValue);
+	/* handle vertical properties */
+	else if (index & SCROLL_VERTICAL_MASK)
+		return SCROLL_SetBarProp(
+			SCROLL_GetScrollInfo(hwnd, SB_VERT), index, newValue);
+	/* handle the windows properties */
+	else if (index == WSB_PROP_WINSTYLE)
+		SetWindowLongW (hwnd, GWL_STYLE, newValue);
+	return TRUE;
 }
 
 
 /***********************************************************************
  *           ScrollBarWndProc
+ *
+ *  The routine for handling window events
+ *  
+ * RETURNS
+ *   Zero
+*/
+static LRESULT WINAPI ScrollBarWndProc(
+HWND hwnd /* [in] Handle of window whose scrollbar(s) will be affected */,
+UINT message /* [in] The windows message to be actioned */,
+WPARAM wParam /* [in] Variable input including enable state */,
+LPARAM lParam /* [in] Variable input including input point */)
+{	
+	TRACE("hwnd=%04x message=%s wParam=%d lParam=%ld\n",
+		hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam);
+	
+	/* handle the windows message */
+	if (IsWindow(hwnd)) switch (message)
+	{
+	case WM_CREATE:
+		SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam); break;
+
+	case WM_ENABLE:
+		return EnableScrollBar(hwnd, SB_CTL,
+			wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH);
+
+	case WM_LBUTTONDOWN:
+	case WM_LBUTTONUP:
+	case WM_MOUSEMOVE:
+	case WM_SYSTIMER:
+		SCROLL_HandleScrollEvent(hwnd, SB_CTL, message, lParam); break;
+
+	case WM_KEYDOWN:
+		SCROLL_HandleKbdEvent(hwnd, wParam, lParam); break;
+
+	case WM_KEYUP:
+		ShowCaret(hwnd); break;
+
+	case WM_SETFOCUS:
+		SCROLL_SetFocus(hwnd); break;
+
+	case WM_KILLFOCUS:
+		SCROLL_KillFocus(hwnd);  break;
+
+	case WM_ERASEBKGND:
+		return 1;
+
+	case WM_GETDLGCODE:
+		return DLGC_WANTARROWS; /* Windows returns this value */
+
+	case WM_PAINT:
+		/* FIXME: If the message technique is used for FlatSB's then this has
+		   to updated to handle the direction of the bar */
+		SCROLL_PaintScrollBar(hwnd, SB_CTL); break;
+
+	case SBM_SETPOS16:
+	case SBM_SETPOS:
+		return SetScrollPos(hwnd, SB_CTL, wParam, (BOOL)lParam);
+
+	case SBM_GETPOS16:
+	case SBM_GETPOS:
+		return GetScrollPos(hwnd, SB_CTL);
+
+	case SBM_SETRANGE16:
+		return SetScrollRange(hwnd, SB_CTL, LOWORD(lParam),
+			HIWORD(lParam), wParam); 
+ 
+	case SBM_SETRANGE:
+		return SCROLL_SetScrollRange(hwnd, wParam, lParam, FALSE);
+
+	case SBM_GETRANGE16:
+		FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x, lp=%08lx)\n",
+			wParam, lParam);
+		break;
+
+	case SBM_GETRANGE:
+		GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
+		break;
+
+	case SBM_ENABLE_ARROWS16:
+	case SBM_ENABLE_ARROWS:
+		return EnableScrollBar(hwnd, SB_CTL, wParam);
+
+	case SBM_SETRANGEREDRAW:
+		return SCROLL_SetScrollRange(hwnd, wParam, lParam, TRUE);
+
+	case SBM_SETSCROLLINFO:
+		return SetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam);
+	    
+	case SBM_GETSCROLLINFO:
+		return GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
+
+	case 0x00e5:
+		return SCROLL_GetScrollProp(hwnd, wParam, (LPINT)lParam);
+	case 0x00e7:
+		return SCROLL_SetScrollProp(hwnd, wParam, lParam);
+	case 0x00e8:
+	case 0x00eb:
+	case 0x00ec:
+	case 0x00ed:
+	case 0x00ee:
+	case 0x00ef:
+		ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
+			message, wParam, lParam);
+		return 0; 
+
+	default:
+		if (message >= WM_USER)
+			WARN("unknown msg %04x wp=%04x lp=%08lx\n",
+				message, wParam, lParam);
+		return DefWindowProcW(hwnd, message, wParam, lParam);
+	}
+	return 0;
+}
+
+
+/*************************************************************************
+ *           ShowScrollBar   (USER32.@)
+ *
+ * RETURNS STD
  */
-static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
+BOOL WINAPI ShowScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+BOOL fShow /* [in] TRUE = show, FALSE = hide  */)
 {
-    if (!IsWindow( hwnd )) return 0;
+	LONG style = GetWindowLongW( hwnd, GWL_STYLE );
+	LONG oldStyle = style;
 
-    switch(message)
-    {
-    case WM_CREATE:
-        {
-	    SCROLLBAR_INFO *infoPtr;
-            CREATESTRUCTW *lpCreat = (CREATESTRUCTW *)lParam;
-
-	    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL ))) return -1;
-	    if (lpCreat->style & WS_DISABLED)
-	    {
-		TRACE("Created WS_DISABLED scrollbar\n");
-		infoPtr->flags = ESB_DISABLE_BOTH;
-	    }
+	TRACE("hwnd=%04x nBar=%d fShow=%d\n", hwnd, nBar, fShow);
 
-            if (lpCreat->style & SBS_SIZEBOX)
-            {
-                FIXME("Unimplemented style SBS_SIZEBOX.\n" );
-                return 0;
-            }
-	    if (lpCreat->style & SBS_VERT)
-            {
-                if (lpCreat->style & SBS_LEFTALIGN)
-                    MoveWindow( hwnd, lpCreat->x, lpCreat->y,
-                                  GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
-                else if (lpCreat->style & SBS_RIGHTALIGN)
-                    MoveWindow( hwnd,
-                                  lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
-                                  lpCreat->y,
-                                  GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
-            }
-            else  /* SBS_HORZ */
-            {
-                if (lpCreat->style & SBS_TOPALIGN)
-                    MoveWindow( hwnd, lpCreat->x, lpCreat->y,
-                                  lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
-                else if (lpCreat->style & SBS_BOTTOMALIGN)
-                    MoveWindow( hwnd,
-                                  lpCreat->x,
-                                  lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
-                                  lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
-            }
-        }
-        if (!hUpArrow) SCROLL_LoadBitmaps();
-        TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
-        return 0;
-
-    case WM_ENABLE:
-        {
-	    SCROLLBAR_INFO *infoPtr;
-	    if ((infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL )))
-	    {
-		infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
-		SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
-	    }
+	/* change the show state as requested */
+	switch (nBar)
+	{
+	case SB_CTL:
+		ShowWindow(hwnd, fShow ? SW_SHOW : SW_HIDE );
+		return TRUE;
+
+	case SB_BOTH:
+	case SB_HORZ:
+		if (fShow)
+			style |= WS_HSCROLL;
+		else  /* hide it */
+			style &= ~WS_HSCROLL;
+		if (nBar == SB_HORZ) break;
+		/* fall through */
+	case SB_VERT:
+		if (fShow)
+			style |= WS_VSCROLL;
+		else  /* hide it */
+			style &= ~WS_VSCROLL;
+	default:
+		break;
 	}
-	return 0;
 
-    case WM_LBUTTONDOWN:
-        {
-	    POINT pt;
-	    pt.x = SLOWORD(lParam);
-	    pt.y = SHIWORD(lParam);
-            SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
-	}
-        break;
-    case WM_LBUTTONUP:
-    case WM_MOUSEMOVE:
-    case WM_SYSTIMER:
-        {
-            POINT pt;
-            pt.x = SLOWORD(lParam);
-            pt.y = SHIWORD(lParam);
-            SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
-        }
-        break;
-
-    /* if key event is received, the scrollbar has the focus */
-    case WM_KEYDOWN:
-        /* hide caret on first KEYDOWN to prevent flicker */
-        if ((lParam & 0x40000000)==0)
-            HideCaret(hwnd);
-        SCROLL_HandleKbdEvent( hwnd, wParam );
-        break;
-
-    case WM_KEYUP:
-        ShowCaret(hwnd);
-        break;
-
-    case WM_SETFOCUS:
-        {
-            /* Create a caret when a ScrollBar get focus */
-            RECT rect;
-            int arrowSize, thumbSize, thumbPos, vertical;
-            vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
-                                                &arrowSize, &thumbSize, &thumbPos );
-            if (!vertical)
-            {
-                CreateCaret(hwnd,1, thumbSize-2, rect.bottom-rect.top-2);
-                SetCaretPos(thumbPos+1, rect.top+1);
-            }
-            else
-            {
-                CreateCaret(hwnd,1, rect.right-rect.left-2,thumbSize-2);
-                SetCaretPos(rect.top+1, thumbPos+1);
-            }
-            ShowCaret(hwnd);
-        }
-        break;
-
-    case WM_KILLFOCUS:
-        {
-            RECT rect;
-            int arrowSize, thumbSize, thumbPos, vertical;
-            vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
-            if (!vertical){
-                rect.left=thumbPos+1;
-                rect.right=rect.left+thumbSize;
-            }
-            else
-            {
-                rect.top=thumbPos+1;
-                rect.bottom=rect.top+thumbSize;
-            }
-            HideCaret(hwnd);
-            InvalidateRect(hwnd,&rect,0);
-            DestroyCaret();
-        }
-        break;
-
-    case WM_ERASEBKGND:
-         return 1;
-
-    case WM_GETDLGCODE:
-         return DLGC_WANTARROWS; /* Windows returns this value */
-
-    case WM_PAINT:
-        {
-            PAINTSTRUCT ps;
-            HDC hdc = BeginPaint( hwnd, &ps );
-            SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
-            EndPaint( hwnd, &ps );
-        }
-        break;
-
-    case SBM_SETPOS16:
-    case SBM_SETPOS:
-        return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
-
-    case SBM_GETPOS16:
-    case SBM_GETPOS:
-        return GetScrollPos( hwnd, SB_CTL );
-
-    case SBM_SETRANGE16:
-        SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
-                          wParam  /* FIXME: Is this correct? */ );
-        return 0;
-
-    case SBM_SETRANGE:
-        {
-            INT oldPos = GetScrollPos( hwnd, SB_CTL );
-            SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
-            if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
-        }
-        return 0;
-
-    case SBM_GETRANGE16:
-        FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
-        return 0;
-
-    case SBM_GETRANGE:
-        GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
-        return 0;
-
-    case SBM_ENABLE_ARROWS16:
-    case SBM_ENABLE_ARROWS:
-        return EnableScrollBar( hwnd, SB_CTL, wParam );
-
-    case SBM_SETRANGEREDRAW:
-        {
-            INT oldPos = GetScrollPos( hwnd, SB_CTL );
-            SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
-            if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
-        }
-        return 0;
-
-    case SBM_SETSCROLLINFO:
-        return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
-
-    case SBM_GETSCROLLINFO:
-        return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
-
-    case 0x00e5:
-    case 0x00e7:
-    case 0x00e8:
-    case 0x00eb:
-    case 0x00ec:
-    case 0x00ed:
-    case 0x00ee:
-    case 0x00ef:
-        ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
-		    message, wParam, lParam );
-        break;
-
-    default:
-        if (message >= WM_USER)
-            WARN("unknown msg %04x wp=%04x lp=%08lx\n",
-			 message, wParam, lParam );
-        return DefWindowProcW( hwnd, message, wParam, lParam );
-    }
-    return 0;
+	/* update the window if frame has changed */
+	if (style != oldStyle)
+	{
+		WIN_SetStyle(hwnd, style);
+		SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
+			SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
+	}
+	return TRUE;
 }
 
 
 /*************************************************************************
  *           SetScrollInfo   (USER32.@)
+ *
  * SetScrollInfo can be used to set the position, upper bound,
  * lower bound, and page size of a scrollbar control.
  *
@@ -1416,200 +1335,150 @@
  *
  * NOTE
  *    For 100 lines of text to be displayed in a window of 25 lines,
- *  one would for instance use info->nMin=0, info->nMax=75
+ *  one would for instance use info->nMin = 0, info->nMax = 75
  *  (corresponding to the 76 different positions of the window on
- *  the text), and info->nPage=25.
+ *  the text), and info->nPage = 25.
  */
-INT WINAPI SetScrollInfo(
-HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
-INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
-const SCROLLINFO *info /* [in] Specifies what to change and new values */,
+INT WINAPI SetScrollInfo( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */, 
+const SCROLLINFO *info /* [in] Specifies what to change and new values */,
 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
 {
-    INT action;
-    INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
+	LPSCROLL_INFO infoPtr;
+	BOOL changed = FALSE; /* only show/hide scrollbar if params change */
+	INT gap, value;
+	UINT oldFlags;
+
+	/* handle invalid data structure */
+	if (SCROLL_INFO_INVALID(info)) return 0;
+	infoPtr = SCROLL_GetScrollInfo(hwnd, nBar);
+	if (!infoPtr) return 0;
+
+	if (TRACE_ON(scroll))
+	{
+		TRACE("hwnd=%04x bar=%d", hwnd, nBar);
+		if (info->fMask & SIF_PAGE) DPRINTF(" page=%d", info->nPage);
+		if (info->fMask & SIF_POS) DPRINTF(" pos=%d", info->nPos);
+		if (info->fMask & SIF_RANGE)
+			DPRINTF(" min=%d max=%d", info->nMin, info->nMax);
+		DPRINTF(" bRedraw=%d\n", bRedraw);
+	}
 
-    if( action & SA_SSI_HIDE )
-	SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
-    else
-    {
-	if( action & SA_SSI_SHOW )
-	    if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
-		return retVal; /* SetWindowPos() already did the painting */
-
-	if( bRedraw && (action & SA_SSI_REFRESH))
-	    SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
-	else if( action & SA_SSI_REPAINT_ARROWS )
-	    SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
-    }
-    return retVal;
-}
-
-INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
-			    const SCROLLINFO *info, INT *action  )
-{
-    /* Update the scrollbar state and set action flags according to
-     * what has to be done graphics wise. */
-
-    SCROLLBAR_INFO *infoPtr;
-    UINT new_flags;
-    BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
-
-   *action = 0;
-
-    if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
-    if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
-    if ((info->cbSize != sizeof(*info)) &&
-        (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
-
-    if (TRACE_ON(scroll))
-    {
-        TRACE("hwnd=%04x bar=%d", hwnd, nBar);
-        if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
-        if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
-        if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
-        DPRINTF("\n");
-    }
-
-    /* Set the page size */
-
-    if (info->fMask & SIF_PAGE)
-    {
-	if( infoPtr->Page != info->nPage )
-	{
-            infoPtr->Page = info->nPage;
-	   *action |= SA_SSI_REFRESH;
-           bChangeParams = TRUE;
-	}
-    }
-
-    /* Set the scroll pos */
-
-    if (info->fMask & SIF_POS)
-    {
-	if( infoPtr->CurVal != info->nPos )
-	{
-	    infoPtr->CurVal = info->nPos;
-	   *action |= SA_SSI_REFRESH;
-	}
-    }
-
-    /* Set the scroll range */
-
-    if (info->fMask & SIF_RANGE)
-    {
-        /* Invalid range -> range is set to (0,0) */
-        if ((info->nMin > info->nMax) ||
-            ((UINT)(info->nMax - info->nMin) >= 0x80000000))
-        {
-            infoPtr->MinVal = 0;
-            infoPtr->MaxVal = 0;
-            bChangeParams = TRUE;
-        }
-        else
-        {
-	    if( infoPtr->MinVal != info->nMin ||
-		infoPtr->MaxVal != info->nMax )
-	    {
-                *action |= SA_SSI_REFRESH;
-                infoPtr->MinVal = info->nMin;
-                infoPtr->MaxVal = info->nMax;
-                bChangeParams = TRUE;
-	    }
-        }
-    }
-
-    /* Make sure the page size is valid */
-
-    if (infoPtr->Page < 0) infoPtr->Page = 0;
-    else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
-        infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
-
-    /* Make sure the pos is inside the range */
-
-    if (infoPtr->CurVal < infoPtr->MinVal)
-        infoPtr->CurVal = infoPtr->MinVal;
-    else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
-        infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
-
-    TRACE("    new values: page=%d pos=%d min=%d max=%d\n",
-		 infoPtr->Page, infoPtr->CurVal,
-		 infoPtr->MinVal, infoPtr->MaxVal );
-
-    /* don't change the scrollbar state if SetScrollInfo
-     * is just called with SIF_DISABLENOSCROLL
-     */
-    if(!(info->fMask & SIF_ALL)) goto done;
-
-    /* Check if the scrollbar should be hidden or disabled */
-
-    if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
-    {
-        new_flags = infoPtr->flags;
-        if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
-        {
-            /* Hide or disable scroll-bar */
-            if (info->fMask & SIF_DISABLENOSCROLL)
-	    {
-                new_flags = ESB_DISABLE_BOTH;
-	       *action |= SA_SSI_REFRESH;
-	    }
-            else if ((nBar != SB_CTL) && bChangeParams)
-	    {
-		*action = SA_SSI_HIDE;
-		goto done;
-            }
-        }
-        else  /* Show and enable scroll-bar */
-        {
-	    new_flags = 0;
-            if ((nBar != SB_CTL) && bChangeParams)
-		*action |= SA_SSI_SHOW;
-        }
-
-        if (infoPtr->flags != new_flags) /* check arrow flags */
-        {
-            infoPtr->flags = new_flags;
-           *action |= SA_SSI_REPAINT_ARROWS;
-        }
-    }
+	/* set the scroll range */
+	if (info->fMask & SIF_RANGE)
+	{
+		if ((info->nMin > info->nMax) ||
+			((UINT)(info->nMax - info->nMin) >= 0x80000000))
+		{
+			/* invalid range -> range is set to (0,0) */
+			changed = ((infoPtr->minVal) || (infoPtr->maxVal));
+			infoPtr->minVal = 0;
+			infoPtr->maxVal = 0;
+		}
+		else if ((infoPtr->minVal != info->nMin) || 
+			(infoPtr->maxVal != info->nMax))
+		{
+			infoPtr->minVal = info->nMin;
+			infoPtr->maxVal = info->nMax;
+			changed = TRUE;
+		}
+	}
+
+	/* determine desired page size */
+	value = infoPtr->page;
+	if ((info->fMask & SIF_PAGE) && (value != info->nPage))
+		value = info->nPage;
+
+	/* make sure the page size is valid */
+	gap = infoPtr->maxVal - infoPtr->minVal + 1;
+	if (value > gap)
+		value = gap;
+	else if (value < 1)
+		value = 1;
+	/* change page if required */
+	if (value != infoPtr->page)
+	{
+		infoPtr->page = value;
+		changed = TRUE;
+	}
+
+	/* set the scroll pos */
+	value = infoPtr->curVal;
+	if ((info->fMask & SIF_POS) && (value != info->nPos))
+		value = info->nPos;
+
+	/* make sure the pos is inside the range */
+	gap = infoPtr->maxVal - infoPtr->page + 1;
+	if (value < infoPtr->minVal)
+		value = infoPtr->minVal;
+	else if (value > gap)
+		value = gap;
+
+	TRACE("    new values: page=%d pos=%d min=%d max=%d\n",
+		 infoPtr->page, value, infoPtr->minVal, infoPtr->maxVal);
+
+	/* determine the activation state */
+	oldFlags = infoPtr->flags;
+	if (!(info->fMask & SIF_ALL))
+		; /* if called without SIF_ALL don't change state */
+	else if (info->fMask & SIF_DISABLENOSCROLL)
+		infoPtr->flags |= ESB_DISABLE_BOTH;
+	else if (changed && (nBar != SB_CTL) &&
+		(info->fMask & (SIF_RANGE | SIF_PAGE)))
+			ShowScrollBar(hwnd, nBar, infoPtr->minVal < gap);
 
-done:
-    /* Return current position */
+	/* change position if required */
+	if (value != infoPtr->curVal)
+	{
+		infoPtr->curVal = value;
+		changed = TRUE;
+	}
+    
+	/* redraw the scroll bar if desired or required */
+	if (WIN_IsWindowDrawable(hwnd, FALSE) &&
+		((infoPtr->flags != oldFlags) ||
+			(bRedraw && changed && (infoPtr->minVal < gap))))
+				SCROLL_RefreshScrollBar(hwnd, nBar, infoPtr);
 
-    return infoPtr->CurVal;
+	return infoPtr->curVal;
 }
 
 
 /*************************************************************************
  *           GetScrollInfo   (USER32.@)
- * GetScrollInfo can be used to retrieve the position, upper bound,
+ *
+ * GetScrollInfo can be used to retrieve the position, upper bound, 
  * lower bound, and page size of a scrollbar control.
  *
  * RETURNS STD
  */
-BOOL WINAPI GetScrollInfo(
-  HWND hwnd /* [in] Handle of window */ ,
-  INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
-  LPSCROLLINFO info /* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
-{
-    SCROLLBAR_INFO *infoPtr;
-
-    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
-    if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
-    if ((info->cbSize != sizeof(*info)) &&
-        (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
-
-    if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
-    if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
-    if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
-        info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->CurVal;
-    if (info->fMask & SIF_RANGE)
-    {
-	info->nMin = infoPtr->MinVal;
-	info->nMax = infoPtr->MaxVal;
-    }
-    return (info->fMask & SIF_ALL) != 0;
+BOOL WINAPI GetScrollInfo( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */, 
+LPSCROLLINFO info /* [in/out] (fMask specifies which values to retrieve) */)
+{
+	LPSCROLL_INFO infoPtr;
+
+	/* handle invalid data structure */
+	if (SCROLL_INFO_INVALID(info)) return FALSE;
+	infoPtr = SCROLL_GetScrollInfo(hwnd, nBar);
+	if (!infoPtr) return FALSE;
+
+	TRACE("hwnd=%04x nBar=%d info=%p\n", hwnd, nBar, info);
+
+	/* fill in the desired scroll info structure */
+	if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
+	if (info->fMask & SIF_POS) info->nPos =infoPtr->curVal;
+	if (info->fMask & SIF_RANGE)
+	{
+		info->nMin = infoPtr->minVal;
+		info->nMax = infoPtr->maxVal;
+	}
+	if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
+		info->nTrackPos = infoPtr->curVal;
+
+	return (info->fMask & SIF_ALL);
 }
 
 
@@ -1624,23 +1493,25 @@
  *    Note the ambiguity when 0 is returned.  Use GetLastError
  *    to make sure there was an error (and to know which one).
  */
-INT WINAPI SetScrollPos(
-HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
+INT WINAPI SetScrollPos( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
 INT nPos /* [in] New value */,
-BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */ )
+BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
 {
-    SCROLLINFO info;
-    SCROLLBAR_INFO *infoPtr;
-    INT oldPos;
-
-    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
-    oldPos      = infoPtr->CurVal;
-    info.cbSize = sizeof(info);
-    info.nPos   = nPos;
-    info.fMask  = SIF_POS;
-    SetScrollInfo( hwnd, nBar, &info, bRedraw );
-    return oldPos;
+	INT oldPos = GetScrollPos(hwnd, nBar);
+	SCROLLINFO info;
+
+	TRACE("hwnd=%04x nBar=%d nPos=%d bRedraw=%d\n",
+		hwnd, nBar, nPos, bRedraw);
+
+	/* fill in an info structure and use common set info code */
+	info.cbSize = sizeof(info);
+	info.nPos   = nPos;
+	info.fMask  = SIF_POS;
+	SetScrollInfo(hwnd, nBar, &info, bRedraw);
+	
+	return oldPos; 
 }
 
 
@@ -1649,20 +1520,21 @@
  *
  * RETURNS
  *    Success: Current position
- *    Failure: 0
+ *    Failure: 0   
  *
  * REMARKS
- *    Note the ambiguity when 0 is returned.  Use GetLastError
+ *    There is ambiguity when 0 is returned.  Use GetLastError
  *    to make sure there was an error (and to know which one).
  */
-INT WINAPI GetScrollPos(
-HWND hwnd, /* [in] Handle of window */
+INT WINAPI GetScrollPos( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
 {
-    SCROLLBAR_INFO *infoPtr;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, nBar);
 
-    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
-    return infoPtr->CurVal;
+	TRACE("hwnd=%04x nBar=%d\n", hwnd, nBar);
+    
+	return info ? info->curVal: 0;
 }
 
 
@@ -1671,58 +1543,26 @@
  *
  * RETURNS STD
  */
-BOOL WINAPI SetScrollRange(
-HWND hwnd, /* [in] Handle of window whose scrollbar will be affected */
-INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
-INT MinVal, /* [in] New minimum value */
-INT MaxVal, /* [in] New maximum value */
+BOOL WINAPI SetScrollRange( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
+INT minVal /* [in] New minimum value */,
+INT maxVal /* [in] New maximum value */,
 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
 {
-    SCROLLINFO info;
+	SCROLLINFO info;
 
-    info.cbSize = sizeof(info);
-    info.nMin   = MinVal;
-    info.nMax   = MaxVal;
-    info.fMask  = SIF_RANGE;
-    SetScrollInfo( hwnd, nBar, &info, bRedraw );
-    return TRUE;
-}
+	TRACE("hwnd=%04x nBar=%d minVal=%d maxVal=%d bRedraw=%d\n",
+		hwnd, nBar, minVal, maxVal, bRedraw);
 
+	/* fill in an info structure and use common set info code */
+	info.cbSize = sizeof(info);
+	info.nMin   = minVal;
+	info.nMax   = maxVal;
+	info.fMask  = SIF_RANGE;
+	SetScrollInfo(hwnd, nBar, &info, bRedraw);
 
-/*************************************************************************
- *	     SCROLL_SetNCSbState
- *
- * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
- */
-INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
-                        int hMin, int hMax, int hPos)
-{
-    INT vA, hA;
-    SCROLLINFO vInfo, hInfo;
-
-    vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
-    vInfo.nMin   = vMin;
-    vInfo.nMax   = vMax;
-    vInfo.nPos   = vPos;
-    hInfo.nMin   = hMin;
-    hInfo.nMax   = hMax;
-    hInfo.nPos   = hPos;
-    vInfo.fMask  = hInfo.fMask = SIF_RANGE | SIF_POS;
-
-    SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, &vA );
-    SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, &hA );
-
-    if( !SCROLL_ShowScrollBar( hwnd, SB_BOTH,
-			      (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
-    {
-	/* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
-	if( vA & SA_SSI_REFRESH )
-	    SCROLL_RefreshScrollBar( hwnd, SB_VERT, FALSE, TRUE );
-
-	if( hA & SA_SSI_REFRESH )
-	    SCROLL_RefreshScrollBar( hwnd, SB_HORZ, FALSE, TRUE );
-    }
-    return 0;
+	return TRUE;
 }
 
 
@@ -1731,138 +1571,70 @@
  *
  * RETURNS STD
  */
-BOOL WINAPI GetScrollRange(
-HWND hwnd, /* [in] Handle of window */
-INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL  */
-LPINT lpMin, /* [out] Where to store minimum value */
+BOOL WINAPI GetScrollRange( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL  */,
+LPINT lpMin /* [out] Where to store minimum value */,
 LPINT lpMax /* [out] Where to store maximum value */)
 {
-    SCROLLBAR_INFO *infoPtr;
+	LPSCROLL_INFO info = SCROLL_GetScrollInfo(hwnd, nBar);
 
-    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
-    {
-        if (lpMin) lpMin = 0;
-        if (lpMax) lpMax = 0;
-        return FALSE;
-    }
-    if (lpMin) *lpMin = infoPtr->MinVal;
-    if (lpMax) *lpMax = infoPtr->MaxVal;
-    return TRUE;
+	TRACE("hwnd=%04x nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
+    
+	if (lpMin) *lpMin = info ? info->minVal : 0;
+	if (lpMax) *lpMax = info ? info->maxVal : 0;
+    
+	return (BOOL)info;
 }
 
 
 /*************************************************************************
- *           SCROLL_ShowScrollBar()
- *
- * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
- */
-BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
-			     BOOL fShowH, BOOL fShowV )
-{
-    LONG style = GetWindowLongW( hwnd, GWL_STYLE );
-
-    TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
-                    hwnd, nBar, fShowH, fShowV );
-
-    switch(nBar)
-    {
-    case SB_CTL:
-        ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
-        return TRUE;
-
-    case SB_BOTH:
-    case SB_HORZ:
-        if (fShowH)
-        {
-            fShowH = !(style & WS_HSCROLL);
-            style |= WS_HSCROLL;
-        }
-        else  /* hide it */
-        {
-            fShowH = (style & WS_HSCROLL);
-            style &= ~WS_HSCROLL;
-        }
-        if( nBar == SB_HORZ ) {
-            fShowV = FALSE;
-            break;
-        }
-	/* fall through */
-
-    case SB_VERT:
-        if (fShowV)
-        {
-            fShowV = !(style & WS_VSCROLL);
-            style |= WS_VSCROLL;
-        }
-	else  /* hide it */
-        {
-            fShowV = (style & WS_VSCROLL);
-            style &= ~WS_VSCROLL;
-        }
-        if ( nBar == SB_VERT )
-           fShowH = FALSE;
-        break;
-
-    default:
-        return FALSE;  /* Nothing to do! */
-    }
-
-    if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
-    {
-        WIN_SetStyle( hwnd, style );
-	SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
-                    | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
-        return TRUE;
-    }
-    return FALSE; /* no frame changes */
-}
-
-
-/*************************************************************************
- *           ShowScrollBar   (USER32.@)
+ *           EnableScrollBar   (USER32.@)
  *
  * RETURNS STD
  */
-BOOL WINAPI ShowScrollBar(
-HWND hwnd, /* [in] Handle of window whose scrollbar(s) will be affected   */
-INT nBar, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
-BOOL fShow /* [in] TRUE = show, FALSE = hide  */)
-{
-    SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
-                                      (nBar == SB_HORZ) ? 0 : fShow );
-    return TRUE;
-}
-
-
-/*************************************************************************
- *           EnableScrollBar   (USER32.@)
- */
-BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
+BOOL WINAPI EnableScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT nBar /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */,
+UINT flags /* [in] Flags indicating which scroll bars to enable */)
 {
-    BOOL bFineWithMe;
-    SCROLLBAR_INFO *infoPtr;
+	BOOL ret = TRUE;
+	LPSCROLL_INFO info;
 
-    TRACE("%04x %d %d\n", hwnd, nBar, flags );
+	TRACE("hwnd=%04x nBar=%d flags=%04x\n", hwnd, nBar, flags);
 
-    flags &= ESB_DISABLE_BOTH;
-
-    if (nBar == SB_BOTH)
-    {
-	if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
-	if (!(bFineWithMe = (infoPtr->flags == flags)) )
+	/* use recursion to handle the case of two scroll bars */
+	if (nBar == SB_BOTH)
 	{
-	    infoPtr->flags = flags;
-	    SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
+		ret = EnableScrollBar(hwnd, SB_VERT, flags);
+		nBar = SB_HORZ;
 	}
-	nBar = SB_HORZ;
-    }
-    else
-	bFineWithMe = TRUE;
 
-    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
-    if (bFineWithMe && infoPtr->flags == flags) return FALSE;
-    infoPtr->flags = flags;
+	/* change the enable flags of the bar and redraw if necessary */
+	flags &= ~ESB_DISABLE_BOTH;
+	info = SCROLL_GetScrollInfo(hwnd, nBar);
+	ret = ret && info && (info->flags != flags);
+	if (ret)
+	{
+		info->flags = flags;
+		if (WIN_IsWindowDrawable(hwnd, FALSE))
+			SCROLL_RefreshScrollBar(hwnd, nBar, info);
+	}
 
-    SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
-    return TRUE;
+	return ret;
 }
+
+
+/*********************************************************************
+ * scrollbar class descriptor
+ */
+const struct builtin_class_descr SCROLL_builtin_class =
+{
+	"ScrollBar",         /* name */
+	CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
+	NULL,                /* procA (winproc is Unicode only) */
+	ScrollBarWndProc,    /* procW */
+	sizeof(SCROLL_INFO), /* extra */
+	IDC_ARROWA,          /* cursor */
+	0                    /* brush */
+};





More information about the wine-patches mailing list