⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 4 页
字号:
				    CurInfo = IntGetSysCursorInfo(WinStaObject);
                  *((UINT*)pvParam) = CurInfo->WheelScroChars;
					// FIXME add this value to scroll list as scroll value ?? 
                  break;
               case SPI_SETDOUBLECLKWIDTH:
                  CurInfo = IntGetSysCursorInfo(WinStaObject);
                  /* FIXME limit the maximum value? */
                  CurInfo->DblClickWidth = uiParam;
                  break;
               case SPI_SETDOUBLECLKHEIGHT:
                  CurInfo = IntGetSysCursorInfo(WinStaObject);
                  /* FIXME limit the maximum value? */
                  CurInfo->DblClickHeight = uiParam;
                  break;
               case SPI_SETDOUBLECLICKTIME:
                  CurInfo = IntGetSysCursorInfo(WinStaObject);
                  /* FIXME limit the maximum time to 1000 ms? */
                  CurInfo->DblClickSpeed = uiParam;
                  break;
               case SPI_SETDESKWALLPAPER:
                  {
                     /* This function expects different parameters than the user mode version!

                        We let the user mode code load the bitmap, it passed the handle to
                        the bitmap. We'll change it's ownership to system and replace it with
                        the current wallpaper bitmap */
                     HBITMAP hOldBitmap, hNewBitmap;
                     UNICODE_STRING Key = RTL_CONSTANT_STRING(L"Control Panel\\Desktop"); 
                     UNICODE_STRING Tile = RTL_CONSTANT_STRING(L"TileWallpaper"); 
                     UNICODE_STRING Style = RTL_CONSTANT_STRING(L"WallpaperStyle");
                     UNICODE_STRING KeyPath;
                     OBJECT_ATTRIBUTES KeyAttributes;
                     OBJECT_ATTRIBUTES ObjectAttributes;
                     NTSTATUS Status;
                     HANDLE CurrentUserKey = NULL;
                     HANDLE KeyHandle = NULL;
                     PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
                     ULONG Length = 0;
                     ULONG ResLength = 0;
                     ULONG TileNum = 0;
                     ULONG StyleNum = 0;
                     ASSERT(pvParam);

                     hNewBitmap = *(HBITMAP*)pvParam;
                     if(hNewBitmap != NULL)
                     {
                        BITMAPOBJ *bmp;
                        /* try to get the size of the wallpaper */
                        if(!(bmp = BITMAPOBJ_LockBitmap(hNewBitmap)))
                        {
                           ObDereferenceObject(WinStaObject);
                           return FALSE;
                        }
                        WinStaObject->cxWallpaper = bmp->SurfObj.sizlBitmap.cx;
                        WinStaObject->cyWallpaper = bmp->SurfObj.sizlBitmap.cy;

                        BITMAPOBJ_UnlockBitmap(bmp);

                        /* change the bitmap's ownership */
                        GDIOBJ_SetOwnership(GdiHandleTable, hNewBitmap, NULL);
                     }
                     hOldBitmap = (HBITMAP)InterlockedExchange((LONG*)&WinStaObject->hbmWallpaper, (LONG)hNewBitmap);
                     if(hOldBitmap != NULL)
                     {
                        /* delete the old wallpaper */
                        NtGdiDeleteObject(hOldBitmap);
                     }
                     
                     /* Set the style */

                     /*default value is center */
                     WinStaObject->WallpaperMode = wmCenter;
                     
                     
                     
                     /* Get a handle to the current users settings */
                     RtlFormatCurrentUserKeyPath(&KeyPath);
                     InitializeObjectAttributes(&ObjectAttributes,&KeyPath,OBJ_CASE_INSENSITIVE,NULL,NULL);
                     ZwOpenKey(&CurrentUserKey, KEY_READ, &ObjectAttributes);
                     RtlFreeUnicodeString(&KeyPath);

                     /* open up the settings to read the values */
                     InitializeObjectAttributes(&KeyAttributes, &Key, OBJ_CASE_INSENSITIVE,
                              CurrentUserKey, NULL);
                     ZwOpenKey(&KeyHandle, KEY_READ, &KeyAttributes);
                     ZwClose(CurrentUserKey);
                     
                     /* read the tile value in the registry */
                     Status = ZwQueryValueKey(KeyHandle, &Tile, KeyValuePartialInformation,
                                              0, 0, &ResLength);

                     /* fall back to .DEFAULT if we didnt find values */
                     if(Status == STATUS_INVALID_HANDLE)
                     {
                        RtlInitUnicodeString (&KeyPath,L"\\Registry\\User\\.Default\\Control Panel\\Desktop");
                        InitializeObjectAttributes(&KeyAttributes, &KeyPath, OBJ_CASE_INSENSITIVE,
                                                   NULL, NULL);
                        ZwOpenKey(&KeyHandle, KEY_READ, &KeyAttributes);
                        ZwQueryValueKey(KeyHandle, &Tile, KeyValuePartialInformation,
                                        0, 0, &ResLength);
                     }

                     ResLength += sizeof(KEY_VALUE_PARTIAL_INFORMATION);
                     KeyValuePartialInfo = ExAllocatePoolWithTag(PagedPool, ResLength, TAG_STRING);
                     Length = ResLength;

                     if(!KeyValuePartialInfo)
                     {
                        NtClose(KeyHandle);
                        return FALSE;
                     }

                     Status = ZwQueryValueKey(KeyHandle, &Tile, KeyValuePartialInformation,
                                              (PVOID)KeyValuePartialInfo, Length, &ResLength);
                     if(!NT_SUCCESS(Status) || (KeyValuePartialInfo->Type != REG_SZ))
                     {
                        ZwClose(KeyHandle);
                        ExFreePool(KeyValuePartialInfo);
                        return FALSE;
                     }
                
                     Tile.Length = KeyValuePartialInfo->DataLength;
                     Tile.MaximumLength = KeyValuePartialInfo->DataLength;
                     Tile.Buffer = (PWSTR)KeyValuePartialInfo->Data;
                     
                     Status = RtlUnicodeStringToInteger(&Tile, 0, &TileNum);
                     if(!NT_SUCCESS(Status))
                     {
                        TileNum = 0;
                     }
                     ExFreePool(KeyValuePartialInfo);
                     
                     /* start over again and look for the style*/
                     ResLength = 0;
                     Status = ZwQueryValueKey(KeyHandle, &Style, KeyValuePartialInformation,
                                              0, 0, &ResLength);
                            
                     ResLength += sizeof(KEY_VALUE_PARTIAL_INFORMATION);
                     KeyValuePartialInfo = ExAllocatePoolWithTag(PagedPool, ResLength, TAG_STRING);
                     Length = ResLength;

                     if(!KeyValuePartialInfo)
                     {
                        ZwClose(KeyHandle);
                        return FALSE;
                     }

                     Status = ZwQueryValueKey(KeyHandle, &Style, KeyValuePartialInformation,
                                              (PVOID)KeyValuePartialInfo, Length, &ResLength);
                     if(!NT_SUCCESS(Status) || (KeyValuePartialInfo->Type != REG_SZ))
                     {
                        ZwClose(KeyHandle);
                        ExFreePool(KeyValuePartialInfo);
                        return FALSE;
                     }
                
                     Style.Length = KeyValuePartialInfo->DataLength;
                     Style.MaximumLength = KeyValuePartialInfo->DataLength;
                     Style.Buffer = (PWSTR)KeyValuePartialInfo->Data;
                     
                     Status = RtlUnicodeStringToInteger(&Style, 0, &StyleNum);
                     if(!NT_SUCCESS(Status))
                     {
                        StyleNum = 0;
                     }
                     ExFreePool(KeyValuePartialInfo);
                     
                     /* Check the values we found in the registry */
                     if(TileNum && !StyleNum)
                     {
                        WinStaObject->WallpaperMode = wmTile;                     
                     }
                     else if(!TileNum && StyleNum == 2)
                     {
                        WinStaObject->WallpaperMode = wmStretch;
                     }
                     
                     ZwClose(KeyHandle);
                     break;
                  }
               case SPI_GETDESKWALLPAPER:
                  /* This function expects different parameters than the user mode version!

                     We basically return the current wallpaper handle - if any. The user
                     mode version should load the string from the registry and return it
                     without calling this function */
                  ASSERT(pvParam);
                  *(HBITMAP*)pvParam = (HBITMAP)WinStaObject->hbmWallpaper;
                  break;
            }

            /* FIXME save the value to the registry */

            ObDereferenceObject(WinStaObject);
            break;
         }
      case SPI_SETWORKAREA:
         {
            RECT *rc;
            PDESKTOP_OBJECT Desktop = PsGetCurrentThreadWin32Thread()->Desktop;

            if(!Desktop)
            {
               /* FIXME - Set last error */
               return FALSE;
            }

            ASSERT(pvParam);
            rc = (RECT*)pvParam;
            Desktop->WorkArea = *rc;
            bChanged = TRUE;

            break;
         }
      case SPI_GETWORKAREA:
         {
            PDESKTOP_OBJECT Desktop = PsGetCurrentThreadWin32Thread()->Desktop;

            if(!Desktop)
            {
               /* FIXME - Set last error */
               return FALSE;
            }

            ASSERT(pvParam);
            IntGetDesktopWorkArea(Desktop, (PRECT)pvParam);

            break;
         }
      case SPI_SETGRADIENTCAPTIONS:
         {
            GradientCaptions = (pvParam != NULL);
            /* FIXME - should be checked if the color depth is higher than 8bpp? */
            bChanged = TRUE;
            break;
         }
      case SPI_GETGRADIENTCAPTIONS:
         {
            HDC hDC;
            BOOL Ret = GradientCaptions;

            hDC = IntGetScreenDC();
            if(!hDC)
            {
               return FALSE;
            }
               Ret = (NtGdiGetDeviceCaps(hDC, BITSPIXEL) > 8) && Ret;

               ASSERT(pvParam);
               *((PBOOL)pvParam) = Ret;
            break;
            }
      case SPI_SETFONTSMOOTHING:
         {
            IntEnableFontRendering(uiParam != 0);
            bChanged = TRUE;
            break;
         }
      case SPI_GETFONTSMOOTHING:
         {
            ASSERT(pvParam);
            *((BOOL*)pvParam) = IntIsFontRenderingEnabled();
            break;
         }
      case SPI_GETICONTITLELOGFONT:
         {
            ASSERT(pvParam);
            *((LOGFONTW*)pvParam) = IconFont;
            break;
         }
      case SPI_GETNONCLIENTMETRICS:
         {
            ASSERT(pvParam);
            *((NONCLIENTMETRICSW*)pvParam) = pMetrics;
            break;
         }
      case SPI_SETNONCLIENTMETRICS:
         {
            ASSERT(pvParam);
            pMetrics = *((NONCLIENTMETRICSW*)pvParam);
            bChanged = TRUE;
            break;
         }
      case SPI_GETMINIMIZEDMETRICS:
         {
            ASSERT(pvParam);
            *((MINIMIZEDMETRICS*)pvParam) = MinimizedMetrics;
            break;
         }
      case SPI_SETMINIMIZEDMETRICS:
         {
            ASSERT(pvParam);
            MinimizedMetrics = *((MINIMIZEDMETRICS*)pvParam);
            bChanged = TRUE;
            break;
         }
      case SPI_GETFOCUSBORDERHEIGHT:
         {
            ASSERT(pvParam);
            *((UINT*)pvParam) = FocusBorderHeight;
            break;
         }
      case SPI_GETFOCUSBORDERWIDTH:
         {
            ASSERT(pvParam);
            *((UINT*)pvParam) = FocusBorderWidth;
            break;
         }
      case SPI_SETFOCUSBORDERHEIGHT:
         {
            FocusBorderHeight = (UINT)pvParam;
            bChanged = TRUE;
            break;
         }
      case SPI_SETFOCUSBORDERWIDTH:
         {
            FocusBorderWidth = (UINT)pvParam;
            bChanged = TRUE;
            break;
         }

      default:
         {
            DPRINT1("SystemParametersInfo: Unsupported Action 0x%x (uiParam: 0x%x, pvParam: 0x%x, fWinIni: 0x%x)\n",
                    uiAction, uiParam, pvParam, fWinIni);
            return FALSE;
         }
   }
   /* Did we change something ? */
   if (bChanged)
   {
      /* Shall we send a WM_SETTINGCHANGE message ? */
      if (fWinIni & (SPIF_UPDATEINIFILE | SPIF_SENDCHANGE))
      {
         /* Broadcast WM_SETTINGCHANGE to all toplevel windows */
         /* FIXME: lParam should be pointer to a string containing the reg key */
         UserPostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, (WPARAM)uiAction, 0);
}
   }
   return TRUE;
}

/*
 * @implemented
 */
BOOL FASTCALL
UserSystemParametersInfo(
   UINT uiAction,
   UINT uiParam,
   PVOID pvParam,
   UINT fWinIni)
{
   NTSTATUS Status;

   switch(uiAction)
   {
      case SPI_SETDOUBLECLKWIDTH:
      case SPI_SETDOUBLECLKHEIGHT:
      case SPI_SETDOUBLECLICKTIME:
      case SPI_SETGRADIENTCAPTIONS:
      case SPI_SETFONTSMOOTHING:
      case SPI_SETFOCUSBORDERHEIGHT:
      case SPI_SETFOCUSBORDERWIDTH:
         {
            return (DWORD)IntSystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
         }
      case SPI_SETWORKAREA:
         {
            RECT rc;
            Status = MmCopyFromCaller(&rc, (PRECT)pvParam, sizeof(RECT));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( (DWORD)IntSystemParametersInfo(uiAction, uiParam, &rc, fWinIni));
         }
      case SPI_GETWORKAREA:
         {
            RECT rc;

            if(!IntSystemParametersInfo(uiAction, uiParam, &rc, fWinIni))
            {
               return( FALSE);
            }

            Status = MmCopyToCaller((PRECT)pvParam, &rc, sizeof(RECT));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( TRUE);
         }
      case SPI_GETFONTSMOOTHING:
      case SPI_GETGRADIENTCAPTIONS:
      case SPI_GETFOCUSBORDERHEIGHT:
      case SPI_GETFOCUSBORDERWIDTH:
	  case SPI_GETWHEELSCROLLLINES:
      case SPI_GETWHEELSCROLLCHARS:
	  case SPI_GETSCREENSAVERRUNNING:
	  case SPI_SETSCREENSAVERRUNNING:
	  case SPI_GETSCREENSAVETIMEOUT:
	  case SPI_SETSCREENSAVETIMEOUT:
	  case SPI_GETSCREENSAVEACTIVE:
	  case SPI_GETFLATMENU:
      case SPI_SETFLATMENU:
         {
            BOOL Ret;

            if(!IntSystemParametersInfo(uiAction, uiParam, &Ret, fWinIni))
            {
               return( FALSE);
            }

            Status = MmCopyToCaller(pvParam, &Ret, sizeof(BOOL));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( TRUE);
         }
      case SPI_SETDESKWALLPAPER:
         {
            /* !!! 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))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( IntSystemParametersInfo(SPI_SETDESKWALLPAPER, 0, &hbmWallpaper, fWinIni));
         }
      case SPI_GETDESKWALLPAPER:
         {
            /* !!! As opposed to the user mode version this version returns a handle
                   to the bitmap! */
            HBITMAP hbmWallpaper;
            BOOL Ret;

            Ret = IntSystemParametersInfo(SPI_GETDESKWALLPAPER, 0, &hbmWallpaper, fWinIni);

            Status = MmCopyToCaller(pvParam, &hbmWallpaper, sizeof(HBITMAP));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( Ret);
         }
      case SPI_GETICONTITLELOGFONT:
         {
            LOGFONTW IconFont;

            if(!IntSystemParametersInfo(uiAction, uiParam, &IconFont, fWinIni))
            {
               return( FALSE);
            }

            Status = MmCopyToCaller(pvParam, &IconFont, sizeof(LOGFONTW));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( TRUE);
         }
      case SPI_GETNONCLIENTMETRICS:
      case SPI_SETNONCLIENTMETRICS:
         {
            NONCLIENTMETRICSW metrics;

            Status = MmCopyFromCaller(&metrics, pvParam, sizeof(NONCLIENTMETRICSW));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            if(metrics.cbSize != sizeof(NONCLIENTMETRICSW))
            {
               SetLastWin32Error(ERROR_INVALID_PARAMETER);
               return( FALSE);
            }

            if(!IntSystemParametersInfo(uiAction, uiParam, &metrics, fWinIni))
            {
               return( FALSE);
            }

            Status = MmCopyToCaller(pvParam, &metrics, sizeof(NONCLIENTMETRICSW));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);
               return( FALSE);
            }
            return( TRUE);
         }
      case SPI_GETMINIMIZEDMETRICS:
      case SPI_SETMINIMIZEDMETRICS:
         {
            MINIMIZEDMETRICS minimetrics;

            Status = MmCopyFromCaller(&minimetrics, pvParam, sizeof(MINIMIZEDMETRICS));
            if(!NT_SUCCESS(Status))
            {
               SetLastNtError(Status);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -