Do not allocate any USER data on the system heap.

diff --git a/controls/menu.c b/controls/menu.c
index 9e75635..43f4102 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -640,7 +640,7 @@
 {
     /* delete text */
     if (IS_STRING_ITEM(item->fType) && item->text)
-        HeapFree( SystemHeap, 0, item->text );
+        HeapFree( GetProcessHeap(), 0, item->text );
 }
 
 /***********************************************************************
@@ -1869,7 +1869,7 @@
                 flags |= MF_HELP;
                 str++;
             }
-            if (!(text = HEAP_strdupW( SystemHeap, 0, str ))) return FALSE;
+            if (!(text = HEAP_strdupW( GetProcessHeap(), 0, str ))) return FALSE;
             item->text = text;
         }
     }
@@ -1914,7 +1914,7 @@
     /* Don't call SetRectEmpty here! */
 
 
-    if (prevText) HeapFree( SystemHeap, 0, prevText );
+    if (prevText) HeapFree( GetProcessHeap(), 0, prevText );
 
     debug_print_menuitem("MENU_SetItemData to  : ", item, "");
     return TRUE;
@@ -1950,7 +1950,7 @@
 
     /* Create new items array */
 
-    newItems = HeapAlloc( SystemHeap, 0, sizeof(MENUITEM) * (menu->nItems+1) );
+    newItems = HeapAlloc( GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
     if (!newItems)
     {
         WARN("allocation failed\n" );
@@ -1962,7 +1962,7 @@
 	if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
 	if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
 					(menu->nItems-pos)*sizeof(MENUITEM) );
-        HeapFree( SystemHeap, 0, menu->items );
+        HeapFree( GetProcessHeap(), 0, menu->items );
     }
     menu->items = newItems;
     menu->nItems++;
@@ -2046,14 +2046,8 @@
 	/* Align the following fields on a dword boundary.  */
 	res += (~((int)res - 1)) & 3;
 
-        /* FIXME: This is inefficient and cannot be optimised away by gcc.  */
-	{
-	    LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
-					   0, mii.dwTypeData);
-	    TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
-			 mii.fType, mii.fState, mii.wID, resinfo, newstr);
-	    HeapFree( GetProcessHeap(), 0, newstr );
-	}
+        TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
+              mii.fType, mii.fState, mii.wID, resinfo, debugstr_w(mii.dwTypeData));
 
 	if (resinfo & 1) {	/* Pop-up? */
 	    /* DWORD helpid = GET_DWORD(res); FIXME: use this.  */
@@ -3720,7 +3714,7 @@
 
     if (--menu->nItems == 0)
     {
-        HeapFree( SystemHeap, 0, menu->items );
+        HeapFree( GetProcessHeap(), 0, menu->items );
         menu->items = NULL;
     }
     else
@@ -3731,7 +3725,7 @@
 	    item++;
 	    nPos++;
 	}
-        menu->items = HeapReAlloc( SystemHeap, 0, menu->items,
+        menu->items = HeapReAlloc( GetProcessHeap(), 0, menu->items,
                                    menu->nItems * sizeof(MENUITEM) );
     }
     return TRUE;
@@ -3960,7 +3954,7 @@
 	            if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
 		    MENU_FreeItemData( item );
 	        }
-	        HeapFree( SystemHeap, 0, lppop->items );
+	        HeapFree( GetProcessHeap(), 0, lppop->items );
 	    }
 	    USER_HEAP_FREE( hMenu );
             MENU_ReleaseTopPopupWnd();
@@ -4500,7 +4494,7 @@
     if (lpmii->fMask & MIIM_TYPE ) {
 	/* Get rid of old string.  */
 	if ( IS_STRING_ITEM(menu->fType) && menu->text) {
-	    HeapFree(SystemHeap, 0, menu->text);
+	    HeapFree(GetProcessHeap(), 0, menu->text);
 	    menu->text = NULL;
 	}
 
@@ -4512,16 +4506,16 @@
 
 	if (IS_STRING_ITEM(menu->fType) && menu->text) {
 	    if (unicode)
-		menu->text = HEAP_strdupW(SystemHeap, 0,  lpmii->dwTypeData);
+		menu->text = HEAP_strdupW(GetProcessHeap(), 0,  lpmii->dwTypeData);
 	    else
-		menu->text = HEAP_strdupAtoW(SystemHeap, 0, (LPSTR)lpmii->dwTypeData);
+		menu->text = HEAP_strdupAtoW(GetProcessHeap(), 0, (LPSTR)lpmii->dwTypeData);
 	}
     }
 
     if (lpmii->fMask & MIIM_FTYPE ) {
 	/* free the string when the type is changing */
 	if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
-	    HeapFree(SystemHeap, 0, menu->text);
+	    HeapFree(GetProcessHeap(), 0, menu->text);
 	    menu->text = NULL;
 	}
 	menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
@@ -4531,11 +4525,11 @@
     if (lpmii->fMask & MIIM_STRING ) {
 	/* free the string when used */
 	if ( IS_STRING_ITEM(menu->fType) && menu->text) {
-	    HeapFree(SystemHeap, 0, menu->text);
+	    HeapFree(GetProcessHeap(), 0, menu->text);
 	    if (unicode)
-		menu->text = HEAP_strdupW(SystemHeap, 0,  lpmii->dwTypeData);
+		menu->text = HEAP_strdupW(GetProcessHeap(), 0,  lpmii->dwTypeData);
 	    else
-		menu->text = HEAP_strdupAtoW(SystemHeap, 0, (LPSTR) lpmii->dwTypeData);
+		menu->text = HEAP_strdupAtoW(GetProcessHeap(), 0, (LPSTR) lpmii->dwTypeData);
 	}
     }
 
diff --git a/controls/scroll.c b/controls/scroll.c
index 2c739b8..6999865 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -9,7 +9,6 @@
 #include "wingdi.h"
 #include "wine/winuser16.h"
 #include "controls.h"
-#include "heap.h"
 #include "win.h"
 #include "debugtools.h"
 #include "user.h"
@@ -162,7 +161,7 @@
 
     if (!infoPtr)  /* Create the info structure if needed */
     {
-        if ((infoPtr = HeapAlloc( SystemHeap, 0, sizeof(SCROLLBAR_INFO) )))
+        if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
         {
             infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
             infoPtr->MaxVal = 100;
diff --git a/dlls/ttydrv/wnd.c b/dlls/ttydrv/wnd.c
index eed7a96..3247d65 100644
--- a/dlls/ttydrv/wnd.c
+++ b/dlls/ttydrv/wnd.c
@@ -7,7 +7,6 @@
 #include "config.h"
 
 #include "gdi.h"
-#include "heap.h"
 #include "ttydrv.h"
 #include "win.h"
 #include "debugtools.h"
@@ -52,8 +51,7 @@
  */
 void TTYDRV_WND_Initialize(WND *wndPtr)
 {
-  TTYDRV_WND_DATA *pWndDriverData = 
-    (TTYDRV_WND_DATA *) HeapAlloc(SystemHeap, 0, sizeof(TTYDRV_WND_DATA));
+  TTYDRV_WND_DATA *pWndDriverData = HeapAlloc(GetProcessHeap(), 0, sizeof(TTYDRV_WND_DATA));
 
   TRACE("(%p)\n", wndPtr);
 
@@ -81,7 +79,7 @@
     ERR("WND destroyed without destroying the associated Curses Windows");
   }
 
-  HeapFree(SystemHeap, 0, pWndDriverData);
+  HeapFree(GetProcessHeap(), 0, pWndDriverData);
   wndPtr->pDriverData = NULL;
 }
 
diff --git a/windows/cursoricon.c b/windows/cursoricon.c
index 19f5d19..0ba9df4 100644
--- a/windows/cursoricon.c
+++ b/windows/cursoricon.c
@@ -174,7 +174,7 @@
  */
 static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HANDLE handle )
 {
-    ICONCACHE *ptr = HeapAlloc( SystemHeap, 0, sizeof(ICONCACHE) );
+    ICONCACHE *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(ICONCACHE) );
     if ( !ptr ) return;
 
     ptr->hModule = hModule;
