- Silence some debug messages
[reactos.git] / reactos / subsys / win32k / ntuser / misc.c
index 7910397..4bc6d4e 100644 (file)
 /* registered Logon process */
 PW32PROCESS LogonProcess = NULL;
 
-void W32kRegisterPrimitiveMessageQueue() {
+VOID W32kRegisterPrimitiveMessageQueue(VOID)
+{
   extern PUSER_MESSAGE_QUEUE pmPrimitiveMessageQueue;
   if( !pmPrimitiveMessageQueue ) {
     PW32THREAD pThread;
     pThread = PsGetWin32Thread();
     if( pThread && pThread->MessageQueue ) {
       pmPrimitiveMessageQueue = pThread->MessageQueue;
+      IntReferenceMessageQueue(pmPrimitiveMessageQueue);
       DPRINT( "Installed primitive input queue.\n" );
-    }    
+    }
   } else {
     DPRINT1( "Alert! Someone is trying to steal the primitive queue.\n" );
   }
 }
 
-PUSER_MESSAGE_QUEUE W32kGetPrimitiveMessageQueue() {
+VOID W32kUnregisterPrimitiveMessageQueue(VOID)
+{
+  extern PUSER_MESSAGE_QUEUE pmPrimitiveMessageQueue;
+  IntDereferenceMessageQueue(pmPrimitiveMessageQueue);
+  pmPrimitiveMessageQueue = NULL;
+}
+
+PUSER_MESSAGE_QUEUE W32kGetPrimitiveMessageQueue()
+{
   extern PUSER_MESSAGE_QUEUE pmPrimitiveMessageQueue;
   return pmPrimitiveMessageQueue;
 }
 
 BOOL FASTCALL
-IntRegisterLogonProcess(DWORD ProcessId, BOOL Register)
+IntRegisterLogonProcess(HANDLE ProcessId, BOOL Register)
 {
   PEPROCESS Process;
   NTSTATUS Status;
-  CSRSS_API_REQUEST Request;
-  CSRSS_API_REPLY Reply;
+  CSR_API_MESSAGE Request;
 
-  Status = PsLookupProcessByProcessId((PVOID)ProcessId,
+  Status = PsLookupProcessByProcessId(ProcessId,
                                      &Process);
   if (!NT_SUCCESS(Status))
   {
@@ -61,12 +70,12 @@ IntRegisterLogonProcess(DWORD ProcessId, BOOL Register)
       return FALSE;
     }
 
-    LogonProcess = Process->Win32Process;
+    LogonProcess = (PW32PROCESS)Process->Win32Process;
   }
   else
   {
     /* Deregister the logon process */
-    if (LogonProcess != Process->Win32Process)
+    if (LogonProcess != (PW32PROCESS)Process->Win32Process)
     {
       ObDereferenceObject(Process);
       return FALSE;
@@ -77,11 +86,11 @@ IntRegisterLogonProcess(DWORD ProcessId, BOOL Register)
 
   ObDereferenceObject(Process);
 
-  Request.Type = CSRSS_REGISTER_LOGON_PROCESS;
+  Request.Type = MAKE_CSR_API(REGISTER_LOGON_PROCESS, CSR_GUI);
   Request.Data.RegisterLogonProcessRequest.ProcessId = ProcessId;
   Request.Data.RegisterLogonProcessRequest.Register = Register;
 
-  Status = CsrNotify(&Request, &Reply);
+  Status = CsrNotify(&Request);
   if (! NT_SUCCESS(Status))
   {
     DPRINT1("Failed to register logon process with CSRSS\n");
@@ -106,11 +115,11 @@ NtUserCallNoParam(DWORD Routine)
       W32kRegisterPrimitiveMessageQueue();
       Result = (DWORD)TRUE;
       break;
-    
+
     case NOPARAM_ROUTINE_DESTROY_CARET:
       Result = (DWORD)IntDestroyCaret(PsGetCurrentThread()->Tcb.Win32Thread);
       break;
-    
+
     case NOPARAM_ROUTINE_INIT_MESSAGE_PUMP:
       Result = (DWORD)IntInitMessagePumpHook();
       break;
@@ -118,11 +127,11 @@ NtUserCallNoParam(DWORD Routine)
     case NOPARAM_ROUTINE_UNINIT_MESSAGE_PUMP:
       Result = (DWORD)IntUninitMessagePumpHook();
       break;
-    
+
     case NOPARAM_ROUTINE_GETMESSAGEEXTRAINFO:
       Result = (DWORD)MsqGetMessageExtraInfo();
       break;
-    
+
     case NOPARAM_ROUTINE_ANYPOPUP:
       Result = (DWORD)IntAnyPopup();
       break;
@@ -130,11 +139,7 @@ NtUserCallNoParam(DWORD Routine)
     case NOPARAM_ROUTINE_CSRSS_INITIALIZED:
       Result = (DWORD)CsrInit();
       break;
-    
-    case NOPARAM_ROUTINE_GDI_QUERY_TABLE:
-      Result = (DWORD)GDI_MapHandleTable(NtCurrentProcess());
-      break;
-    
+
     case NOPARAM_ROUTINE_MSQCLEARWAKEMASK:
       return (DWORD)IntMsqClearWakeMask();
 
@@ -161,25 +166,25 @@ NtUserCallOneParam(
     {
       PWINDOW_OBJECT WindowObject;
       DWORD Result;
-      
+
       WindowObject = IntGetWindowObject((HWND)Param);
       if(!WindowObject)
       {
         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
         return FALSE;
       }
-      
+
       Result = (DWORD)WindowObject->IDMenu;
-      
+
       IntReleaseWindowObject(WindowObject);
       return Result;
     }
-      
+
     case ONEPARAM_ROUTINE_ISWINDOWUNICODE:
     {
       PWINDOW_OBJECT WindowObject;
       DWORD Result;
-      
+
       WindowObject = IntGetWindowObject((HWND)Param);
       if(!WindowObject)
       {
@@ -190,34 +195,34 @@ NtUserCallOneParam(
       IntReleaseWindowObject(WindowObject);
       return Result;
     }
-      
+
     case ONEPARAM_ROUTINE_WINDOWFROMDC:
       return (DWORD)IntWindowFromDC((HDC)Param);
-      
+
     case ONEPARAM_ROUTINE_GETWNDCONTEXTHLPID:
     {
       PWINDOW_OBJECT WindowObject;
       DWORD Result;
-      
+
       WindowObject = IntGetWindowObject((HWND)Param);
       if(!WindowObject)
       {
         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
         return FALSE;
       }
-      
+
       Result = WindowObject->ContextHelpId;
-      
+
       IntReleaseWindowObject(WindowObject);
       return Result;
     }
-    
+
     case ONEPARAM_ROUTINE_SWAPMOUSEBUTTON:
     {
       PWINSTATION_OBJECT WinStaObject;
       NTSTATUS Status;
       DWORD Result;
-      
+
       Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
                                               KernelMode,
                                               0,
@@ -232,42 +237,41 @@ NtUserCallOneParam(
       ObDereferenceObject(WinStaObject);
       return Result;
     }
-    
+
     case ONEPARAM_ROUTINE_SWITCHCARETSHOWING:
       return (DWORD)IntSwitchCaretShowing((PVOID)Param);
-    
+
     case ONEPARAM_ROUTINE_SETCARETBLINKTIME:
       return (DWORD)IntSetCaretBlinkTime((UINT)Param);
 
     case ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS:
       return (DWORD)IntEnumClipboardFormats((UINT)Param);
-    
+
     case ONEPARAM_ROUTINE_GETWINDOWINSTANCE:
     {
       PWINDOW_OBJECT WindowObject;
       DWORD Result;
-      
+
       if(!(WindowObject = IntGetWindowObject((HWND)Param)))
       {
         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
         return FALSE;
       }
-      
+
       Result = (DWORD)WindowObject->Instance;
       IntReleaseWindowObject(WindowObject);
       return Result;
     }
-    
+
     case ONEPARAM_ROUTINE_SETMESSAGEEXTRAINFO:
       return (DWORD)MsqSetMessageExtraInfo((LPARAM)Param);
-    
+
     case ONEPARAM_ROUTINE_GETCURSORPOSITION:
     {
-      PSYSTEM_CURSORINFO CurInfo;
       PWINSTATION_OBJECT WinStaObject;
       NTSTATUS Status;
       POINT Pos;
-      
+
       if(!Param)
         return (DWORD)FALSE;
       Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
@@ -276,12 +280,10 @@ NtUserCallOneParam(
                                               &WinStaObject);
       if (!NT_SUCCESS(Status))
         return (DWORD)FALSE;
-      
-      CurInfo = IntGetSysCursorInfo(WinStaObject);
+
       /* FIXME - check if process has WINSTA_READATTRIBUTES */
-      Pos.x = CurInfo->x;
-      Pos.y = CurInfo->y;
-      
+      IntGetCursorLocation(WinStaObject, &Pos);
+
       Status = MmCopyToCaller((PPOINT)Param, &Pos, sizeof(POINT));
       if(!NT_SUCCESS(Status))
       {
@@ -289,58 +291,64 @@ NtUserCallOneParam(
         SetLastNtError(Status);
         return FALSE;
       }
-      
+
       ObDereferenceObject(WinStaObject);
-      
+
       return (DWORD)TRUE;
     }
-    
+
     case ONEPARAM_ROUTINE_ISWINDOWINDESTROY:
     {
       PWINDOW_OBJECT WindowObject;
       DWORD Result;
-      
+
       WindowObject = IntGetWindowObject((HWND)Param);
       if(!WindowObject)
       {
         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
         return FALSE;
       }
-      
+
       Result = (DWORD)IntIsWindowInDestroy(WindowObject);
-      
+
       IntReleaseWindowObject(WindowObject);
       return Result;
     }
-    
+
     case ONEPARAM_ROUTINE_ENABLEPROCWNDGHSTING:
     {
       BOOL Enable;
       PW32PROCESS Process = PsGetWin32Process();
-      
+
       if(Process != NULL)
       {
         Enable = (BOOL)(Param != 0);
-        
+
         if(Enable)
         {
           Process->Flags &= ~W32PF_NOWINDOWGHOSTING;
-        }  
+        }
         else
         {
           Process->Flags |= W32PF_NOWINDOWGHOSTING;
         }
-        
+
         return TRUE;
       }
-      
+
       return FALSE;
     }
 
     case ONEPARAM_ROUTINE_MSQSETWAKEMASK:
       return (DWORD)IntMsqSetWakeMask(Param);
+
+    case ONEPARAM_ROUTINE_GETKEYBOARDTYPE:
+      return NtUserGetKeyboardType(Param);
+      
+    case ONEPARAM_ROUTINE_GETKEYBOARDLAYOUT:
+      return (DWORD)NtUserGetKeyboardLayout(Param);
   }
-  DPRINT1("Calling invalid routine number 0x%x in NtUserCallOneParam(), Param=0x%x\n", 
+  DPRINT1("Calling invalid routine number 0x%x in NtUserCallOneParam(), Param=0x%x\n",
           Routine, Param);
   SetLastWin32Error(ERROR_INVALID_PARAMETER);
   return 0;
@@ -359,7 +367,7 @@ NtUserCallTwoParam(
 {
   NTSTATUS Status;
   PWINDOW_OBJECT WindowObject;
-  
+
   switch(Routine)
   {
     case TWOPARAM_ROUTINE_SETDCPENCOLOR:
@@ -397,7 +405,7 @@ NtUserCallTwoParam(
       PMENU_OBJECT MenuObject = IntGetMenuObject((HMENU)Param1);
       if(!MenuObject)
         return 0;
-      
+
       if(Param2 > 0)
       {
         Ret = (MenuObject->MenuInfo.Height == (int)Param2);
@@ -415,27 +423,27 @@ NtUserCallTwoParam(
       PMENU_OBJECT MenuObject = IntGetMenuObject((HMENU)Param1);
       if(!MenuObject)
         return 0;
-      
+
       if(!NT_SUCCESS(MmCopyFromCaller(&smir, (PVOID)Param2, sizeof(SETMENUITEMRECT))))
       {
         IntReleaseMenuObject(MenuObject);
         return 0;
       }
-      
+
       Ret = IntSetMenuItemRect(MenuObject, smir.uItem, smir.fByPosition, &smir.rcRect);
-      
+
       IntReleaseMenuObject(MenuObject);
       return (DWORD)Ret;
     }
-    
+
     case TWOPARAM_ROUTINE_SETGUITHRDHANDLE:
     {
       PUSER_MESSAGE_QUEUE MsgQueue = PsGetCurrentThread()->Tcb.Win32Thread->MessageQueue;
-      
+
       ASSERT(MsgQueue);
       return (DWORD)MsqSetStateWindow(MsgQueue, (ULONG)Param1, (HWND)Param2);
     }
-    
+
     case TWOPARAM_ROUTINE_ENABLEWINDOW:
          UNIMPLEMENTED
       return 0;
@@ -445,16 +453,39 @@ NtUserCallTwoParam(
          return 0;
 
     case TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS:
-         UNIMPLEMENTED
-         return 0;
+         return (DWORD)IntShowOwnedPopups((HWND) Param1, (BOOL) Param2);
 
+    case TWOPARAM_ROUTINE_ROS_SHOWWINDOW:
+    {
+#define WIN_NEEDS_SHOW_OWNEDPOPUP (0x00000040)
+          PWINDOW_OBJECT Window = IntGetWindowObject((HWND)Param1);
+         DPRINT1("ROS_SHOWWINDOW\n");
+          if (Window == 0)
+           {
+                 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
+                 return FALSE;
+           }
+          if (Param2)
+           {
+               if (!(Window->Flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
+                {
+                    IntReleaseWindowObject(Window);
+                    return TRUE;
+                }
+                Window->Flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
+           }
+          else Window->Flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
+          DPRINT1("ROS_SHOWWINDOW ---> 0x%x\n",Window->Flags);
+          IntReleaseWindowObject(Window);
+          return TRUE;
+    }
     case TWOPARAM_ROUTINE_SWITCHTOTHISWINDOW:
          UNIMPLEMENTED
          return 0;
 
     case TWOPARAM_ROUTINE_VALIDATERGN:
       return (DWORD)NtUserValidateRgn((HWND) Param1, (HRGN) Param2);
-      
+
     case TWOPARAM_ROUTINE_SETWNDCONTEXTHLPID:
       WindowObject = IntGetWindowObject((HWND)Param1);
       if(!WindowObject)
@@ -462,31 +493,31 @@ NtUserCallTwoParam(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return (DWORD)FALSE;
       }
-      
+
       WindowObject->ContextHelpId = Param2;
-      
+
       IntReleaseWindowObject(WindowObject);
       return (DWORD)TRUE;
-    
+
     case TWOPARAM_ROUTINE_SETCARETPOS:
       return (DWORD)IntSetCaretPos((int)Param1, (int)Param2);
-    
+
     case TWOPARAM_ROUTINE_GETWINDOWINFO:
     {
       WINDOWINFO wi;
       DWORD Ret;
-      
+
       if(!(WindowObject = IntGetWindowObject((HWND)Param1)))
       {
         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
         return FALSE;
       }
-      
+
 #if 0
       /*
        * According to WINE, Windows' doesn't check the cbSize field
        */
-      
+
       Status = MmCopyFromCaller(&wi.cbSize, (PVOID)Param2, sizeof(wi.cbSize));
       if(!NT_SUCCESS(Status))
       {
@@ -494,7 +525,7 @@ NtUserCallTwoParam(
         SetLastNtError(Status);
         return FALSE;
       }
-      
+
       if(wi.cbSize != sizeof(WINDOWINFO))
       {
         IntReleaseWindowObject(WindowObject);
@@ -502,7 +533,7 @@ NtUserCallTwoParam(
         return FALSE;
       }
 #endif
-      
+
       if((Ret = (DWORD)IntGetWindowInfo(WindowObject, &wi)))
       {
         Status = MmCopyToCaller((PVOID)Param2, &wi, sizeof(WINDOWINFO));
@@ -513,13 +544,13 @@ NtUserCallTwoParam(
           return FALSE;
         }
       }
-      
+
       IntReleaseWindowObject(WindowObject);
       return Ret;
     }
-    
+
     case TWOPARAM_ROUTINE_REGISTERLOGONPROC:
-      return (DWORD)IntRegisterLogonProcess(Param1, (BOOL)Param2);
+      return (DWORD)IntRegisterLogonProcess((HANDLE)Param1, (BOOL)Param2);
 
     case TWOPARAM_ROUTINE_SETSYSCOLORS:
     {
@@ -532,20 +563,20 @@ NtUserCallTwoParam(
       } ChangeSysColors;
 
       /* FIXME - we should make use of SEH here... */
-      
+
       Status = MmCopyFromCaller(&ChangeSysColors, (PVOID)Param1, sizeof(ChangeSysColors));
       if(!NT_SUCCESS(Status))
       {
         SetLastNtError(Status);
         return 0;
       }
-      
+
       Buffer = ExAllocatePool(PagedPool, (Param2 * sizeof(INT)) + (Param2 * sizeof(COLORREF)));
       if(Buffer != NULL)
       {
         INT *Elements = (INT*)Buffer;
         COLORREF *Colors = (COLORREF*)Buffer + Param2;
-        
+
         Status = MmCopyFromCaller(Elements, ChangeSysColors.Elements, Param2 * sizeof(INT));
         if(NT_SUCCESS(Status))
         {
@@ -562,6 +593,8 @@ NtUserCallTwoParam(
 
         ExFreePool(Buffer);
       }
+
+
       return Ret;
     }
 
@@ -579,7 +612,7 @@ NtUserCallTwoParam(
       } Buffer;
 
       /* FIXME - we should make use of SEH here... */
-      
+
       Buffer.Pointer = ExAllocatePool(PagedPool, Param2 * sizeof(HANDLE));
       if(Buffer.Pointer != NULL)
       {
@@ -598,7 +631,7 @@ NtUserCallTwoParam(
             Ret = 0;
             break;
         }
-        
+
         if(Ret > 0)
         {
           Status = MmCopyToCaller((PVOID)Param1, Buffer.Pointer, Param2 * sizeof(HANDLE));
@@ -611,10 +644,9 @@ NtUserCallTwoParam(
 
         ExFreePool(Buffer.Pointer);
       }
-
       return Ret;
     }
-    
+
   }
   DPRINT1("Calling invalid routine number 0x%x in NtUserCallTwoParam(), Param1=0x%x Parm2=0x%x\n",
           Routine, Param1, Param2);
@@ -622,6 +654,7 @@ NtUserCallTwoParam(
   return 0;
 }
 
+
 /*
  * @unimplemented
  */
@@ -645,12 +678,25 @@ NtUserCallHwndLock(
    switch (Routine)
    {
       case HWNDLOCK_ROUTINE_ARRANGEICONICWINDOWS:
-         /* FIXME */
+         WinPosArrangeIconicWindows(Window);
          break;
 
       case HWNDLOCK_ROUTINE_DRAWMENUBAR:
-         /* FIXME */
-         break;
+           {
+              PMENU_OBJECT MenuObject;
+              DPRINT("HWNDLOCK_ROUTINE_DRAWMENUBAR\n");
+              Ret = FALSE;
+              if (!((Window->Style & (WS_CHILD | WS_POPUP)) != WS_CHILD)) break;
+              MenuObject = IntGetMenuObject((HMENU) Window->IDMenu);
+              if(MenuObject == NULL) break;
+              MenuObject->MenuInfo.WndOwner = hWnd;
+              MenuObject->MenuInfo.Height = 0;
+              IntReleaseMenuObject(MenuObject);
+              WinPosSetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
+                           SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
+              Ret = TRUE;
+              break;
+            }
 
       case HWNDLOCK_ROUTINE_REDRAWFRAME:
          /* FIXME */
@@ -670,6 +716,9 @@ NtUserCallHwndLock(
    return Ret;
 }
 
+/*
+ * @unimplemented
+ */
 HWND
 STDCALL
 NtUserCallHwndOpt(
@@ -679,15 +728,23 @@ NtUserCallHwndOpt(
    switch (Routine)
    {
       case HWNDOPT_ROUTINE_SETPROGMANWINDOW:
-         /* FIXME */
+         /* 
+          * FIXME 
+          * Nothing too hard...validate the hWnd and save it in the Desktop Info
+          */
+         DPRINT1("HWNDOPT_ROUTINE_SETPROGMANWINDOW UNIMPLEMENTED\n");
          break;
 
       case HWNDOPT_ROUTINE_SETTASKMANWINDOW:
-         /* FIXME */
+         /* 
+          * FIXME 
+          * Nothing too hard...validate the hWnd and save it in the Desktop Info
+          */
+         DPRINT1("HWNDOPT_ROUTINE_SETTASKMANWINDOW UNIMPLEMENTED\n");
          break;
    }
 
-   return 0;
+   return Param;
 }
 
 /*
@@ -706,8 +763,8 @@ NtUserGetThreadState(
 }
 
 VOID FASTCALL
-IntGetFontMetricSetting(LPWSTR lpValueName, PLOGFONTW font) 
-{ 
+IntGetFontMetricSetting(LPWSTR lpValueName, PLOGFONTW font)
+{
    RTL_QUERY_REGISTRY_TABLE QueryTable[2];
    NTSTATUS Status;
    static LOGFONTW DefaultFont = {
@@ -751,19 +808,19 @@ IntSystemParametersInfo(
   static BOOL GradientCaptions = TRUE;
   static UINT FocusBorderHeight = 1;
   static UINT FocusBorderWidth = 1;
-  
+
   if (!bInitialized)
   {
-    ZeroMemory(&IconFont, sizeof(LOGFONTW)); 
-    ZeroMemory(&pMetrics, sizeof(NONCLIENTMETRICSW));
-    
+    RtlZeroMemory(&IconFont, sizeof(LOGFONTW));
+    RtlZeroMemory(&pMetrics, sizeof(NONCLIENTMETRICSW));
+
     IntGetFontMetricSetting(L"CaptionFont", &pMetrics.lfCaptionFont);
     IntGetFontMetricSetting(L"SmCaptionFont", &pMetrics.lfSmCaptionFont);
     IntGetFontMetricSetting(L"MenuFont", &pMetrics.lfMenuFont);
     IntGetFontMetricSetting(L"StatusFont", &pMetrics.lfStatusFont);
     IntGetFontMetricSetting(L"MessageFont", &pMetrics.lfMessageFont);
     IntGetFontMetricSetting(L"IconFont", &IconFont);
-    
+
     pMetrics.iBorderWidth = 1;
     pMetrics.iScrollWidth = NtUserGetSystemMetrics(SM_CXVSCROLL);
     pMetrics.iScrollHeight = NtUserGetSystemMetrics(SM_CYHSCROLL);
@@ -774,10 +831,10 @@ IntSystemParametersInfo(
     pMetrics.iMenuWidth = NtUserGetSystemMetrics(SM_CXMENUSIZE);
     pMetrics.iMenuHeight = NtUserGetSystemMetrics(SM_CYMENUSIZE);
     pMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
-    
+
     bInitialized = TRUE;
   }
-  
+
   switch(uiAction)
   {
     case SPI_SETDOUBLECLKWIDTH:
@@ -787,7 +844,7 @@ IntSystemParametersInfo(
     case SPI_GETDESKWALLPAPER:
     {
       PSYSTEM_CURSORINFO CurInfo;
-      
+
       Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
                                               KernelMode,
                                               0,
@@ -797,7 +854,7 @@ IntSystemParametersInfo(
         SetLastNtError(Status);
         return (DWORD)FALSE;
       }
-      
+
       switch(uiAction)
       {
         case SPI_SETDOUBLECLKWIDTH:
@@ -838,8 +895,8 @@ IntSystemParametersInfo(
             WinStaObject->cxWallpaper = bmp->SurfObj.sizlBitmap.cx;
             WinStaObject->cyWallpaper = bmp->SurfObj.sizlBitmap.cy;
 
-            BITMAPOBJ_UnlockBitmap(hNewBitmap);
-            
+            BITMAPOBJ_UnlockBitmap(bmp);
+
             /* change the bitmap's ownership */
             GDIOBJ_SetOwnership(hNewBitmap, NULL);
           }
@@ -861,9 +918,9 @@ IntSystemParametersInfo(
           *(HBITMAP*)pvParam = (HBITMAP)WinStaObject->hbmWallpaper;
           break;
       }
-      
+
       /* FIXME save the value to the registry */
-      
+
       ObDereferenceObject(WinStaObject);
       return TRUE;
     }
@@ -871,32 +928,32 @@ IntSystemParametersInfo(
     {
       RECT *rc;
       PDESKTOP_OBJECT Desktop = PsGetWin32Thread()->Desktop;
-      
+
       if(!Desktop)
       {
         /* FIXME - Set last error */
         return FALSE;
       }
-      
+
       ASSERT(pvParam);
       rc = (RECT*)pvParam;
       Desktop->WorkArea = *rc;
-      
+
       return TRUE;
     }
     case SPI_GETWORKAREA:
     {
       PDESKTOP_OBJECT Desktop = PsGetWin32Thread()->Desktop;
-      
+
       if(!Desktop)
       {
         /* FIXME - Set last error */
         return FALSE;
       }
-      
+
       ASSERT(pvParam);
       IntGetDesktopWorkArea(Desktop, (PRECT)pvParam);
-      
+
       return TRUE;
     }
     case SPI_SETGRADIENTCAPTIONS:
@@ -909,12 +966,12 @@ IntSystemParametersInfo(
     {
       HDC hDC;
       BOOL Ret = GradientCaptions;
-      
+
       hDC = IntGetScreenDC();
       if(hDC)
       {
         Ret = (NtGdiGetDeviceCaps(hDC, BITSPIXEL) > 8) && Ret;
-        
+
         ASSERT(pvParam);
         *((PBOOL)pvParam) = Ret;
         return TRUE;
@@ -966,7 +1023,7 @@ IntSystemParametersInfo(
       FocusBorderWidth = (UINT)pvParam;
       return TRUE;
     }
-    
+
     default:
     {
       DPRINT1("SystemParametersInfo: Unsupported Action 0x%x (uiParam: 0x%x, pvParam: 0x%x, fWinIni: 0x%x)\n",
@@ -1016,12 +1073,12 @@ NtUserSystemParametersInfo(
     case SPI_GETWORKAREA:
     {
       RECT rc;
-      
+
       if(!IntSystemParametersInfo(uiAction, uiParam, &rc, fWinIni))
       {
         return FALSE;
       }
-      
+
       Status = MmCopyToCaller((PRECT)pvParam, &rc, sizeof(RECT));
       if(!NT_SUCCESS(Status))
       {
@@ -1036,12 +1093,12 @@ NtUserSystemParametersInfo(
     case SPI_GETFOCUSBORDERWIDTH:
     {
       BOOL Ret;
-      
+
       if(!IntSystemParametersInfo(uiAction, uiParam, &Ret, fWinIni))
       {
         return FALSE;
       }
-      
+
       Status = MmCopyToCaller(pvParam, &Ret, sizeof(BOOL));
       if(!NT_SUCCESS(Status))
       {
@@ -1055,7 +1112,7 @@ NtUserSystemParametersInfo(
       /* !!! As opposed to the user mode version this version accepts a handle
              to the bitmap! */
       HBITMAP hbmWallpaper;
-      
+
       Status = MmCopyFromCaller(&hbmWallpaper, pvParam, sizeof(HBITMAP));
       if(!NT_SUCCESS(Status))
       {
@@ -1070,7 +1127,7 @@ NtUserSystemParametersInfo(
              to the bitmap! */
       HBITMAP hbmWallpaper;
       BOOL Ret;
-      
+
       Ret = IntSystemParametersInfo(SPI_GETDESKWALLPAPER, 0, &hbmWallpaper, fWinIni);
 
       Status = MmCopyToCaller(pvParam, &hbmWallpaper, sizeof(HBITMAP));
@@ -1084,12 +1141,12 @@ NtUserSystemParametersInfo(
     case SPI_GETICONTITLELOGFONT:
     {
       LOGFONTW IconFont;
-      
+
       if(!IntSystemParametersInfo(uiAction, uiParam, &IconFont, fWinIni))
       {
         return FALSE;
       }
-      
+
       Status = MmCopyToCaller(pvParam, &IconFont, sizeof(LOGFONTW));
       if(!NT_SUCCESS(Status))
       {
@@ -1101,7 +1158,7 @@ NtUserSystemParametersInfo(
     case SPI_GETNONCLIENTMETRICS:
     {
       NONCLIENTMETRICSW metrics;
-      
+
       Status = MmCopyFromCaller(&metrics.cbSize, pvParam, sizeof(UINT));
       if(!NT_SUCCESS(Status))
       {
@@ -1113,12 +1170,12 @@ NtUserSystemParametersInfo(
         SetLastWin32Error(ERROR_INVALID_PARAMETER);
         return FALSE;
       }
-      
+
       if(!IntSystemParametersInfo(uiAction, uiParam, &metrics, fWinIni))
       {
         return FALSE;
       }
-      
+
       Status = MmCopyToCaller(pvParam, &metrics.cbSize, sizeof(NONCLIENTMETRICSW));
       if(!NT_SUCCESS(Status))
       {
@@ -1139,7 +1196,7 @@ NtUserGetDoubleClickTime(VOID)
   NTSTATUS Status;
   PWINSTATION_OBJECT WinStaObject;
   PSYSTEM_CURSORINFO CurInfo;
-  
+
   Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
                                           KernelMode,
                                           0,
@@ -1149,7 +1206,7 @@ NtUserGetDoubleClickTime(VOID)
 
   CurInfo = IntGetSysCursorInfo(WinStaObject);
   Result = CurInfo->DblClickSpeed;
-      
+
   ObDereferenceObject(WinStaObject);
   return Result;
 }
@@ -1166,23 +1223,23 @@ NtUserGetGUIThreadInfo(
   PDESKTOP_OBJECT Desktop;
   PUSER_MESSAGE_QUEUE MsgQueue;
   PETHREAD Thread = NULL;
-  
+
   Status = MmCopyFromCaller(&SafeGui, lpgui, sizeof(DWORD));
   if(!NT_SUCCESS(Status))
   {
     SetLastNtError(Status);
     return FALSE;
   }
-  
+
   if(SafeGui.cbSize != sizeof(GUITHREADINFO))
   {
     SetLastWin32Error(ERROR_INVALID_PARAMETER);
     return FALSE;
   }
-  
+
   if(idThread)
   {
-    Status = PsLookupThreadByThreadId((PVOID)idThread, &Thread);
+    Status = PsLookupThreadByThreadId((HANDLE)idThread, &Thread);
     if(!NT_SUCCESS(Status))
     {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
@@ -1204,7 +1261,7 @@ NtUserGetGUIThreadInfo(
       }
     }
   }
-  
+
   if(!Thread || !Desktop)
   {
     if(idThread && Thread)
@@ -1212,33 +1269,33 @@ NtUserGetGUIThreadInfo(
     SetLastWin32Error(ERROR_ACCESS_DENIED);
     return FALSE;
   }
-  
+
   MsgQueue = (PUSER_MESSAGE_QUEUE)Desktop->ActiveMessageQueue;
   CaretInfo = MsgQueue->CaretInfo;
-  
+
   SafeGui.flags = (CaretInfo->Visible ? GUI_CARETBLINKING : 0);
   if(MsgQueue->MenuOwner)
     SafeGui.flags |= GUI_INMENUMODE | MsgQueue->MenuState;
   if(MsgQueue->MoveSize)
     SafeGui.flags |= GUI_INMOVESIZE;
-  
+
   /* FIXME add flag GUI_16BITTASK */
-  
+
   SafeGui.hwndActive = MsgQueue->ActiveWindow;
   SafeGui.hwndFocus = MsgQueue->FocusWindow;
   SafeGui.hwndCapture = MsgQueue->CaptureWindow;
   SafeGui.hwndMenuOwner = MsgQueue->MenuOwner;
   SafeGui.hwndMoveSize = MsgQueue->MoveSize;
   SafeGui.hwndCaret = CaretInfo->hWnd;
-  
+
   SafeGui.rcCaret.left = CaretInfo->Pos.x;
   SafeGui.rcCaret.top = CaretInfo->Pos.y;
   SafeGui.rcCaret.right = SafeGui.rcCaret.left + CaretInfo->Size.cx;
   SafeGui.rcCaret.bottom = SafeGui.rcCaret.top + CaretInfo->Size.cy;
-  
+
   if(idThread)
     ObDereferenceObject(Thread);
-  
+
   Status = MmCopyToCaller(lpgui, &SafeGui, sizeof(GUITHREADINFO));
   if(!NT_SUCCESS(Status))
   {
@@ -1260,28 +1317,28 @@ NtUserGetGuiResources(
   PW32PROCESS W32Process;
   NTSTATUS Status;
   DWORD Ret = 0;
-  
+
   Status = ObReferenceObjectByHandle(hProcess,
                                      PROCESS_QUERY_INFORMATION,
                                      PsProcessType,
                                      ExGetPreviousMode(),
                                      (PVOID*)&Process,
                                      NULL);
-  
+
   if(!NT_SUCCESS(Status))
   {
     SetLastNtError(Status);
     return 0;
   }
-  
-  W32Process = Process->Win32Process;
+
+  W32Process = (PW32PROCESS)Process->Win32Process;
   if(!W32Process)
   {
     ObDereferenceObject(Process);
     SetLastWin32Error(ERROR_INVALID_PARAMETER);
     return 0;
   }
-  
+
   switch(uiFlags)
   {
     case GR_GDIOBJECTS:
@@ -1300,7 +1357,7 @@ NtUserGetGuiResources(
       break;
     }
   }
-  
+
   ObDereferenceObject(Process);
 
   return Ret;
@@ -1312,21 +1369,21 @@ IntSafeCopyUnicodeString(PUNICODE_STRING Dest,
 {
   NTSTATUS Status;
   PWSTR Src;
-  
+
   Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING));
   if(!NT_SUCCESS(Status))
   {
     return Status;
   }
-  
+
   if(Dest->Length > 0x4000)
   {
     return STATUS_UNSUCCESSFUL;
   }
-  
+
   Src = Dest->Buffer;
   Dest->Buffer = NULL;
-  
+
   if(Dest->Length > 0 && Src)
   {
     Dest->MaximumLength = Dest->Length;
@@ -1335,7 +1392,7 @@ IntSafeCopyUnicodeString(PUNICODE_STRING Dest,
     {
       return STATUS_NO_MEMORY;
     }
-    
+
     Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
     if(!NT_SUCCESS(Status))
     {
@@ -1343,11 +1400,11 @@ IntSafeCopyUnicodeString(PUNICODE_STRING Dest,
       Dest->Buffer = NULL;
       return Status;
     }
-    
-    
+
+
     return STATUS_SUCCESS;
   }
-  
+
   /* string is empty */
   return STATUS_SUCCESS;
 }
@@ -1358,21 +1415,21 @@ IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest,
 {
   NTSTATUS Status;
   PWSTR Src;
-  
+
   Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING));
   if(!NT_SUCCESS(Status))
   {
     return Status;
   }
-  
+
   if(Dest->Length > 0x4000)
   {
     return STATUS_UNSUCCESSFUL;
   }
-  
+
   Src = Dest->Buffer;
   Dest->Buffer = NULL;
-  
+
   if(Dest->Length > 0 && Src)
   {
     Dest->MaximumLength = Dest->Length + sizeof(WCHAR);
@@ -1381,7 +1438,7 @@ IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest,
     {
       return STATUS_NO_MEMORY;
     }
-    
+
     Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
     if(!NT_SUCCESS(Status))
     {
@@ -1389,14 +1446,14 @@ IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest,
       Dest->Buffer = NULL;
       return Status;
     }
-    
+
     /* make sure the string is null-terminated */
     Src = (PWSTR)((PBYTE)Dest->Buffer + Dest->Length);
     *Src = L'\0';
-    
+
     return STATUS_SUCCESS;
   }
-  
+
   /* string is empty */
   return STATUS_SUCCESS;
 }