Release 940201

Tue Feb  1 21:14:47 1994  Bob Amstadt  (bob@pooh)

	* [loader/selector.c]
	Added function CreateNewSegments().  Modified IPCCopySelector
	to allow aliasing to any arbitrary memory space.

	* [memory/global.c]
	Fixed potential bug in GlobalGetFreeSegments().

	* [memory/linear.c]
	Created functions GlobalLinearLock() and GlobalLinearUnlock().

Tue Feb  1 05:51:43 1994  julliard@di.epfl.ch (Alexandre Julliard)

	* [controls/widgets.c]
	Removed CAPTION window class.

	* [loader/cursor.c]
	Bug fix in LoadCursor(): don't allocate memory every time for
	built-in cursors.

	* [windows/clipping.c]
	Invalidate child windows in InvalidateRgn().

	* [windows/defwnd.c]
	Added repaint of the caption when changing window text.

	* [windows/event.c]
	Modified SetCapture() to allow keyboard events while capturing.

	* [windows/message.c]
	New function MSG_GetHardwareMessage(), to do mouse tracking
	without returning control to the Windows program.

	* [windows/nonclient.c]
	A couple of changes in frame drawing for DLGMODALFRAME windows.
	Rewritten window moving code, to use MSG_GetHardwareMessage()
	instead of non-client mouse events (this is the way Windows
	does it), and to send WM_ENTERSIZEMOVE messages.
	Removed WM_NCBUTTONUP and WM_NCMOUSEMOVE handlers.

	* [windows/win.c]
	Allocate temporary structures on the USER heap instead of
	using GlobalAlloc().

	* [windows/winpos.c]
	Added function WINPOS_GetMinMaxInfo() to get sizing informations.

Jan 31, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [windows/nonclient.c]
	Call to StdDrawScrollBar() during NC's drawing.
	Call to NC_ScrollBarButtonDown() on NC mouse events WM_LBUTTONDOWN.
	Call to NC_ScrollBarButtonUp() on NC mouse events WM_LBUTTONUP.
	Call to NC_ScrollBarMouseMove() on NC mouse events WM_MOUSEMOVE.

	* [controls/menu.c]
	New GetSubMenu() function.
	Move GetMenu() & SetMenu() functions from 'windows/win.c'.

	* [controls/listbox.c]
	Start changes to satisfy recent changes in scrollbars/windows.

	* [loader/resource.c]
	Put some code in LoadAccelerators() stub.
	New TranslateAccelerator() function.

	* [windows/win.c]
	Remove GetMenu() & SetMenu() functions.
	Call to NC_CreateScrollBars() if required by CreateWindow().

Mon Jan 24 10:40:10 EST 1994 John Richardson (jrichard@cs.uml.edu)

        * [window/win.c]
        Added functions EnumWindows, EnumChildWindows, and helper
        WIN_EnumChildWin.  EnumWindows won't list all wine windows
        because GetDesktopWindow isn't complete.  However, the code
        is in place for it to work correctly and only needs 
        GetDesktopWindow to do so.  

Tue Jan 25 05:51:47 1994  julliard@di.epfl.ch (Alexandre Julliard)

	* [windows/defwnd.c]
	Added handling of activation messages (WM_ACTIVATE,
	WM_NCACTIVATE, WM_MOUSEACTIVATE)

	* [windows/event.c]
	De-activate the window when losing input focus.

	* [windows/focus.c]
	Bug fix in SetFocus().

	* [windows/message.c]
	Added activation of the window on mouse-clicks.

	* [windows/nonclient.c]
	Changed non-client area painting to use the correct colors
	depending upon the activation state.
	Added WM_NCACTIVATE message handling.
	Fixed a couple of bugs in window moving and resizing.

	* [windows/winpos.c]
	Implemented Get/SetActiveWindow().
	Implemented SWP_NOACTIVATE flag in SetWindowPos().

Jan 17, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [misc/message.c]
	MessageBox has a CaptionBar for his title except for
		MB_SYSTEMMODAL with MB_ICONHAND.

	* [windows/nonclient.c]
	Call to NC_TrackSysMenu on SysMenu button mouse click.

	* [windows/defwnd.c]
	Call to NC_TrackSysMenu on Alt key (VK_MENU).

	* [controls/menu.c]
	New GetSystemMenu() function.
	New CopySystemMenu() internal function.
	New NC_TrackSysMenu() internal function.

	* [include/windows.h]
	New WM_INITMENU, WM_INITMENUPOPUP, WM_MENUSELECT & WM_MENUCHAR defines.
diff --git a/controls/Imakefile b/controls/Imakefile
index aee3e14..22fb4af 100644
--- a/controls/Imakefile
+++ b/controls/Imakefile
@@ -3,30 +3,24 @@
 MODULE = controls
 
 SRCS = \
-	menu.c \
-	widgets.c \
 	button.c \
-	scroll.c \
-	listbox.c \
+	caption.c \
 	combo.c \
+	listbox.c \
+	menu.c \
+	scroll.c \
 	static.c \
-	SmeMenuButto.c \
-	WinLabel.c \
-	WinCommand.c \
-	WinMenuButto.c
+	widgets.c
 
 OBJS = \
-	menu.o \
-	widgets.o \
 	button.o \
-	scroll.o \
-	listbox.o \
+	caption.o \
 	combo.o \
+	listbox.o \
+	menu.o \
+	scroll.o \
 	static.o \
-	SmeMenuButto.o \
-	WinLabel.o \
-	WinCommand.o \
-	WinMenuButto.o
+	widgets.o
 
 WineRelocatableTarget($(TOP)/$(MODULE),,$(OBJS))
 DependTarget()
diff --git a/controls/button.c b/controls/button.c
index aad2aa1..7ecd9db 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -512,8 +512,8 @@
     FillRect(hDC, &rc, hBrush);
 
     textlen = GetWindowTextLength(hWnd);
-    hText = LocalAlloc(LMEM_MOVEABLE, textlen+1);
-    text = LocalLock(hText);
+    hText = USER_HEAP_ALLOC(0, textlen+1);
+    text = USER_HEAP_ADDR(hText);
     GetWindowText(hWnd, text, textlen+1);
     GetTextMetrics(hDC, &tm);
 
@@ -555,8 +555,7 @@
 	DrawFocusRect(hDC, &rc);
     }
 
-    LocalUnlock(hText);
-    LocalFree(hText);
+    USER_HEAP_FREE(hText);
     GlobalUnlock(hWnd);
     EndPaint(hWnd, &ps);
 }
@@ -725,8 +724,8 @@
     FillRect(hDC, &rc, hBrush);
 
     textlen = GetWindowTextLength(hWnd);
-    hText = LocalAlloc(LMEM_MOVEABLE, textlen+1);
-    text = LocalLock(hText);
+    hText = USER_HEAP_ALLOC(0, textlen+1);
+    text = USER_HEAP_ADDR(hText);
     GetWindowText(hWnd, text, textlen+1);
     GetTextMetrics(hDC, &tm);
 
@@ -760,8 +759,7 @@
 	DrawFocusRect(hDC, &rc);
     }
 
-    LocalUnlock(hText);
-    LocalFree(hText);
+    USER_HEAP_FREE(hText);
     GlobalUnlock(hWnd);
     EndPaint(hWnd, &ps);
 }
@@ -900,8 +898,8 @@
     FillRect(hDC, &rc, hBrush);
 
     textlen = GetWindowTextLength(hWnd);
-    hText = LocalAlloc(LMEM_MOVEABLE, textlen+1);
-    text = LocalLock(hText);
+    hText = USER_HEAP_ALLOC(0, textlen+1);
+    text = USER_HEAP_ADDR(hText);
     GetWindowText(hWnd, text, textlen+1);
     GetTextExtentPoint(hDC, text, textlen, &size);
 
@@ -913,8 +911,7 @@
     rc.bottom = size.cy;
     DrawText(hDC, text, textlen, &rc, DT_SINGLELINE);
 
-    LocalUnlock(hText);
-    LocalFree(hText);
+    USER_HEAP_FREE(hText);
     EndPaint(hWnd, &ps);
 }
 
diff --git a/controls/combo.c b/controls/combo.c
index f4af8dc..2bcde7f 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -66,9 +66,15 @@
 	lphc->hWndDrop = CreateWindow("BUTTON", "", 
         	WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | BS_OWNERDRAW,
         	width - 16, 0, 16, 16, hwnd, 1, wndPtr->hInstance, 0L);
-	lphc->hWndEdit = CreateWindow("STATIC", "", 
-        	WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
-        	0, 0, width - 16, 16, hwnd, 1, wndPtr->hInstance, 0L);
+        if (wndPtr->dwStyle & CBS_SIMPLE)
+/*	    lphc->hWndEdit = CreateWindow("EDIT", "", */
+	    lphc->hWndEdit = CreateWindow("STATIC", "", 
+		WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
+		0, 0, width - 16, 16, hwnd, 1, wndPtr->hInstance, 0L);
+	else
+	    lphc->hWndEdit = CreateWindow("STATIC", "", 
+		WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
+		0, 0, width - 16, 16, hwnd, 1, wndPtr->hInstance, 0L);
 	lphc->hWndLBox = CreateWindow("LISTBOX", "", 
         	WS_CHILD | WS_CLIPCHILDREN | WS_BORDER | WS_VSCROLL | LBS_NOTIFY,
         	wndPtr->rectClient.left, wndPtr->rectClient.top + 16, width, height, 
@@ -128,7 +134,7 @@
             switch(HIWORD(lParam))
         	{
         	case LBN_SELCHANGE:
-		    lphc->dwState = lphc->dwState & (CB_SHOWDROPDOWN ^ 0xFFFF);
+		    lphc->dwState = lphc->dwState & (CB_SHOWDROPDOWN ^ 0xFFFFFFFFL);
 		    ShowWindow(lphc->hWndLBox, SW_HIDE);
 		    y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
 		    if (y != LB_ERR) {
diff --git a/controls/listbox.c b/controls/listbox.c
index b1dfb73..642d47e 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -79,11 +79,11 @@
 	else
 	    lphl->hWndLogicParent = GetParent(hwnd);
 	lphl->ColumnsWidth = wndPtr->rectClient.right - wndPtr->rectClient.left;
-	if (wndPtr->hWndVScroll != (HWND)NULL) {
+	if (wndPtr->dwStyle & WS_VSCROLL) {
 	    SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
 	    ShowScrollBar(hwnd, SB_VERT, FALSE);
 	    }
-	if (wndPtr->hWndHScroll != (HWND)NULL) {
+	if (wndPtr->dwStyle & WS_HSCROLL) {
 	    SetScrollRange(hwnd, SB_HORZ, 1, 1, TRUE);
 	    ShowScrollBar(hwnd, SB_HORZ, FALSE);
 	    }
@@ -225,7 +225,7 @@
 	        lphl = ListBoxGetStorageHeader(hwnd);
 		if (lphl->FirstVisible > 1) {
 		    lphl->FirstVisible--;
-		    if (wndPtr->hWndVScroll != (HWND)NULL)
+		    if (wndPtr->dwStyle & WS_VSCROLL)
 			SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
 		    InvalidateRect(hwnd, NULL, TRUE);
 		    UpdateWindow(hwnd);
@@ -237,7 +237,7 @@
 	        lphl = ListBoxGetStorageHeader(hwnd);
 		if (lphl->FirstVisible < lphl->ItemsCount) {
 		    lphl->FirstVisible++;
-		    if (wndPtr->hWndVScroll != (HWND)NULL)
+		    if (wndPtr->dwStyle & WS_VSCROLL)
 			SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
 		    InvalidateRect(hwnd, NULL, TRUE);
 		    UpdateWindow(hwnd);
@@ -310,7 +310,7 @@
 	if ((wndPtr->dwStyle & LBS_MULTIPLESEL) != LBS_MULTIPLESEL) {
 	    ListBoxSetCurSel(hwnd, lphl->ItemFocused);
 	    }
-	if (wndPtr->hWndVScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_VSCROLL)
 	    SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
         InvalidateRect(hwnd, NULL, TRUE);
         UpdateWindow(hwnd);
@@ -419,7 +419,7 @@
         printf("ListBox LB_SETTOPINDEX wParam=%x !\n", wParam);
         lphl = ListBoxGetStorageHeader(hwnd);
 	lphl->FirstVisible = wParam;
-	if (wndPtr->hWndVScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_VSCROLL)
 	    SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
 	InvalidateRect(hwnd, NULL, TRUE);
 	UpdateWindow(hwnd);
@@ -482,10 +482,10 @@
 		    MAKELONG(hwnd, CTLCOLOR_LISTBOX));
 	if (hBrush == (HBRUSH)NULL)  hBrush = GetStockObject(WHITE_BRUSH);
 	GetClientRect(hwnd, &rect);
-	if ((wndPtr->hWndVScroll != (HWND)NULL) &&
-	    IsWindowVisible(wndPtr->hWndVScroll)) rect.right -= 16;
-	if ((wndPtr->hWndHScroll != (HWND)NULL) &&
-	    IsWindowVisible(wndPtr->hWndHScroll)) rect.bottom -= 16;
+/*
+	if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
+	if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
+*/
 	FillRect(hdc, &rect, hBrush);
 	maxwidth = rect.right;
 	rect.right = lphl->ColumnsWidth;
@@ -531,9 +531,11 @@
 EndOfPaint:
     EndPaint( hwnd, &ps );
     if ((lphl->ItemsCount > lphl->ItemsVisible) &
-	(wndPtr->hWndVScroll != (HWND)NULL)) {
+	(wndPtr->dwStyle & WS_VSCROLL)) {
+/*
         InvalidateRect(wndPtr->hWndVScroll, NULL, TRUE);
         UpdateWindow(wndPtr->hWndVScroll);
+*/
  	}
 }
 
@@ -563,10 +565,8 @@
 		    MAKELONG(hwnd, CTLCOLOR_LISTBOX));
 	if (hBrush == (HBRUSH)NULL)  hBrush = GetStockObject(WHITE_BRUSH);
 	GetClientRect(hwnd, &rect);
-	if ((wndPtr->hWndVScroll != (HWND)NULL) &&
-	    IsWindowVisible(wndPtr->hWndVScroll)) rect.right -= 16;
-	if ((wndPtr->hWndHScroll != (HWND)NULL) &&
-	    IsWindowVisible(wndPtr->hWndHScroll)) rect.bottom -= 16;
+	if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
+	if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
 	FillRect(hdc, &rect, hBrush);
 	maxwidth = rect.right;
 	rect.right = lphl->ColumnsWidth;
@@ -612,9 +612,11 @@
 EndOfPaint:
     EndPaint( hwnd, &ps );
     if ((lphl->ItemsCount > lphl->ItemsVisible) &
-	(wndPtr->hWndVScroll != (HWND)NULL)) {
+	(wndPtr->dwStyle & WS_VSCROLL)) {
+/*
         InvalidateRect(wndPtr->hWndVScroll, NULL, TRUE);
         UpdateWindow(wndPtr->hWndVScroll);
+*/
         }
 }
 
@@ -634,10 +636,8 @@
     lpls = lphl->lpFirst;
     if (lpls == NULL) return LB_ERR;
     GetClientRect(hwnd, &rect);
-    if ((wndPtr->hWndVScroll != (HWND)NULL) &&
-	IsWindowVisible(wndPtr->hWndVScroll)) rect.right -= 16;
-    if ((wndPtr->hWndHScroll != (HWND)NULL) &&
-	IsWindowVisible(wndPtr->hWndHScroll)) rect.bottom -= 16;
+    if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
+    if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
     h = w2 = 0;
     w = lphl->ColumnsWidth;
     for(i = 1; i <= lphl->ItemsCount; i++) {
@@ -720,10 +720,10 @@
     lplsnew->dis.itemID = lphl->ItemsCount;
     lplsnew->dis.itemData = (DWORD)newstr;
     lplsnew->hData = hTemp;
-    if (wndPtr->hWndVScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_VSCROLL)
 	SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, 
 	    (lphl->FirstVisible != 1));
-    if (wndPtr->hWndHScroll != (HWND)NULL && lphl->ItemsPerColumn != 0)
+    if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
 	SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible / 
 	    lphl->ItemsPerColumn + 1, (lphl->FirstVisible != 1));
     if (lphl->FirstVisible >= (lphl->ItemsCount - lphl->ItemsVisible)) {
@@ -731,9 +731,9 @@
         UpdateWindow(hwnd);
         }
     if ((lphl->ItemsCount - lphl->FirstVisible) == lphl->ItemsVisible) {
-	if (wndPtr->hWndVScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_VSCROLL)
 	    ShowScrollBar(hwnd, SB_VERT, TRUE);
-	if (wndPtr->hWndHScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_HSCROLL)
 	    ShowScrollBar(hwnd, SB_HORZ, TRUE);
 	}
     return lphl->ItemsCount;
@@ -779,17 +779,17 @@
     lplsnew->dis.itemID = lphl->ItemsCount;
     lplsnew->dis.itemData = (DWORD)newstr;
     lplsnew->hData = hTemp;
-   if (wndPtr->hWndVScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_VSCROLL)
 	SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, 
 	    (lphl->FirstVisible != 1));
-    if (wndPtr->hWndHScroll != (HWND)NULL && lphl->ItemsPerColumn != 0)
+    if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
 	SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible / 
 	    lphl->ItemsPerColumn + 1, (lphl->FirstVisible != 1));
     if (((lphl->ItemsCount - lphl->FirstVisible) == lphl->ItemsVisible) && 
         (lphl->ItemsVisible != 0)) {
-	if (wndPtr->hWndVScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_VSCROLL)
 	    ShowScrollBar(hwnd, SB_VERT, TRUE);
-	if (wndPtr->hWndHScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_HSCROLL)
 	    ShowScrollBar(hwnd, SB_HORZ, TRUE);
 	}
     if ((lphl->FirstVisible <= uIndex) &&
@@ -851,15 +851,15 @@
     lphl->ItemsCount--;
     if (lpls->hData != 0) USER_HEAP_FREE(lpls->hData);
     if (lpls->hMem != 0) USER_HEAP_FREE(lpls->hMem);
-    if (wndPtr->hWndVScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_VSCROLL)
 	SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
-    if (wndPtr->hWndHScroll != (HWND)NULL && lphl->ItemsPerColumn != 0)
+    if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
 	SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible / 
 	    lphl->ItemsPerColumn + 1, TRUE);
     if (lphl->ItemsCount < lphl->ItemsVisible) {
-	if (wndPtr->hWndVScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_VSCROLL)
 	    ShowScrollBar(hwnd, SB_VERT, FALSE);
-	if (wndPtr->hWndHScroll != (HWND)NULL)
+	if (wndPtr->dwStyle & WS_HSCROLL)
 	    ShowScrollBar(hwnd, SB_HORZ, FALSE);
 	}
     if ((lphl->FirstVisible <= uIndex) &&
@@ -922,14 +922,14 @@
 	SendMessage(wndPtr->hwndParent, WM_COMMAND, 
     	    wndPtr->wIDmenu, MAKELONG(hwnd, LBN_SELCHANGE));
 
-    if (wndPtr->hWndVScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_VSCROLL)
 	SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
-    if (wndPtr->hWndHScroll != (HWND)NULL && lphl->ItemsPerColumn != 0)
+    if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
 	SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible / 
 	    lphl->ItemsPerColumn + 1, TRUE);
-    if (wndPtr->hWndVScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_VSCROLL)
 	ShowScrollBar(hwnd, SB_VERT, FALSE);
-    if (wndPtr->hWndHScroll != (HWND)NULL)
+    if (wndPtr->dwStyle & WS_HSCROLL)
 	ShowScrollBar(hwnd, SB_HORZ, FALSE);
     InvalidateRect(hwnd, NULL, TRUE);
     UpdateWindow(hwnd);
diff --git a/controls/menu.c b/controls/menu.c
index 8c43e6f..add8f18 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -4,18 +4,26 @@
 
 /*
 #define DEBUG_MENU
+#define DEBUG_SYSMENU
 */
 #define USE_POPUPMENU
 
 #include <X11/Intrinsic.h>
 #include <X11/StringDefs.h>
 #include "windows.h"
+#include "sysmetrics.h"
 #include "menu.h"
 #include "heap.h"
 #include "win.h"
 #include "bitmaps/check_bitmap"
 #include "bitmaps/nocheck_bitmap"
 
+#define SC_ABOUTWINE     SC_SCREENSAVE+1
+#define SC_SYSMENU	 SC_SCREENSAVE+2
+#define SC_ABOUTWINEDLG	 SC_SCREENSAVE+3
+
+extern HINSTANCE hSysRes;
+HMENU	hSysMenu = 0;
 HBITMAP hStdCheck = 0;
 HBITMAP hStdMnArrow = 0;
 
@@ -40,9 +48,12 @@
 LPSTR GetShortCutString(LPSTR str);
 WORD GetShortCutPos(LPSTR str);
 BOOL HideAllSubPopupMenu(LPPOPUPMENU menu);
+HMENU CopySysMenu();
 WORD * ParseMenuResource(WORD *first_item, int level, HMENU hMenu);
 void SetMenuLogicalParent(HMENU hMenu, HWND hWnd);
 
+BOOL FAR PASCAL AboutWine_Proc(HWND hDlg, WORD msg, WORD wParam, LONG lParam);
+
 /***********************************************************************
  *           PopupMenuWndProc
  */
@@ -98,13 +109,26 @@
 	return 0;
     case WM_COMMAND:
 	lppop = PopupMenuGetWindowAndStorage(hwnd, &wndPtr);
-#ifdef DEBUG_MENU
-    	printf("PopupMenu // push to lower parent WM_COMMAND !\n");
-#endif
-	if (lppop->hWndParent != (HWND)NULL)
+	if (lppop->hWndParent != (HWND)NULL) {
 	    SendMessage(lppop->hWndParent, WM_COMMAND, wParam, lParam);
-	else 
-	    SendMessage(lppop->ownerWnd, WM_COMMAND, wParam, lParam);
+#ifdef DEBUG_MENU
+	    printf("PopupMenu // push to lower parent WM_COMMAND !\n");
+#endif
+	    }
+	else {
+	    if (lppop->SysFlag == 0) {
+		SendMessage(lppop->ownerWnd, WM_COMMAND, wParam, lParam);
+#ifdef DEBUG_MENU
+		printf("PopupMenu // push to Owner WM_COMMAND !\n");
+#endif
+		}
+	    else {
+#ifdef DEBUG_SYSMENU
+		printf("PopupMenu // push to Owner WM_SYSCOMMAND !\n");
+#endif
+		SendMessage(lppop->ownerWnd, WM_SYSCOMMAND, wParam, lParam);
+		}
+	    }
 	if (lppop->BarFlags == 0) ShowWindow(hwnd, SW_HIDE);
     	break;
     case WM_SHOWWINDOW:
@@ -169,16 +193,18 @@
 		GetClientRect(hwnd, &rect);
 		if (lppop->BarFlags != 0) {
 		    y = rect.bottom - rect.top;
+		    GetWindowRect(hwnd, &rect);
+		    y += rect.top;
 		    TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-			lpitem->rect.left, 0, 
-			0, lppop->ownerWnd, (LPRECT)NULL);
+			rect.left + lpitem->rect.left, 
+			y, 0, lppop->ownerWnd, (LPRECT)NULL);
 		    }
 		else {
 		    x = rect.right;
 		    GetWindowRect(hwnd, &rect);
 		    x += rect.left;
 		    TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-			x, lpitem->rect.top,
+			x, rect.top + lpitem->rect.top,
 			0, lppop->ownerWnd, (LPRECT)NULL);
 		    }
 		break;
@@ -199,12 +225,40 @@
 	    if (((lpitem->item_flags & MF_SEPARATOR) != MF_SEPARATOR) &&
 		((lpitem->item_flags & MF_POPUP) != MF_POPUP)) {
 	    	ShowWindow(lppop->hWnd, SW_HIDE);
-		if (lppop->hWndParent != (HWND)NULL)
+		if (lppop->hWndParent != (HWND)NULL) {
 		    SendMessage(lppop->hWndParent, WM_COMMAND, 
 					lpitem->item_id, 0L);
-		else 
-		    SendMessage(lppop->ownerWnd, WM_COMMAND, 
+#ifdef DEBUG_MENU
+		    printf("PopupMenu // WM_COMMAND to ParentMenu wParam=%d !\n", 
+			lpitem->item_id);
+#endif
+		    }
+		else {
+		    if (lppop->SysFlag == 0) {
+#ifdef DEBUG_MENU
+			printf("PopupMenu // WM_COMMAND wParam=%d !\n", 
+				lpitem->item_id);
+#endif
+			SendMessage(lppop->ownerWnd, WM_COMMAND, 
 					lpitem->item_id, 0L);
+			}
+		    else {
+			if (lpitem->item_id == SC_ABOUTWINE) {
+			    printf("SysMenu // Show 'About Wine ...' !\n");
+/*			    DialogBox(hSysRes, MAKEINTRESOURCE(SC_ABOUTWINEDLG), */
+			    DialogBox(hSysRes, MAKEINTRESOURCE(2), 
+				GetParent(hwnd), (FARPROC)AboutWine_Proc);
+			    }
+			else {
+			    SendMessage(lppop->ownerWnd, WM_SYSCOMMAND,
+						 lpitem->item_id, 0L);
+#ifdef DEBUG_SYSMENU
+			    printf("PopupMenu // WM_SYSCOMMAND wParam=%04X !\n", 
+					lpitem->item_id);
+#endif
+			    }
+			}
+		    }
 #ifdef DEBUG_MENU
 		printf("PopupMenu // SendMessage WM_COMMAND wParam=%d !\n", 
 			lpitem->item_id);
@@ -248,10 +302,9 @@
 		    if (lppop2 == NULL) break;
 		    if (lppop->BarFlags != 0) {
 			lppop2->hWndParent = hwnd;
-			GetClientRect(hwnd, &rect);
-			y = rect.bottom - rect.top;
+			GetWindowRect(hwnd, &rect);
 			TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-				lpitem->rect.left, 0, 
+				lpitem->rect.left, rect.top, 
 				0, lppop->ownerWnd, (LPRECT)NULL);
 			}
 		    }
@@ -747,6 +800,9 @@
     HFONT	hOldFont;
     UINT  	i, OldWidth, TempWidth;
     DWORD	dwRet;
+#ifdef DEBUG_MENUCALC
+	printf("PopupMenuCalcSize hWnd=%04X !\n", hWnd);
+#endif
     lppop = PopupMenuGetWindowAndStorage(hwnd, &wndPtr);
     if (lppop == NULL) return;
     if (lppop->nItems == 0) return;
@@ -759,6 +815,9 @@
     lpitem = lppop->firstItem;
     for(i = 0; i < lppop->nItems; i++) {
 	if (lpitem == NULL) break;
+#ifdef DEBUG_MENUCALC
+	printf("PopupMenuCalcSize item #%d !\n", i);
+#endif
 	rect.right = rect.left + lppop->Width;
 	if ((lpitem->item_flags & MF_SEPARATOR) == MF_SEPARATOR) {
 	    rect.bottom = rect.top + 3;
@@ -788,11 +847,10 @@
     if (OldWidth < lppop->Width) goto CalcAGAIN;
     lppop->Height = rect.bottom;
 #ifdef DEBUG_MENUCALC
-    printf("PopupMenuCalcSize w=%d h=%d !\n", 
-    	lppop->Width, lppop->Height);
+    printf("PopupMenuCalcSize w=%d h=%d !\n", lppop->Width, lppop->Height);
 #endif
     SelectObject(hDC, hOldFont);
-    ReleaseDC(0, hDC);
+    ReleaseDC(hwnd, hDC);
 }
 
 
@@ -1775,6 +1833,7 @@
     menu->hWndParent	  = 0;
     menu->MouseFlags	  = 0;
     menu->BarFlags	  = 0;
+    menu->SysFlag	  = FALSE;
     menu->Width = 100;
     menu->Height = 0;
     return hMenu;
@@ -1798,8 +1857,8 @@
     wndPtr = WIN_FindWndPtr(hWnd);
     lppop->ownerWnd = hWnd;
     if (lppop->hWnd == (HWND)NULL) {
-        lppop->hWnd = CreateWindow("POPUPMENU", "", WS_CHILD | WS_VISIBLE,
-        	x, y, lppop->Width, lppop->Height, hWnd, 0, 
+        lppop->hWnd = CreateWindow("POPUPMENU", "", WS_POPUP | WS_VISIBLE,
+        	x, y, lppop->Width, lppop->Height, (HWND)NULL, 0, 
         	wndPtr->hInstance, (LPSTR)lppop);
         }
     else {
@@ -1828,6 +1887,43 @@
 
 
 /**********************************************************************
+ *			NC_TrackSysMenu		[Internal]
+ */
+void NC_TrackSysMenu(hWnd)
+{
+    RECT	rect;
+    LPPOPUPMENU	lpsys;
+    WND *wndPtr = WIN_FindWndPtr(hWnd);    
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu hWnd=%04X !\n", hWnd);
+#endif
+    if (!wndPtr) return;
+    lpsys = (LPPOPUPMENU)GlobalLock(wndPtr->hSysMenu);
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr->hSysMenu);
+#endif
+    if (lpsys == NULL) return;
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr->hSysMenu);
+#endif
+    lpsys->BarFlags = FALSE;
+    lpsys->SysFlag = TRUE;
+    if (!IsWindowVisible(lpsys->hWnd)) {
+	GetWindowRect(hWnd, &rect);
+#ifdef DEBUG_MENU
+	printf("NC_TrackSysMenu lpsys->hWnd=%04X !\n", lpsys->hWnd);
+#endif
+	TrackPopupMenu(wndPtr->hSysMenu, TPM_LEFTBUTTON, 
+		rect.left, rect.top + SYSMETRICS_CYSIZE, 
+		0, hWnd, (LPRECT)NULL);
+	}
+    else {
+	ShowWindow(lpsys->hWnd, SW_HIDE);
+	}
+}
+
+
+/**********************************************************************
  *			SetMenuItemBitmaps	[USER.418]
  */
 BOOL SetMenuItemBitmaps(HMENU hMenu, WORD nPos, WORD wFlags,
@@ -1881,6 +1977,7 @@
     menu->hWndParent	  = 0;
     menu->MouseFlags	  = 0;
     menu->BarFlags	  = TRUE;
+    menu->SysFlag	  = FALSE;
     menu->Width = 100;
     menu->Height = 0;
     return hMenu;
@@ -1923,7 +2020,105 @@
 
 
 /**********************************************************************
- *			DrawMenuBar		[USER.152]
+ *			LoadMenu		[USER.150]
+ */
+HMENU LoadMenu(HINSTANCE instance, char *menu_name)
+{
+    HMENU     		hMenu;
+    HANDLE		hMenu_desc;
+    MENU_HEADER 	*menu_desc;
+
+#ifdef DEBUG_MENU
+    if ((LONG)menu_name & 0xFFFF0000L)
+	printf("LoadMenu: instance %02x, menu '%s'\n", instance, menu_name);
+    else
+	printf("LoadMenu: instance %02x, menu '%04X'\n", instance, menu_name);
+#endif
+    if (instance == (HANDLE)NULL)  instance = hSysRes;
+    if (menu_name == NULL || 
+	(hMenu_desc = RSC_LoadMenu(instance, menu_name)) == 0 ||
+	(menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc)) == NULL)
+    {
+	return 0;
+    }
+    hMenu = CreateMenu();
+    ParseMenuResource((WORD *) (menu_desc + 1), 0, hMenu);
+    return hMenu;
+}
+
+
+/**********************************************************************
+ *			GetSystemMenu		[USER.156]
+ */
+HMENU GetSystemMenu(HWND hWnd, BOOL bRevert)
+{
+    WND		*wndPtr;
+    wndPtr = WIN_FindWndPtr(hWnd);
+    if (!bRevert) {
+	return wndPtr->hSysMenu;
+	}
+    else {
+	DestroyMenu(wndPtr->hSysMenu);
+	wndPtr->hSysMenu = CopySysMenu();
+	}
+    return wndPtr->hSysMenu;
+}
+
+
+/**********************************************************************
+ *			GetMenu		[USER.157]
+ */
+HMENU GetMenu(HWND hWnd) 
+{ 
+    WND * wndPtr = WIN_FindWndPtr(hWnd);
+    if (wndPtr == NULL) return 0;
+    return wndPtr->wIDmenu;
+}
+
+/**********************************************************************
+ * 			SetMenu 	[USER.158]
+ */
+BOOL SetMenu(HWND hWnd, HMENU hMenu)
+{
+    WND * wndPtr = WIN_FindWndPtr(hWnd);
+    if (wndPtr == NULL) return FALSE;
+    wndPtr->wIDmenu = hMenu;
+    return TRUE;
+}
+
+
+/**********************************************************************
+ *			GetSubMenu		[USER.159]
+ */
+HMENU GetSubMenu(HMENU hMenu, short nPos)
+{
+    HMENU	hSubMenu;
+    LPPOPUPMENU lppop;
+    LPMENUITEM 	lpitem;
+    int		i;
+#ifdef DEBUG_MENU
+    printf("GetSubMenu (%04X, %04X) !\n", hMenu, nPos);
+#endif
+    if (hMenu == 0) return 0;
+    lppop = (LPPOPUPMENU) GlobalLock(hMenu);
+    if (lppop == NULL) return 0;
+    lpitem = lppop->firstItem;
+    for (i = 0; i < lppop->nItems; i++) {
+    	if (lpitem == NULL) break;
+    	if (i == nPos) {
+	    if (lpitem->item_flags & MF_POPUP)
+		return hSubMenu;
+	    else
+		return 0;
+	    }
+    	lpitem = (LPMENUITEM)lpitem->next;
+    	}
+    return 0;
+}
+
+
+/**********************************************************************
+ *			DrawMenuBar		[USER.160]
  */
 void DrawMenuBar(HWND hWnd)
 {
@@ -1940,31 +2135,53 @@
 
 
 /**********************************************************************
- *			LoadMenu		[USER.152]
+ *			CopySysMenu (Internal)
  */
-HMENU LoadMenu(HINSTANCE instance, char *menu_name)
+HMENU CopySysMenu()
 {
     HMENU     		hMenu;
-    HANDLE		hMenu_desc;
-    MENU_HEADER 	*menu_desc;
-
+    LPPOPUPMENU 	menu;
+    LPPOPUPMENU 	sysmenu;
 #ifdef DEBUG_MENU
-    printf("LoadMenu: instance %02x, menu '%s'\n",
-	   instance, menu_name);
+    printf("CopySysMenu entry !\n");
 #endif
-    if (menu_name == NULL || 
-	(hMenu_desc = RSC_LoadMenu(instance, menu_name)) == 0 ||
-	(menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc)) == NULL)
-    {
-	return 0;
-    }
-    hMenu = CreateMenu();
-    ParseMenuResource((WORD *) (menu_desc + 1), 0, hMenu);
-    
+    if (hSysMenu == 0) {
+	hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(1));
+/*	hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(SC_SYSMENU));*/
+/*	hSysMenu = LoadMenu((HINSTANCE)NULL, "SYSMENU"); */
+	if (hSysMenu == 0) {
+	    printf("SysMenu not found in system resources !\n");
+	    return (HMENU)NULL;
+	    }
+#ifdef DEBUG_MENU
+	else
+	    printf("SysMenu loaded from system resources %04X !\n", hSysMenu);
+#endif
+	}
+    hMenu = GlobalAlloc(GMEM_MOVEABLE, sizeof(POPUPMENU));
+    menu = (LPPOPUPMENU) GlobalLock(hMenu);
+    sysmenu = (LPPOPUPMENU) GlobalLock(hSysMenu);
+    if (menu != NULL && sysmenu != NULL) {
+	sysmenu->BarFlags = FALSE;
+	memcpy(menu, sysmenu, sizeof(POPUPMENU));
+	}
+    else {
+	printf("CopySysMenu // Bad SysMenu pointers !\n");
+	if (menu != NULL) {
+	    GlobalUnlock(hMenu);
+	    GlobalFree(hMenu);
+	    }
+	return (HMENU)NULL;
+	}
+    GlobalUnlock(hMenu);
+    GlobalUnlock(hSysMenu);
     return hMenu;
 }
 
 
+/**********************************************************************
+ *			ParseMenuResource (for Xlib version)
+ */
 WORD * ParseMenuResource(WORD *first_item, int level, HMENU hMenu)
 {
     WORD 	*item;
@@ -1975,12 +2192,10 @@
     level++;
     next_item = first_item;
     i = 0;
-    do
-    {
+    do {
 	i++;
 	item = next_item;
-	if (*item & MF_POPUP)
-	{
+	if (*item & MF_POPUP) {
 	    MENU_POPUPITEM *popup_item = (MENU_POPUPITEM *) item;
 	    next_item = (WORD *) (popup_item->item_text + 
 				  strlen(popup_item->item_text) + 1);
@@ -1988,20 +2203,19 @@
 	    next_item = ParseMenuResource(next_item, level, hSubMenu);
 	    AppendMenu(hMenu, popup_item->item_flags, 
 	    	hSubMenu, popup_item->item_text);
-	}
-	else
-	{
+	    }
+	else {
 	    MENU_NORMALITEM *normal_item = (MENU_NORMALITEM *) item;
 	    next_item = (WORD *) (normal_item->item_text + 
 				  strlen(normal_item->item_text) + 1);
 	    AppendMenu(hMenu, normal_item->item_flags, 
 	    	normal_item->item_id, normal_item->item_text);
+	    }
 	}
-    }
     while (!(*item & MF_END));
-
     return next_item;
 }
 
+
 #endif
 
diff --git a/controls/scroll.c b/controls/scroll.c
index 47da5bf..0f2aa84 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -8,12 +8,12 @@
 /*
 #define DEBUG_SCROLL
 */
-
 static char Copyright[] = "Copyright Martin Ayotte, 1993";
 
 #include <X11/Intrinsic.h>
 #include <X11/StringDefs.h>
 #include "windows.h"
+#include "sysmetrics.h"
 #include "scroll.h"
 #include "heap.h"
 #include "win.h"
@@ -30,33 +30,39 @@
 HBITMAP hLfArrowD = 0;
 HBITMAP hRgArrowD = 0;
 
-LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hwnd, WND **wndPtr);
-LPHEADSCROLL ScrollBarGetStorageHeader(HWND hwnd);
-void StdDrawScrollBar(HWND hwnd);
-int CreateScrollBarStruct(HWND hwnd);
+LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hWnd, WND **wndPtr);
+LPHEADSCROLL ScrollBarGetStorageHeader(HWND hWnd);
+LPHEADSCROLL GetScrollObjectHandle(HWND hWnd, int nBar);
+void ScrollBarButtonDown(HWND hWnd, int nBar, int x, int y);
+void ScrollBarButtonUp(HWND hWnd, int nBar, int x, int y);
+void ScrollBarMouseMove(HWND hWnd, int nBar, WORD wParam, int x, int y);
+void StdDrawScrollBar(HWND hWnd, HDC hDC, int nBar, LPRECT lprect, LPHEADSCROLL lphs);
+int CreateScrollBarStruct(HWND hWnd);
+void NC_CreateScrollBars(HWND hWnd);
+LPHEADSCROLL AllocScrollBar(DWORD dwStyle, int width, int height);
 
 
 /***********************************************************************
  *           WIDGETS_ScrollBarWndProc
  */
-LONG ScrollBarWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
+LONG ScrollBarWndProc( HWND hWnd, WORD message, WORD wParam, LONG lParam )
 {    
     WORD	wRet;
     short	x, y;
     short	width, height;
     WND  	*wndPtr;
     LPHEADSCROLL lphs;
-    LPDRAWITEMSTRUCT lpdis;
-    HDC		hMemDC;
+    PAINTSTRUCT ps;
+    HDC		hDC;
     BITMAP	bm;
-    RECT 	rect;
+    RECT 	rect, rect2;
     static RECT rectsel;
     switch(message)
     {
     case WM_CREATE:
-	CreateScrollBarStruct(hwnd);
+	CreateScrollBarStruct(hWnd);
 #ifdef DEBUG_SCROLL
-        printf("ScrollBar Creation up=%X down=%X!\n", lphs->hWndUp, lphs->hWndDown);
+        printf("ScrollBar Creation !\n");
 #endif
 	if (hUpArrow == (HBITMAP)NULL) 
 	    hUpArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWI));
@@ -76,197 +82,271 @@
 	    hRgArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWD));
 	return 0;
     case WM_DESTROY:
-	lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
+	lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
 	if (lphs == 0) return 0;
 #ifdef DEBUG_SCROLL
         printf("ScrollBar WM_DESTROY %lX !\n", lphs);
 #endif
-	DestroyWindow(lphs->hWndUp);
-	DestroyWindow(lphs->hWndDown);
 	free(lphs);
 	*((LPHEADSCROLL *)&wndPtr->wExtra[1]) = 0;
 	return 0;
 	
-    case WM_COMMAND:
-#ifdef DEBUG_SCROLL
-        printf("ScrollBar WM_COMMAND wParam=%X lParam=%lX !\n", wParam, lParam);
-#endif
-	lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
-	if (HIWORD(lParam) != BN_CLICKED) return 0;
-        if (LOWORD(lParam) == lphs->hWndUp)
-            SendMessage(wndPtr->hwndParent, lphs->Direction, 
-            	SB_LINEUP, MAKELONG(0, hwnd));
-        if (LOWORD(lParam) == lphs->hWndDown)
-            SendMessage(wndPtr->hwndParent, lphs->Direction, 
-            	SB_LINEDOWN, MAKELONG(0, hwnd));
-/*
-	SetFocus(hwnd);
-*/
-	return 0;
-
     case WM_LBUTTONDOWN:
-	lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
-/*
-	SetFocus(hwnd);
-*/
-	SetCapture(hwnd);
-	GetClientRect(hwnd, &rect);
-	if (lphs->Direction == WM_VSCROLL) {
-	    y = HIWORD(lParam);
-#ifdef DEBUG_SCROLL
-	    printf("WM_LBUTTONDOWN y=%d cur+right=%d %d\n", 
-	    	y, lphs->CurPix + rect.right, lphs->CurPix + (rect.right << 1));
-#endif
-	    if (y < (lphs->CurPix + rect.right)) 
-	        SendMessage(wndPtr->hwndParent, lphs->Direction, 
-	        	SB_PAGEUP, MAKELONG(0, hwnd));
-	    if (y > (lphs->CurPix + (rect.right << 1))) 
-	        SendMessage(wndPtr->hwndParent, lphs->Direction, 
-	        	SB_PAGEDOWN, MAKELONG(0, hwnd));
-	    if ((y > (lphs->CurPix + rect.right)) &&
-	        (y < (lphs->CurPix + (rect.right << 1)))) {
-	        lphs->ThumbActive = TRUE;
-#ifdef DEBUG_SCROLL
-	        printf("THUMB DOWN !\n");
-#endif
-	        }
-	    }
-	else {
-	    x = LOWORD(lParam);
-#ifdef DEBUG_SCROLL
-	    printf("WM_LBUTTONDOWN x=%d Cur+bottom=%d %d\n",
-	    	 x, lphs->CurPix + rect.bottom, lphs->CurPix + (rect.bottom << 1));
-#endif
-	    if (x < (lphs->CurPix + rect.bottom))
-	        SendMessage(wndPtr->hwndParent, lphs->Direction, 
-	        	SB_PAGEUP, MAKELONG(0, hwnd));
-	    if (x > (lphs->CurPix + (rect.bottom << 1)))
-	        SendMessage(wndPtr->hwndParent, lphs->Direction, 
-	        	SB_PAGEDOWN, MAKELONG(0, hwnd));
-	    if ((x > (lphs->CurPix + rect.bottom)) &&
-		(x < (lphs->CurPix + (rect.bottom << 1)))) {
-	        lphs->ThumbActive = TRUE;
-#ifdef DEBUG_SCROLL
-	        printf("THUMB DOWN !\n");
-#endif
-		}
-	    }
+	SetCapture(hWnd);
+	ScrollBarButtonDown(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
 	break;
     case WM_LBUTTONUP:
-	lphs = ScrollBarGetStorageHeader(hwnd);
-        lphs->ThumbActive = FALSE;
 	ReleaseCapture();
+	ScrollBarButtonUp(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
 	break;
 
     case WM_MOUSEMOVE:
-        if ((wParam & MK_LBUTTON) != 0) {
-	    lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
-	    if (lphs->ThumbActive == 0) break;
-	    GetClientRect(hwnd, &rect);
-	    if (lphs->Direction == WM_VSCROLL)
-		y = HIWORD(lParam) - rect.right - (rect.right >> 1);
-	    else
-		y = LOWORD(lParam) - rect.bottom - (rect.bottom >> 1);
-	    x = (y * (lphs->MaxVal - lphs->MinVal) / 
-	    		lphs->MaxPix) + lphs->MinVal;
-#ifdef DEBUG_SCROLL
-	    printf("Scroll WM_MOUSEMOVE val=%d pix=%d\n", x, y);
-#endif
-            SendMessage(wndPtr->hwndParent, lphs->Direction, 
-            		SB_THUMBTRACK, MAKELONG(x, hwnd));
-	    }
+	ScrollBarMouseMove(hWnd, SB_CTL, wParam, LOWORD(lParam), HIWORD(lParam));
 	break;
     case WM_KEYDOWN:
     case WM_KEYUP:
     case WM_CHAR:
-	lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
+	lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
 	return(SendMessage(wndPtr->hwndParent, message, wParam, lParam));
 
-    case WM_SIZE:
-	lphs = ScrollBarGetWindowAndStorage(hwnd, &wndPtr);
-	width  = LOWORD(lParam);
-	height = HIWORD(lParam);
-	if (lphs->Direction == WM_VSCROLL) {
-	    MoveWindow(lphs->hWndUp, 0, 0, width, width, TRUE);
-	    MoveWindow(lphs->hWndDown, 0, height - width, width, width, TRUE);
-	    }
-	else {
-	    MoveWindow(lphs->hWndUp, 0, 0, height, height, TRUE);
-	    MoveWindow(lphs->hWndDown, width - height, 0, height, height, TRUE);
-	    }
-	break;
-    case WM_DRAWITEM:
+    case WM_TIMER:
 #ifdef DEBUG_SCROLL
-	    printf("Scroll WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
+        printf("ScrollBar WM_TIMER wParam=%X lParam=%lX !\n", wParam, lParam);
 #endif
-        lpdis = (LPDRAWITEMSTRUCT)lParam;
-	if (lpdis->CtlType == ODT_BUTTON && lpdis->itemAction == ODA_DRAWENTIRE) {
-	    hMemDC = CreateCompatibleDC(lpdis->hDC);
-	    if (lpdis->CtlID == 1) {
-		GetObject(hUpArrow, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hUpArrow);
-/*		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY); */
-		StretchBlt(lpdis->hDC, 0, 0, lpdis->rcItem.right, lpdis->rcItem.right,
-			hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 2) {
-		GetObject(hDnArrow, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hDnArrow);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 3) {
-		GetObject(hLfArrow, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hLfArrow);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 4) {
-		GetObject(hRgArrow, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hRgArrow);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    DeleteDC(hMemDC);
+	lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
+	KillTimer(hWnd, wParam);
+	switch(lphs->ButtonDown) {
+	    case 0:
+		lphs->TimerPending = FALSE;
+		return 0;
+	    case 1:
+	    case 3:
+		SendMessage(wndPtr->hwndParent, lphs->Direction, 
+			SB_LINEUP, MAKELONG(0, hWnd));
+		break;
+	    case 2:
+	    case 4:
+		SendMessage(wndPtr->hwndParent, lphs->Direction, 
+			SB_LINEDOWN, MAKELONG(0, hWnd));
+		break;
+	    case 5:
+		SendMessage(wndPtr->hwndParent, lphs->Direction, 
+			SB_PAGEUP, MAKELONG(0, hWnd));
+		break;
+	    case 6:
+		SendMessage(wndPtr->hwndParent, lphs->Direction, 
+			SB_PAGEDOWN, MAKELONG(0, hWnd));
+		break;
 	    }
-	if (lpdis->CtlType == ODT_BUTTON && lpdis->itemAction == ODA_SELECT) {
-	    hMemDC = CreateCompatibleDC(lpdis->hDC);
-	    if (lpdis->CtlID == 1) {
-		GetObject(hUpArrowD, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hUpArrowD);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 2) {
-		GetObject(hDnArrowD, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hDnArrowD);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 3) {
-		GetObject(hLfArrowD, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hLfArrowD);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    if (lpdis->CtlID == 4) {
-		GetObject(hRgArrowD, sizeof(BITMAP), (LPSTR)&bm);
-		SelectObject(hMemDC, hRgArrowD);
-		BitBlt(lpdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-		}
-	    DeleteDC(hMemDC);
-	    }
-	break;
+	SetTimer(hWnd, 1, 100, NULL);
+	return 0;
+
     case WM_PAINT:
-	StdDrawScrollBar(hwnd);
+	hDC = BeginPaint(hWnd, &ps);
+	lphs = ScrollBarGetStorageHeader(hWnd);
+	if (lphs != NULL) {
+	    GetClientRect(hWnd, &rect);
+	    StdDrawScrollBar(hWnd, hDC, SB_CTL, &rect, lphs);
+	    }
+	EndPaint(hWnd, &ps);
 	break;
     default:
-	return DefWindowProc( hwnd, message, wParam, lParam );
+	return DefWindowProc( hWnd, message, wParam, lParam );
     }
 return(0);
 }
 
 
 
-LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hwnd, WND **wndPtr)
+void ScrollBarButtonDown(HWND hWnd, int nBar, int x, int y)
+{
+    LPHEADSCROLL lphs;
+    HWND	hWndParent;
+    RECT	rect, rect2;
+    int		width, height;
+    LONG	dwOwner;
+    lphs = GetScrollObjectHandle(hWnd, nBar);
+	    printf("ScrollBarButtonDown // x=%d y=%d\n", x, y);
+#ifdef DEBUG_SCROLL
+	    printf("ScrollBarButtonDown // x=%d y=%d\n", x, y);
+#endif
+    if (nBar == SB_CTL) {
+	hWndParent = GetParent(hWnd);
+	dwOwner = MAKELONG(0, lphs->hWndOwner);
+	}
+    else {
+	hWndParent = hWnd;
+	dwOwner = 0L;
+	}
+/*
+    SetFocus(lphs->hWndOwner);
+*/
+    if (nBar != SB_CTL) {
+	GetWindowRect(lphs->hWndOwner, &rect);
+	x -= rect.left;
+	y -= rect.top;
+	}
+    CopyRect(&rect, &lphs->rect);
+    printf("ScrollDown / x=%d y=%d left=%d top=%d right=%d bottom=%d \n",
+    	x, y, rect.left, rect.top, rect.right, rect.bottom);
+    if (lphs->Direction == WM_VSCROLL) {
+	y -= rect.top;
+	width = rect.right - rect.left;
+	if (y < (lphs->CurPix + width)) {
+	    if (y < width) {
+		lphs->ButtonDown = 1;
+		CopyRect(&rect2, &rect);
+		rect2.bottom = rect2.top + width;
+		InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
+	    printf("ScrollBarButtonDown // SB_LINEUP \n");
+	        SendMessage(hWndParent, lphs->Direction, 
+				SB_LINEUP, dwOwner);
+		}
+	    else {
+		lphs->ButtonDown = 5;
+	    printf("ScrollBarButtonDown // SB_PAGEUP \n");
+		SendMessage(hWndParent, lphs->Direction, 
+				SB_PAGEUP, dwOwner);
+		}
+	    }
+	if (y > (lphs->CurPix + (width << 1))) {
+	    if (y > (rect.bottom - width)) {
+		lphs->ButtonDown = 2;
+		CopyRect(&rect2, &rect);
+		rect2.top = rect2.bottom - width;
+		InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
+	    printf("ScrollBarButtonDown // SB_LINEDOWN \n");
+	        SendMessage(hWndParent, lphs->Direction, 
+				SB_LINEDOWN, dwOwner);
+		}
+	    else {
+		lphs->ButtonDown = 6;
+	    printf("ScrollBarButtonDown // SB_PAGEDOWN \n");
+		SendMessage(hWndParent, lphs->Direction, 
+				SB_PAGEDOWN, dwOwner);
+		}
+	    }
+	if ((y > (lphs->CurPix + width)) &&
+	    (y < (lphs->CurPix + (width << 1)))) {
+	    lphs->ThumbActive = TRUE;
+#ifdef DEBUG_SCROLL
+	    printf("THUMB DOWN !\n");
+#endif
+	    }
+	}
+    else {
+	x -= rect.left;
+	height = rect.bottom - rect.top;
+	if (x < (lphs->CurPix + height)) {
+	    if (x < height) {
+		lphs->ButtonDown = 3;
+		CopyRect(&rect2, &rect);
+		rect2.right = rect2.left + height;
+		InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
+	        SendMessage(hWndParent, lphs->Direction, 
+				SB_LINEUP, dwOwner);
+		}
+	    else {
+		lphs->ButtonDown = 5;
+		SendMessage(hWndParent, lphs->Direction, 
+				SB_PAGEUP, dwOwner);
+		}
+	    }
+	if (x > (lphs->CurPix + (height << 1))) {
+	    if (x > (rect.right - rect.left - height)) {
+		lphs->ButtonDown = 4;
+		CopyRect(&rect2, &rect);
+		rect2.left = rect2.right - height;
+		InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
+	        SendMessage(hWndParent, lphs->Direction, 
+				SB_LINEDOWN, dwOwner);
+		}
+	    else {
+		lphs->ButtonDown = 6;
+		SendMessage(hWndParent, lphs->Direction, 
+				SB_PAGEDOWN, dwOwner);
+		}
+	    }
+	if ((x > (lphs->CurPix + height)) &&
+	    (x < (lphs->CurPix + (height << 1)))) {
+	    lphs->ThumbActive = TRUE;
+#ifdef DEBUG_SCROLL
+	    printf("THUMB DOWN !\n");
+#endif
+	    }
+	}
+    if (lphs->ButtonDown != 0) {
+	UpdateWindow(lphs->hWndOwner);
+	if (!lphs->TimerPending && nBar == SB_CTL) {
+	    lphs->TimerPending = TRUE;
+	    SetTimer(lphs->hWndOwner, 1, 500, NULL);
+	    }
+	}
+}
+
+
+void ScrollBarButtonUp(HWND hWnd, int nBar, int x, int y)
+{
+    LPHEADSCROLL lphs;
+    RECT	rect, rect2;
+    printf("ScrollBarButtonUp // x=%d y=%d\n", x, y); 
+#ifdef DEBUG_SCROLL
+    printf("ScrollBarButtonUp // x=%d y=%d\n", x, y); 
+#endif
+    lphs = GetScrollObjectHandle(hWnd, nBar);
+    lphs->ThumbActive = FALSE;
+    if (lphs->ButtonDown != 0) {
+	lphs->ButtonDown = 0;
+	GetClientRect(lphs->hWndOwner, &rect);
+	InvalidateRect(lphs->hWndOwner, &rect, TRUE);
+	UpdateWindow(lphs->hWndOwner);
+	}
+}
+
+
+void ScrollBarMouseMove(HWND hWnd, int nBar, WORD wParam, int x, int y)
+{
+    LPHEADSCROLL lphs;
+    HWND	hWndParent;
+    HWND	hWndOwner;
+    LONG	dwOwner;
+    if ((wParam & MK_LBUTTON) == 0) return;
+#ifdef DEBUG_SCROLL
+    printf("ScrollBarButtonMove // w=%04X x=%d y=%d \n", wParam, x, y);
+#endif
+    lphs = GetScrollObjectHandle(hWnd, nBar);
+    if (lphs->ThumbActive == 0) return;
+    if (nBar == SB_CTL) {
+	hWndParent = GetParent(hWnd);
+	hWndOwner = lphs->hWndOwner;
+	}
+    else {
+	hWndParent = hWnd;
+	hWndOwner = 0;
+	}
+    if (lphs->Direction == WM_VSCROLL) {
+	int butsiz = lphs->rect.right - lphs->rect.left;
+	y = y - butsiz - (butsiz >> 1);
+	}
+    else {
+	int butsiz = lphs->rect.bottom - lphs->rect.top;
+	y = x - butsiz - (butsiz >> 1);
+	}
+    x = (y * (lphs->MaxVal - lphs->MinVal) / 
+		lphs->MaxPix) + lphs->MinVal;
+#ifdef DEBUG_SCROLL
+    printf("Scroll WM_MOUSEMOVE val=%d pix=%d\n", x, y);
+#endif
+    SendMessage(hWndParent, lphs->Direction, 
+	SB_THUMBTRACK, MAKELONG(x, hWndOwner));
+}
+
+
+LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hWnd, WND **wndPtr)
 {
     WND  *Ptr;
     LPHEADSCROLL lphs;
-    *(wndPtr) = Ptr = WIN_FindWndPtr(hwnd);
+    *(wndPtr) = Ptr = WIN_FindWndPtr(hWnd);
     if (Ptr == 0) {
     	printf("Bad Window handle on ScrollBar !\n");
     	return 0;
@@ -276,11 +356,11 @@
 }
 
 
-LPHEADSCROLL ScrollBarGetStorageHeader(HWND hwnd)
+LPHEADSCROLL ScrollBarGetStorageHeader(HWND hWnd)
 {
     WND  *wndPtr;
     LPHEADSCROLL lphs;
-    wndPtr = WIN_FindWndPtr(hwnd);
+    wndPtr = WIN_FindWndPtr(hWnd);
     if (wndPtr == 0) {
     	printf("Bad Window handle on ScrollBar !\n");
     	return 0;
@@ -290,106 +370,138 @@
 }
 
 
-void StdDrawScrollBar(HWND hwnd)
+void StdDrawScrollBar(HWND hWnd, HDC hDC, int nBar, LPRECT lprect, LPHEADSCROLL lphs)
 {
-    LPHEADSCROLL lphs;
-    PAINTSTRUCT ps;
-    HBRUSH hBrush;
-    HDC hdc;
-    RECT rect;
-    UINT  i, w, h, siz;
+    HWND	hWndParent;
+    HBRUSH 	hBrush;
+    HDC 	hMemDC;
+    BITMAP	bm;
+    RECT 	rect;
+    UINT  	i, w, h, siz;
     char	C[128];
-    hdc = BeginPaint( hwnd, &ps );
-    if (!IsWindowVisible(hwnd)) {
-	EndPaint( hwnd, &ps );
-	return;
-	}
-    hBrush = SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WORD)hdc,
-			MAKELONG(hwnd, CTLCOLOR_SCROLLBAR));
+    if (lphs == NULL) return;
+#ifdef DEBUG_SCROLL
+    if (lphs->Direction == WM_VSCROLL)
+        printf("StdDrawScrollBar Vertical left=%d top=%d right=%d bottom=%d !\n", 
+        	lprect->left, lprect->top, lprect->right, lprect->bottom);
+    else
+        printf("StdDrawScrollBar Horizontal left=%d top=%d right=%d bottom=%d !\n", 
+        	lprect->left, lprect->top, lprect->right, lprect->bottom);
+#endif
+    if (nBar == SB_CTL)
+	hWndParent = GetParent(hWnd);
+    else
+	hWndParent = lphs->hWndOwner;
+    hBrush = SendMessage(hWndParent, WM_CTLCOLOR, (WORD)hDC,
+			MAKELONG(hWnd, CTLCOLOR_SCROLLBAR));
     if (hBrush == (HBRUSH)NULL)  hBrush = GetStockObject(LTGRAY_BRUSH);
-    lphs = ScrollBarGetStorageHeader(hwnd);
-    if (lphs == NULL) goto EndOfPaint;
-    GetClientRect(hwnd, &rect);
+    CopyRect(&lphs->rect, lprect);
+    CopyRect(&rect, lprect);
     w = rect.right - rect.left;
     h = rect.bottom - rect.top;
+    hMemDC = CreateCompatibleDC(hDC);
     if (lphs->Direction == WM_VSCROLL) {
+	GetObject(hUpArrow, sizeof(BITMAP), (LPSTR)&bm);
+	if (lphs->ButtonDown == 1)
+	    SelectObject(hMemDC, hUpArrowD);
+	else
+	    SelectObject(hMemDC, hUpArrow);
+	BitBlt(hDC, rect.left, rect.top, 
+		bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+/*
+	StretchBlt(hDC, 0, 0, lpdis->rcItem.right, lpdis->rcItem.right,
+			hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
+*/
+	GetObject(hDnArrow, sizeof(BITMAP), (LPSTR)&bm);
+	if (lphs->ButtonDown == 2)
+	    SelectObject(hMemDC, hDnArrowD);
+	else
+	    SelectObject(hMemDC, hDnArrow);
+	BitBlt(hDC, rect.left, rect.bottom - bm.bmHeight, 
+		bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
 	rect.top += w;
 	rect.bottom -= w;
 	}
     else {
+	GetObject(hLfArrow, sizeof(BITMAP), (LPSTR)&bm);
+	if (lphs->ButtonDown == 3)
+	    SelectObject(hMemDC, hLfArrowD);
+	else
+	    SelectObject(hMemDC, hLfArrow);
+	BitBlt(hDC, rect.left, rect.top, 
+		bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+	GetObject(hRgArrow, sizeof(BITMAP), (LPSTR)&bm);
+	if (lphs->ButtonDown == 4)
+	    SelectObject(hMemDC, hRgArrowD);
+	else
+	    SelectObject(hMemDC, hRgArrow);
+	BitBlt(hDC, rect.right - bm.bmWidth, rect.top, 
+		bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
 	rect.left += h;
 	rect.right -= h;
 	}
-    FillRect(hdc, &rect, hBrush);
+    DeleteDC(hMemDC);
+    FillRect(hDC, &rect, hBrush);
     if (lphs->Direction == WM_VSCROLL)
-	SetRect(&rect, 0, lphs->CurPix + w, w, lphs->CurPix + (w << 1));
+	SetRect(&rect, rect.left, rect.top + lphs->CurPix, 
+		rect.left + w, rect.top + lphs->CurPix + w);
     else
-	SetRect(&rect, lphs->CurPix + h, 0, lphs->CurPix + (h << 1), h);
-    FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
+	SetRect(&rect, rect.left + lphs->CurPix, rect.top, 
+		rect.left + lphs->CurPix + h, rect.top + h);
+/*
+    if (lphs->Direction == WM_VSCROLL)
+	SetRect(&rect, rect.left, rect.top + lphs->CurPix + w, 
+		rect.left + w, rect.top + lphs->CurPix + (w << 1));
+    else
+	SetRect(&rect, rect.left + lphs->CurPix + h, rect.top, 
+		rect.left + lphs->CurPix + (h << 1), rect.top + h);
+*/
+    FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
     InflateRect(&rect, -1, -1);
-    FillRect(hdc, &rect, GetStockObject(LTGRAY_BRUSH));
-    DrawReliefRect(hdc, rect, 2, 0);
+    FillRect(hDC, &rect, GetStockObject(LTGRAY_BRUSH));
+    DrawReliefRect(hDC, rect, 2, 0);
     InflateRect(&rect, -3, -3);
-    DrawReliefRect(hdc, rect, 1, 1);
-    if (!lphs->ThumbActive) {
-	InvalidateRect(lphs->hWndUp, NULL, TRUE);
-	UpdateWindow(lphs->hWndUp);
-	InvalidateRect(lphs->hWndDown, NULL, TRUE);
-	UpdateWindow(lphs->hWndDown);
-	}
-EndOfPaint:
-    EndPaint( hwnd, &ps );
+    DrawReliefRect(hDC, rect, 1, 1);
 }
 
 
 
-int CreateScrollBarStruct(HWND hwnd)
+int CreateScrollBarStruct(HWND hWnd)
 {
     RECT	rect;
     int		width, height;
     WND  *wndPtr;
     LPHEADSCROLL lphs;
-    wndPtr = WIN_FindWndPtr(hwnd);
+    wndPtr = WIN_FindWndPtr(hWnd);
     lphs = (LPHEADSCROLL)malloc(sizeof(HEADSCROLL));
     if (lphs == 0) {
     	printf("Bad Memory Alloc on ScrollBar !\n");
     	return 0;
     	}
-
 #ifdef DEBUG_SCROLL
         printf("CreateScrollBarStruct %lX !\n", lphs);
 #endif
     *((LPHEADSCROLL *)&wndPtr->wExtra[1]) = lphs;
+    lphs->hWndOwner = hWnd;
     lphs->ThumbActive = FALSE;
+    lphs->TimerPending = FALSE;
+    lphs->ButtonDown = 0;
     lphs->MinVal = 0;
     lphs->MaxVal = 100;
     lphs->CurVal = 0;
     lphs->CurPix = 0;
     width = wndPtr->rectClient.right - wndPtr->rectClient.left;
     height = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
+    CopyRect(&lphs->rect, &wndPtr->rectClient);
     if (width <= height)
 	{
 	lphs->MaxPix = height - 3 * width;
 	lphs->Direction = WM_VSCROLL;
-	lphs->hWndUp = CreateWindow("BUTTON", "", 
-        	WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
-        	0, 0, width, width, hwnd, 1, wndPtr->hInstance, 0L);
-	lphs->hWndDown = CreateWindow("BUTTON", "", 
-        	WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
-        	0, height - width, width, width, hwnd, 2,
-        	wndPtr->hInstance, 0L);
 	}
     else
 	{
 	lphs->MaxPix = width - 3 * height;
 	lphs->Direction = WM_HSCROLL;
-	lphs->hWndUp = CreateWindow("BUTTON", "", 
-        	WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
-        	0, 0, height, height, hwnd, 3, wndPtr->hInstance, 0L);
-	lphs->hWndDown = CreateWindow("BUTTON", "", 
-        	WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
-        	width - height, 0, height, height, hwnd, 4,
-        	wndPtr->hInstance, 0L);
 	}
     if (lphs->MaxPix < 1)  lphs->MaxPix = 1;
     if (wndPtr->hCursor == (HCURSOR)NULL)
@@ -398,31 +510,90 @@
 }
 
 
+
+LPHEADSCROLL AllocScrollBar(DWORD dwStyle, int width, int height)
+{
+    LPHEADSCROLL lphs;
+    lphs = (LPHEADSCROLL)malloc(sizeof(HEADSCROLL));
+    if (lphs == 0) {
+    	printf("Bad Memory Alloc on ScrollBar !\n");
+    	return NULL;
+    	}
+    lphs->ThumbActive = FALSE;
+    lphs->TimerPending = FALSE;
+    lphs->ButtonDown = 0;
+    lphs->MinVal = 0;
+    lphs->MaxVal = 100;
+    lphs->CurVal = 0;
+    lphs->CurPix = 0;
+    if (dwStyle & WS_VSCROLL) {
+	lphs->MaxPix = height - 3 * width;
+	lphs->Direction = WM_VSCROLL;
+	}
+    else {
+	lphs->MaxPix = width - 3 * height;
+	lphs->Direction = WM_HSCROLL;
+	}
+    if (lphs->MaxPix < 1)  lphs->MaxPix = 1;
+    return lphs;
+}
+
+
+void NC_CreateScrollBars(HWND hWnd)
+{
+    RECT	rect;
+    int		width, height;
+    WND  	*wndPtr;
+    LPHEADSCROLL lphs;
+    wndPtr = WIN_FindWndPtr(hWnd);
+    width = wndPtr->rectClient.right - wndPtr->rectClient.left;
+    height = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
+    if (wndPtr->dwStyle & WS_VSCROLL) {
+	if (wndPtr->dwStyle & WS_HSCROLL) height -= SYSMETRICS_CYHSCROLL;
+	lphs = AllocScrollBar(WS_VSCROLL, SYSMETRICS_CXVSCROLL, height);
+#ifdef DEBUG_SCROLL
+        printf("NC_CreateScrollBars Vertical %lX !\n", lphs);
+#endif
+	lphs->hWndOwner = hWnd;
+	wndPtr->VScroll = lphs;
+	}
+    if (wndPtr->dwStyle & WS_HSCROLL) {
+	if (wndPtr->dwStyle & WS_VSCROLL) width -= SYSMETRICS_CYVSCROLL;
+	lphs = AllocScrollBar(WS_HSCROLL, width, SYSMETRICS_CYHSCROLL);
+#ifdef DEBUG_SCROLL
+        printf("NC_CreateScrollBars Horizontal %lX !\n", lphs);
+#endif
+	lphs->hWndOwner = hWnd;
+	wndPtr->HScroll = lphs;
+	}
+}
+
+
 /*************************************************************************
- *			GetScrollWindowHandle
+ *			GetScrollObjectHandle
  */
-HWND GetScrollWindowHandle(HWND hWnd, int nBar)
+LPHEADSCROLL GetScrollObjectHandle(HWND hWnd, int nBar)
 {
     WND *wndPtr;
+    LPHEADSCROLL lphs;
     if (nBar != SB_CTL) {
-    wndPtr = WIN_FindWndPtr(hWnd);
-    	if (nBar == SB_VERT) return wndPtr->hWndVScroll;
-    	if (nBar == SB_HORZ) return wndPtr->hWndHScroll;
-    	return (HWND)NULL;
+	wndPtr = WIN_FindWndPtr(hWnd);
+    	if (nBar == SB_VERT) return (LPHEADSCROLL)wndPtr->VScroll;
+    	if (nBar == SB_HORZ) return (LPHEADSCROLL)wndPtr->HScroll;
+    	return NULL;
 	}
-    return hWnd;
+    return ScrollBarGetStorageHeader(hWnd);
 }
 
 
 /*************************************************************************
  *			SetScrollPos [USER.62]
  */
-int SetScrollPos(HWND hwnd, int nBar, int nPos, BOOL bRedraw)
+int SetScrollPos(HWND hWnd, int nBar, int nPos, BOOL bRedraw)
 {
     int nRet;
     LPHEADSCROLL lphs;
-    hwnd = GetScrollWindowHandle(hwnd, nBar);
-    lphs = ScrollBarGetStorageHeader(hwnd);
+    lphs = GetScrollObjectHandle(hWnd, nBar);
     if (lphs == NULL) return 0;
     nRet = lphs->CurVal;
     lphs->CurVal = (short)nPos;
@@ -436,9 +607,9 @@
     printf("SetScrollPos min=%d max=%d\n", 
 	    lphs->MinVal, lphs->MaxVal);
 #endif
-    if ((bRedraw) && (IsWindowVisible(hwnd))) {
-        InvalidateRect(hwnd, NULL, TRUE);
-        UpdateWindow(hwnd);
+    if ((bRedraw) && (IsWindowVisible(lphs->hWndOwner))) {
+        InvalidateRect(lphs->hWndOwner, &lphs->rect, TRUE);
+        UpdateWindow(lphs->hWndOwner);
         }
     return nRet;
 }
@@ -448,11 +619,10 @@
 /*************************************************************************
  *			GetScrollPos [USER.63]
  */
-int GetScrollPos(HWND hwnd, int nBar)
+int GetScrollPos(HWND hWnd, int nBar)
 {
     LPHEADSCROLL lphs;
-    hwnd = GetScrollWindowHandle(hwnd, nBar);
-    lphs = ScrollBarGetStorageHeader(hwnd);
+    lphs = GetScrollObjectHandle(hWnd, nBar);
     if (lphs == NULL) return 0;
     return lphs->CurVal;
 }
@@ -462,11 +632,10 @@
 /*************************************************************************
  *			SetScrollRange [USER.64]
  */
-void SetScrollRange(HWND hwnd, int nBar, int MinPos, int MaxPos, BOOL bRedraw)
+void SetScrollRange(HWND hWnd, int nBar, int MinPos, int MaxPos, BOOL bRedraw)
 {
     LPHEADSCROLL lphs;
-    hwnd = GetScrollWindowHandle(hwnd, nBar);
-    lphs = ScrollBarGetStorageHeader(hwnd);
+    lphs = GetScrollObjectHandle(hWnd, nBar);
     if (lphs == NULL) return;
     lphs->MinVal = (short)MinPos;
     lphs->MaxVal = (short)MaxPos;
@@ -478,9 +647,9 @@
 #ifdef DEBUG_SCROLL
     printf("SetScrollRange min=%d max=%d\n", lphs->MinVal, lphs->MaxVal);
 #endif
-    if ((bRedraw) && (IsWindowVisible(hwnd))) {
-        InvalidateRect(hwnd, NULL, TRUE);
-        UpdateWindow(hwnd);
+    if ((bRedraw) && (IsWindowVisible(lphs->hWndOwner))) {
+        InvalidateRect(lphs->hWndOwner, &lphs->rect, TRUE);
+        UpdateWindow(lphs->hWndOwner);
         }
 }
 
@@ -489,11 +658,10 @@
 /*************************************************************************
  *			GetScrollRange [USER.65]
  */
-void GetScrollRange(HWND hwnd, int nBar, LPINT lpMin, LPINT lpMax)
+void GetScrollRange(HWND hWnd, int nBar, LPINT lpMin, LPINT lpMax)
 {
     LPHEADSCROLL lphs;
-    hwnd = GetScrollWindowHandle(hwnd, nBar);
-    lphs = ScrollBarGetStorageHeader(hwnd);
+    lphs = GetScrollObjectHandle(hWnd, nBar);
     if (lphs == NULL) return;
     *lpMin = lphs->MinVal;
     *lpMax = lphs->MaxVal;
@@ -519,16 +687,20 @@
 	}
     wndPtr = WIN_FindWndPtr(hWnd);
     if ((wBar == SB_VERT) || (wBar == SB_BOTH)) {
+/*
     	if (bFlag)
 	    ShowWindow(wndPtr->hWndVScroll, SW_SHOW);
 	else
 	    ShowWindow(wndPtr->hWndVScroll, SW_HIDE);
+*/
 	}
     if ((wBar == SB_HORZ) || (wBar == SB_BOTH)) {
+/*
     	if (bFlag)
 	    ShowWindow(wndPtr->hWndHScroll, SW_SHOW);
 	else
 	    ShowWindow(wndPtr->hWndHScroll, SW_HIDE);
+*/
 	}
 }
 
diff --git a/controls/static.c b/controls/static.c
index 558110b..655d2fe 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -149,8 +149,8 @@
     GetClientRect(hwnd, &rc);
 
     textlen = GetWindowTextLength(hwnd);
-    hText = LocalAlloc(LMEM_MOVEABLE, textlen+1);
-    text = LocalLock(hText);
+    hText = USER_HEAP_ALLOC(0, textlen+1);
+    text = USER_HEAP_ADDR(hText);
     GetWindowText(hwnd, text, textlen+1);
 
     switch (style & 0x0000000F)
@@ -185,8 +185,7 @@
     FillRect(hdc, &rc, hBrush);
     DrawText(hdc, text, textlen, &rc, wFormat);
 
-    LocalUnlock(hText);
-    LocalFree(hText);
+    USER_HEAP_FREE(hText);
     GlobalUnlock(hwnd);
     EndPaint(hwnd, &ps);
 }
diff --git a/controls/widgets.c b/controls/widgets.c
index 02d10b4..37b74f1 100644
--- a/controls/widgets.c
+++ b/controls/widgets.c
@@ -7,7 +7,6 @@
 static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
 
 #include "windows.h"
-#include "win.h"
 #include "dialog.h"
 
 
@@ -17,7 +16,6 @@
 LONG ListBoxWndProc  ( HWND hwnd, WORD message, WORD wParam, LONG lParam );
 LONG ComboBoxWndProc ( HWND hwnd, WORD message, WORD wParam, LONG lParam );
 LONG PopupMenuWndProc ( HWND hwnd, WORD message, WORD wParam, LONG lParam );
-LONG CaptionBarWndProc ( HWND hwnd, WORD message, WORD wParam, LONG lParam );
 
 
 static WNDCLASS WIDGETS_BuiltinClasses[] =
@@ -34,8 +32,6 @@
       0, 0, 0, 0, NULL, "COMBOBOX" },
     { CS_GLOBALCLASS, (LONG(*)())PopupMenuWndProc, 0, 8,
       0, 0, 0, 0, NULL, "POPUPMENU" },
-    { CS_GLOBALCLASS, (LONG(*)())CaptionBarWndProc, 0, 8,
-      0, 0, 0, 0, NULL, "CAPTION" },
     { CS_GLOBALCLASS, (LONG(*)())DefDlgProc, 0, DLGWINDOWEXTRA,
       0, 0, 0, 0, NULL, DIALOG_CLASS_NAME }
 };