@@ -234,7 +234,7 @@
             *ptr = freePtr->next;
             
             GlobalFree16( freePtr->handle );
-            HeapFree( SystemHeap, 0, freePtr );
+            HeapFree( GetProcessHeap(), 0, freePtr );
             continue;
         }
         ptr = &(*ptr)->next;
diff --git a/windows/dce.c b/windows/dce.c
index 6a1e70f..15ce262 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -23,7 +23,6 @@
 #include "win.h"
 #include "gdi.h"
 #include "region.h"
-#include "heap.h"
 #include "user.h"
 #include "debugtools.h"
 #include "windef.h"
@@ -76,10 +75,10 @@
     DCE * dce;
     WND* wnd;
     
-    if (!(dce = HeapAlloc( SystemHeap, 0, sizeof(DCE) ))) return NULL;
+    if (!(dce = HeapAlloc( GetProcessHeap(), 0, sizeof(DCE) ))) return NULL;
     if (!(dce->hDC = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
     {
-        HeapFree( SystemHeap, 0, dce );
+        HeapFree( GetProcessHeap(), 0, dce );
 	return 0;
     }
 
@@ -134,7 +133,7 @@
     DeleteDC( dce->hDC );
     if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
 	DeleteObject(dce->hClipRgn);
-    HeapFree( SystemHeap, 0, dce );
+    HeapFree( GetProcessHeap(), 0, dce );
 
     WIN_UnlockWnds();
     
diff --git a/windows/defwnd.c b/windows/defwnd.c
index 0cbf82e..3583cf5 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -9,7 +9,6 @@
 
 #include "win.h"
 #include "user.h"
-#include "heap.h"
 #include "nonclient.h"
 #include "winpos.h"
 #include "dce.h"
@@ -67,8 +66,8 @@
     if (!text) text = "";
     count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
 
-    if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
-    if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
+    if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
+    if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
         MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
     else
         ERR("Not enough memory for window text");
@@ -89,8 +88,8 @@
     if (!text) text = empty_string;
     count = strlenW(text) + 1;
 
-    if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
-    if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
+    if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
+    if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
 	strcpyW( wndPtr->text, text );
     else
         ERR("Not enough memory for window text");
@@ -379,10 +378,10 @@
 	return NC_HandleNCActivate( wndPtr, wParam );
 
     case WM_NCDESTROY:
-	if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
+	if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text );
 	wndPtr->text = NULL;
-	if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
-	if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
+	if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
+	if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
         wndPtr->pVScroll = wndPtr->pHScroll = NULL;
 	return 0;
 
diff --git a/windows/mdi.c b/windows/mdi.c
index 5d4a614..8b6befe 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -1182,8 +1182,8 @@
     /* store new "default" title if lpTitle is not NULL */
     if (lpTitle) 
     {
-	if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
-	ci->frameTitle = HEAP_strdupW( SystemHeap, 0, lpTitle );
+	if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
+	ci->frameTitle = HEAP_strdupW( GetProcessHeap(), 0, lpTitle );
     }
 
     if (ci->frameTitle)
diff --git a/windows/message.c b/windows/message.c
index 6c20ccc..7c36e51 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -454,17 +454,17 @@
  */
 static void MSG_JournalRecordMsg( MSG *msg )
 {
-    EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
-    if (!event) return;
-    event->message = msg->message;
-    event->time = msg->time;
+    EVENTMSG event;
+
+    event.message = msg->message;
+    event.time = msg->time;
     if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
     {
-        event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
-        event->paramH = msg->lParam & 0x7FFF;  
+        event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
+        event.paramH = msg->lParam & 0x7FFF;
         if (HIWORD(msg->lParam) & 0x0100)
-            event->paramH |= 0x8000;               /* special_key - bit */
-        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
+            event.paramH |= 0x8000;               /* special_key - bit */
+        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
     }
     else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
     {
@@ -472,20 +472,18 @@
         pt.x = SLOWORD(msg->lParam);
         pt.y = SHIWORD(msg->lParam);
         ClientToScreen( msg->hwnd, &pt );
-        event->paramL = pt.x;
-        event->paramH = pt.y;
-        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
+        event.paramL = pt.x;
+        event.paramH = pt.y;
+        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
     }
     else if ((msg->message >= WM_NCMOUSEFIRST) &&
              (msg->message <= WM_NCMOUSELAST))
     {
-        event->paramL = LOWORD(msg->lParam);       /* X pos */
-        event->paramH = HIWORD(msg->lParam);       /* Y pos */ 
-        event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
-        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
+        event.paramL = LOWORD(msg->lParam);       /* X pos */
+        event.paramH = HIWORD(msg->lParam);       /* Y pos */
+        event.message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
+        HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
     }
-    
-    HeapFree(SystemHeap, 0, event);
 }
 
 /***********************************************************************
@@ -495,94 +493,84 @@
  */
 static int MSG_JournalPlayBackMsg(void)
 {
- EVENTMSG *tmpMsg;
- long wtime,lParam,wParam;
- WORD keyDown,i,result=0;
+    EVENTMSG tmpMsg;
+    LPARAM lParam;
+    WPARAM wParam;
+    LRESULT wtime;
+    int keyDown,i;
 
- if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
- {
-  tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
-  if (!tmpMsg) return result;
-  
-  wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
-                           (LPARAM) tmpMsg );
-  /*  TRACE(msg,"Playback wait time =%ld\n",wtime); */
-  if (wtime<=0)
-  {
-   wtime=0;
-   if ((tmpMsg->message >= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
-   {
-     wParam=tmpMsg->paramL & 0xFF;
-     lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
-     if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
-     {
-       for (keyDown=i=0; i<256 && !keyDown; i++)
-          if (InputKeyStateTable[i] & 0x80)
-            keyDown++;
-       if (!keyDown)
-         lParam |= 0x40000000;       
-       AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
-     }  
-     else                                       /* WM_KEYUP, WM_SYSKEYUP */
-     {
-       lParam |= 0xC0000000;      
-       AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
-     }
-     if (InputKeyStateTable[VK_MENU] & 0x80)
-       lParam |= 0x20000000;     
-     if (tmpMsg->paramH & 0x8000)              /*special_key bit*/
-       lParam |= 0x01000000;
-     hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
-                     0, 0, tmpMsg->time, 0 );
-   }
-   else
-   {
-    if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
+    if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return 0;
+
+    wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
+    /*  TRACE(msg,"Playback wait time =%ld\n",wtime); */
+    if (wtime<=0)
     {
-     switch (tmpMsg->message)
-     {
-      case WM_LBUTTONDOWN:
-          MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
-      case WM_LBUTTONUP:
-          MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
-      case WM_MBUTTONDOWN:
-          MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
-      case WM_MBUTTONUP:
-          MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
-      case WM_RBUTTONDOWN:
-          MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
-      case WM_RBUTTONUP:
-          MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;      
-     }
-     AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
-     AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
-     AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
-     SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
-     lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
-     wParam=0;             
-     if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
-     if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
-     if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
-     hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
-                     tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
+        wtime=0;
+        if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
+        {
+            wParam=tmpMsg.paramL & 0xFF;
+            lParam=MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
+            if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
+            {
+                for (keyDown=i=0; i<256 && !keyDown; i++)
+                    if (InputKeyStateTable[i] & 0x80)
+                        keyDown++;
+                if (!keyDown)
+                    lParam |= 0x40000000;
+                AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
+            }
+            else                                       /* WM_KEYUP, WM_SYSKEYUP */
+            {
+                lParam |= 0xC0000000;
+                AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
+            }
+            if (InputKeyStateTable[VK_MENU] & 0x80)
+                lParam |= 0x20000000;
+            if (tmpMsg.paramH & 0x8000)              /*special_key bit*/
+                lParam |= 0x01000000;
+            hardware_event( tmpMsg.message, wParam, lParam, 0, 0, tmpMsg.time, 0 );
+        }
+        else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
+        {
+            switch (tmpMsg.message)
+            {
+            case WM_LBUTTONDOWN:
+                MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
+            case WM_LBUTTONUP:
+                MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
+            case WM_MBUTTONDOWN:
+                MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
+            case WM_MBUTTONUP:
+                MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
+            case WM_RBUTTONDOWN:
+                MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
+            case WM_RBUTTONUP:
+                MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
+            }
+            AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
+            AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
+            AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
+            SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
+            lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
+            wParam=0;
+            if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
+            if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
+            if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
+            hardware_event( tmpMsg.message, wParam, lParam,
+                            tmpMsg.paramL, tmpMsg.paramH, tmpMsg.time, 0 );
+        }
+        HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
+        return 0;
     }
-   }
-   HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
-                      (LPARAM) tmpMsg);
-  }
-  else
-  {
-      
-    if( tmpMsg->message == WM_QUEUESYNC )
-        if (HOOK_IsHooked( WH_CBT ))
-            HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
+    else
+    {
+        if( tmpMsg.message == WM_QUEUESYNC )
+            if (HOOK_IsHooked( WH_CBT ))
+                HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
 
-    result= QS_MOUSE | QS_KEY; /* ? */
-  }
-  HeapFree(SystemHeap, 0, tmpMsg);
- }
- return result;
-} 
+        return QS_MOUSE | QS_KEY; /* ? */
+    }
+}
 
 /***********************************************************************
  *           MSG_PeekHardwareMsg
@@ -808,7 +796,7 @@
         return 0;
 
     /* create a SMSG structure to hold SendMessage() parameters */
