📄 misc.c
字号:
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_GETANIMATION:
{
ASSERT(pvParam);
*(( ANIMATIONINFO*)pvParam) = anim;
break;
}
case SPI_SETANIMATION:
{
ASSERT(pvParam);
anim = *((ANIMATIONINFO*)pvParam);
bChanged = TRUE;
}
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("FIXME: Unsupported SPI 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;
}
static BOOL
UserSystemParametersInfo_StructSet(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni,
PVOID pBuffer, /* private kmode buffer */
UINT cbSize /* size of buffer and expected size usermode data, pointed by pvParam */
)
{
NTSTATUS Status = STATUS_SUCCESS;
/* remove this when all spi are implement */
DPRINT1("UserSystemParametersInfo_StructSet SPI Action 0x%x (uiParam: 0x%x, fWinIni: 0x%x)\n",uiAction, uiParam, fWinIni);
_SEH_TRY
{
ProbeForRead(pvParam, cbSize, 1);
RtlCopyMemory(pBuffer,pvParam,cbSize);
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return( FALSE);
}
if(*(PUINT)pBuffer != cbSize)
{
SetLastWin32Error(ERROR_INVALID_PARAMETER);
return( FALSE);
}
return IntSystemParametersInfo(uiAction, uiParam, pBuffer, fWinIni);
}
static BOOL
UserSystemParametersInfo_StructGet(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni,
PVOID pBuffer, /* private kmode buffer */
UINT cbSize /* size of buffer and expected size usermode data, pointed by pvParam */
)
{
NTSTATUS Status = STATUS_SUCCESS;
/* remove this when all spi are implement */
DPRINT1("UserSystemParametersInfo_StructGet SPI Action 0x%x (uiParam: 0x%x, fWinIni: 0x%x)\n",uiAction, uiParam, fWinIni);
_SEH_TRY
{
ProbeForRead(pvParam, cbSize, 1);
/* Copy only first UINT describing structure size*/
*((PUINT)pBuffer) = *((PUINT)pvParam);
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return( FALSE);
}
if(*((PUINT)pBuffer) != cbSize)
{
SetLastWin32Error(ERROR_INVALID_PARAMETER);
return( FALSE);
}
if(!IntSystemParametersInfo(uiAction, uiParam, pBuffer, fWinIni))
{
return( FALSE);
}
_SEH_TRY
{
ProbeForWrite(pvParam, cbSize, 1);
RtlCopyMemory(pvParam,pBuffer,cbSize);
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return( FALSE);
}
return( TRUE);
}
/*
* @implemented
*/
BOOL FASTCALL
UserSystemParametersInfo(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni)
{
NTSTATUS Status = STATUS_SUCCESS;
/* FIXME: Support Windows Vista SPI Actions */
switch(uiAction)
{
#if 1 /* only for 32bit applications */
case SPI_SETLOWPOWERACTIVE:
case SPI_SETLOWPOWERTIMEOUT:
case SPI_SETPOWEROFFACTIVE:
case SPI_SETPOWEROFFTIMEOUT:
#endif
case SPI_SETICONS:
case SPI_SETSCREENSAVETIMEOUT:
case SPI_SETSCREENSAVEACTIVE:
case SPI_SETDOUBLECLKWIDTH:
case SPI_SETDOUBLECLKHEIGHT:
case SPI_SETDOUBLECLICKTIME:
case SPI_SETFONTSMOOTHING:
case SPI_SETMOUSEHOVERTIME:
case SPI_SETMOUSEHOVERWIDTH:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -