Index: win32ss/user/ntuser/nonclient.c
===================================================================
--- win32ss/user/ntuser/nonclient.c	(revision 74115)
+++ win32ss/user/ntuser/nonclient.c	(working copy)
@@ -1171,7 +1171,8 @@
    LRESULT Result = 0;
    SIZE WindowBorders;
    RECT OrigRect;
-   DWORD Style = Wnd->style;
+   LONG Style = Wnd->style;
+   LONG  exStyle = Wnd->ExStyle; 
 
    if (Rect == NULL)
    {
@@ -1239,83 +1240,30 @@
          RECTL_vInflateRect(Rect, -2 * UserGetSystemMetrics(SM_CXBORDER), -2 * UserGetSystemMetrics(SM_CYBORDER));
       }
 
-      if (Wnd->style & (WS_VSCROLL | WS_HSCROLL))
+      if (Style & WS_VSCROLL)
       {
-        SCROLLBARINFO sbi;
-        SETSCROLLBARINFO ssbi;
+         if (Rect->right - Rect->left >= UserGetSystemMetrics(SM_CXVSCROLL))
+         {
+             Wnd->state |= WNDS_HASVERTICALSCROOLLBAR;
 
-        sbi.cbSize = sizeof(SCROLLBARINFO);
-        if ((Style & WS_VSCROLL) && co_IntGetScrollBarInfo(Wnd, OBJID_VSCROLL, &sbi))
-        {
-          int i;
-          LONG sx = Rect->right;
+             /* rectangle is in screen coords when wparam is false */
+             if (!wparam && (exStyle & WS_EX_LAYOUTRTL)) exStyle ^= WS_EX_LEFTSCROLLBAR;
 
-          Wnd->state |= WNDS_HASVERTICALSCROOLLBAR;
-
-          sx -= UserGetSystemMetrics(SM_CXVSCROLL);
-
-          for (i = 0; i <= CCHILDREN_SCROLLBAR; i++)
-              ssbi.rgstate[i] = sbi.rgstate[i];
-
-          if (sx <= Rect->left)
-             ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
-          else
-             ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN;
-
-          co_IntSetScrollBarInfo(Wnd, OBJID_VSCROLL, &ssbi);
-
-          if (ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN)
-             Style &= ~WS_VSCROLL;
-        }
-        else
-          Style &= ~WS_VSCROLL;
-
-        if ((Style & WS_HSCROLL) && co_IntGetScrollBarInfo(Wnd, OBJID_HSCROLL, &sbi))
-        {
-          int i;
-          LONG sy = Rect->bottom;
-
-          Wnd->state |= WNDS_HASHORIZONTALSCROLLBAR;
-
-          sy -= UserGetSystemMetrics(SM_CYHSCROLL);
-
-          for (i = 0; i <= CCHILDREN_SCROLLBAR; i++)
-              ssbi.rgstate[i] = sbi.rgstate[i];
-
-          if (sy <= Rect->top)
-             ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
-          else
-             ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN;
-
-          co_IntSetScrollBarInfo(Wnd, OBJID_HSCROLL, &ssbi);
-
-          if (ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN)
-             Style &= ~WS_HSCROLL;
-        }
-        else
-          Style &= ~WS_HSCROLL;
+             if((exStyle & WS_EX_LEFTSCROLLBAR) != 0)
+                 Rect->left  += UserGetSystemMetrics(SM_CXVSCROLL);
+             else
+                 Rect->right -= UserGetSystemMetrics(SM_CXVSCROLL);
+          }
       }
 
-      if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL))
+      if (Style & WS_HSCROLL)
       {
-         if ((Wnd->ExStyle & WS_EX_LEFTSCROLLBAR) != 0)
-            Rect->left += UserGetSystemMetrics(SM_CXVSCROLL);
-         else
-            Rect->right -= UserGetSystemMetrics(SM_CXVSCROLL);
+         if( Rect->bottom - Rect->top > UserGetSystemMetrics(SM_CYHSCROLL))
+         {
+              Wnd->state |= WNDS_HASHORIZONTALSCROLLBAR;
 
-         Rect->bottom -= UserGetSystemMetrics(SM_CYHSCROLL);
-      }
-      else
-      {
-         if (Style & WS_VSCROLL)
-         {
-            if ((Wnd->ExStyle & WS_EX_LEFTSCROLLBAR) != 0)
-               Rect->left += UserGetSystemMetrics(SM_CXVSCROLL);
-            else
-               Rect->right -= UserGetSystemMetrics(SM_CXVSCROLL);
+              Rect->bottom -= UserGetSystemMetrics(SM_CYHSCROLL);
          }
-         else if (Style & WS_HSCROLL)
-            Rect->bottom -= UserGetSystemMetrics(SM_CYHSCROLL);
       }
 
       if (Rect->top > Rect->bottom)
Index: win32ss/user/ntuser/scrollbar.c
===================================================================
--- win32ss/user/ntuser/scrollbar.c	(revision 74115)
+++ win32ss/user/ntuser/scrollbar.c	(working copy)
@@ -358,6 +358,106 @@
   return (Mask & SIF_ALL) !=0;
 }
 
+/*************************************************************************
+ *           SCROLL_GetScrollBarInfo
+ *
+ * Internal helper for the API function
+ *
+ * PARAMS
+ *    hwnd     [I]  Handle of window with scrollbar(s)
+ *    idObject [I]  One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
+ *    info     [IO] cbSize specifies the size of the structure
+ *
+ * RETURNS
+ *    FALSE if failed
+ */
+#if 0
+static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
+{
+    LPSCROLLBAR_INFO infoPtr;
+    INT nBar;
+    INT nDummy;
+    DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
+    BOOL pressed;
+    RECT rect;
+
+    switch (idObject)
+    {
+        case OBJID_CLIENT: nBar = SB_CTL; break;
+        case OBJID_HSCROLL: nBar = SB_HORZ; break;
+        case OBJID_VSCROLL: nBar = SB_VERT; break;
+        default: return FALSE;
+    }
+
+    /* handle invalid data structure */
+    if (info->cbSize != sizeof(*info))
+        return FALSE;
+
+    SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
+                            &info->dxyLineButton, &info->xyThumbTop);
+    /* rcScrollBar needs to be in screen coordinates */
+    GetWindowRect(hwnd, &rect);
+    OffsetRect(&info->rcScrollBar, rect.left, rect.top);
+
+    info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
+
+    infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
+    if (!infoPtr)
+        return FALSE;
+
+    /* Scroll bar state */
+    info->rgstate[0] = 0;
+    if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
+        || (nBar == SB_VERT && !(style & WS_VSCROLL)))
+        info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
+    if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
+    {
+        if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
+            info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
+        else
+            info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
+    }
+    if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
+        info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
+    
+    pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
+    
+    /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
+    info->rgstate[1] = 0;
+    if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
+        info->rgstate[1] |= STATE_SYSTEM_PRESSED;
+    if (infoPtr->flags & ESB_DISABLE_LTUP)
+        info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
+
+    /* Page up/left region state. MSDN says up/right, but I don't believe it */
+    info->rgstate[2] = 0;
+    if (infoPtr->curVal == infoPtr->minVal)
+        info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
+    if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
+        info->rgstate[2] |= STATE_SYSTEM_PRESSED;
+
+    /* Thumb state */
+    info->rgstate[3] = 0;
+    if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
+        info->rgstate[3] |= STATE_SYSTEM_PRESSED;
+
+    /* Page down/right region state. MSDN says down/left, but I don't believe it */
+    info->rgstate[4] = 0;
+    if (infoPtr->curVal >= infoPtr->maxVal - 1)
+        info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
+    if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
+        info->rgstate[4] |= STATE_SYSTEM_PRESSED;
+    
+    /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
+    info->rgstate[5] = 0;
+    if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
+        info->rgstate[5] |= STATE_SYSTEM_PRESSED;
+    if (infoPtr->flags & ESB_DISABLE_RTDN)
+        info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
+        
+    return TRUE;
+}
+#endif
 static DWORD FASTCALL
 co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
 {
@@ -575,6 +675,21 @@
    IntGetScrollBarRect(Window, Bar, &(sbi->rcScrollBar));
    IntCalculateThumb(Window, Bar, sbi, pSBData);
 
+    /* Scroll bar state */
+    psbi->rgstate[0] = 0;
+    if ((Bar == SB_HORZ && !(Window->style & WS_HSCROLL))
+        || (Bar == SB_VERT && !(Window->style & WS_VSCROLL)))
+        psbi->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
+    if (pSBData->posMin >= pSBData->posMax - max(pSBData->page - 1, 0))
+    {
+        if (!(psbi->rgstate[0] & STATE_SYSTEM_INVISIBLE))
+            psbi->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
+        else
+            psbi->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
+    }
+    if (Bar == SB_CTL && !(Window->style & WS_DISABLED))
+        psbi->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
+
    RtlCopyMemory(psbi, sbi, sizeof(SCROLLBARINFO));
 
    return TRUE;