-    if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
+    if (! (smsg = (SMSG *) HeapAlloc( GetProcessHeap(), 0, sizeof(SMSG) )) )
         return 0;
     if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
 
@@ -908,7 +896,7 @@
         EnterCriticalSection( &queue->cSection );
     
         if (smsg->flags & SMSG_RECEIVED)
-            HeapFree(SystemHeap, 0, smsg);
+            HeapFree(GetProcessHeap(), 0, smsg);
         else
             smsg->flags |= SMSG_RECEIVER_CLEANS;
         
@@ -1000,7 +988,7 @@
         if ( smsg->flags & SMSG_RECEIVER_CLEANS )
         {
             TRACE_(sendmsg)("Receiver cleans up!\n" );
-            HeapFree( SystemHeap, 0, smsg );
+            HeapFree( GetProcessHeap(), 0, smsg );
         }
 
         if (senderQ) LeaveCriticalSection(&senderQ->cSection);
@@ -1366,7 +1354,7 @@
 
         if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
         {
-            MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
+            MSG *pmsg = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
             if (pmsg)
             {
                 BOOL ret;
@@ -1376,7 +1364,7 @@
                        HOOK_CallHooksA( WH_MSGFILTER, code, 0,
                                           (LPARAM) pmsg ));
                        
-                HeapFree( SystemHeap, 0, pmsg );
+                HeapFree( GetProcessHeap(), 0, pmsg );
                 if (ret)
                 {
                     /* Message filtered -> remove it from the queue */
diff --git a/windows/property.c b/windows/property.c
index b3d2f7c..ca96001 100644
--- a/windows/property.c
+++ b/windows/property.c
@@ -135,14 +135,14 @@
         /* We need to create it */
         WND *pWnd = WIN_FindWndPtr( hwnd );
         if (!pWnd) return FALSE;
-        if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) )))
+        if (!(prop = HeapAlloc( GetProcessHeap(), 0, sizeof(*prop) )))
         {
             WIN_ReleaseWndPtr(pWnd);
             return FALSE;
         }
         if (!(prop->string = SEGPTR_STRDUP(str)))
         {
-            HeapFree( SystemHeap, 0, prop );
+            HeapFree( GetProcessHeap(), 0, prop );
             WIN_ReleaseWndPtr(pWnd);
             return FALSE;
 
@@ -229,7 +229,7 @@
     handle = prop->handle;
     *pprop = prop->next;
     SEGPTR_FREE(prop->string);
-    HeapFree( SystemHeap, 0, prop );
+    HeapFree( GetProcessHeap(), 0, prop );
     return handle;
 }
 
@@ -264,7 +264,7 @@
     {
         next = prop->next;
         SEGPTR_FREE( prop->string );
-        HeapFree( SystemHeap, 0, prop );
+        HeapFree( GetProcessHeap(), 0, prop );
     }
     pWnd->pProp = NULL;
 }
diff --git a/windows/queue.c b/windows/queue.c
index 7bd7136..38fd934 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -14,7 +14,6 @@
 #include "queue.h"
 #include "win.h"
 #include "hook.h"
-#include "heap.h"
 #include "thread.h"
 #include "debugtools.h"
 #include "server.h"
@@ -70,7 +69,7 @@
     }
 
     /* Allocate PERQUEUEDATA from the system heap */
-    if (!( pQData = (PERQUEUEDATA *) HeapAlloc( SystemHeap, 0,
+    if (!( pQData = (PERQUEUEDATA *) HeapAlloc( GetProcessHeap(), 0,
                                                     sizeof(PERQUEUEDATA) ) ))
         return 0;
 
@@ -139,7 +138,7 @@
             pQDataWin16 = 0;
             
         /* Free the PERQUEUEDATA instance */
-        HeapFree( SystemHeap, 0, pQData );
+        HeapFree( GetProcessHeap(), 0, pQData );
 
         return 0;
     }
@@ -309,16 +308,16 @@
 {
     MESSAGEQUEUE *queue;
 
-    HeapLock( SystemHeap );  /* FIXME: a bit overkill */
+    HeapLock( GetProcessHeap() );  /* FIXME: a bit overkill */
     queue = GlobalLock16( hQueue );
     if ( !queue || (queue->magic != QUEUE_MAGIC) )
     {
-        HeapUnlock( SystemHeap );
+        HeapUnlock( GetProcessHeap() );
         return NULL;
     }
 
     queue->lockCount++;
-    HeapUnlock( SystemHeap );
+    HeapUnlock( GetProcessHeap() );
     return queue;
 }
 
@@ -333,7 +332,7 @@
 {
     if (queue)
     {
-        HeapLock( SystemHeap );  /* FIXME: a bit overkill */
+        HeapLock( GetProcessHeap() );  /* FIXME: a bit overkill */
 
         if ( --queue->lockCount == 0 )
         {
@@ -343,7 +342,7 @@
             GlobalFree16( queue->self );
         }
     
-        HeapUnlock( SystemHeap );
+        HeapUnlock( GetProcessHeap() );
     }
 }
 
@@ -551,7 +550,7 @@
     /* flush sent messages */
     QUEUE_FlushMessages( msgQueue );
 
-    HeapLock( SystemHeap );  /* FIXME: a bit overkill */
+    HeapLock( GetProcessHeap() );  /* FIXME: a bit overkill */
 
     /* Release per queue data if present */
     if ( msgQueue->pQData )
@@ -579,7 +578,7 @@
     if (pPrev && *pPrev) *pPrev = msgQueue->next;
     msgQueue->self = 0;
 
-    HeapUnlock( SystemHeap );
+    HeapUnlock( GetProcessHeap() );
 
     /* free up resource used by MESSAGEQUEUE structure */
     msgQueue->lockCount--;
@@ -1030,7 +1029,7 @@
     if (!(msgQueue = QUEUE_Lock( hQueue ))) return FALSE;
 
     /* allocate new message in global heap for now */
-    if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) ))
+    if (!(qmsg = (QMSG *) HeapAlloc( GetProcessHeap(), 0, sizeof(QMSG) ) ))
     {
         QUEUE_Unlock( msgQueue );
         return 0;
@@ -1130,7 +1129,7 @@
         msgQueue->lastMsg = qmsg->prevMsg;
 
     /* deallocate the memory for the message */
-    HeapFree( SystemHeap, 0, qmsg );
+    HeapFree( GetProcessHeap(), 0, qmsg );
     
     msgQueue->msgCount--;
     if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE;
@@ -1246,7 +1245,7 @@
 
         /* Don't merge allocate a new msg in the global heap */
         
-        if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) ))
+        if (!(qmsg = (QMSG *) HeapAlloc( GetProcessHeap(), 0, sizeof(QMSG) ) ))
         {
             LeaveCriticalSection( &sysMsgQueue->cSection );
             return;
@@ -1494,13 +1493,13 @@
         queuePtr = QUEUE_Lock( hQueue );
         queuePtr->teb = NtCurrentTeb();
 
-        HeapLock( SystemHeap );  /* FIXME: a bit overkill */
+        HeapLock( GetProcessHeap() );  /* FIXME: a bit overkill */
         SetThreadQueue16( 0, hQueue );
         teb->queue = hQueue;
             
         queuePtr->next  = hFirstQueue;
         hFirstQueue = hQueue;
-        HeapUnlock( SystemHeap );
+        HeapUnlock( GetProcessHeap() );
         
         QUEUE_Unlock( queuePtr );
     }
diff --git a/windows/winpos.c b/windows/winpos.c
index 2f3cc4f..e74a2b7 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -109,7 +109,7 @@
     {
 	if( IsWindow(lpPos->hwndIconTitle) ) 
 	    DestroyWindow( lpPos->hwndIconTitle );
-	HeapFree( SystemHeap, 0, lpPos );
+	HeapFree( GetProcessHeap(), 0, lpPos );
     }
 
     QUEUE_Unlock( pMsgQ );
@@ -1087,7 +1087,7 @@
 	/* this happens when the window is minimized/maximized 
 	 * for the first time (rectWindow is not adjusted yet) */
 
-	lpPos = HeapAlloc( SystemHeap, 0, sizeof(INTERNALPOS) );
+	lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
 	if( !lpPos ) return NULL;
 
 	SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
diff --git a/windows/x11drv/wnd.c b/windows/x11drv/wnd.c
index c0cdc10..fbed353 100644
--- a/windows/x11drv/wnd.c
+++ b/windows/x11drv/wnd.c
@@ -22,7 +22,6 @@
 #include "gdi.h"
 #include "options.h"
 #include "message.h"
-#include "heap.h"
 #include "win.h"
 #include "windef.h"
 #include "x11drv.h"
@@ -137,8 +136,7 @@
  */
 void X11DRV_WND_Initialize(WND *wndPtr)
 {
-  X11DRV_WND_DATA *pWndDriverData = 
-    (X11DRV_WND_DATA *) HeapAlloc(SystemHeap, 0, sizeof(X11DRV_WND_DATA));
+  X11DRV_WND_DATA *pWndDriverData = HeapAlloc(GetProcessHeap(), 0, sizeof(X11DRV_WND_DATA));
 
   wndPtr->pDriverData = (void *) pWndDriverData;
 
@@ -165,7 +163,7 @@
 	  pWndDriverData->window
       );
     }
-  HeapFree(SystemHeap, 0, wndPtr->pDriverData);
+  HeapFree(GetProcessHeap(), 0, wndPtr->pDriverData);
   wndPtr->pDriverData = NULL;
 }