misc.c
来自「一个类似windows」· C语言 代码 · 共 1,945 行 · 第 1/4 页
C
1,945 行
pMetrics.iScrollWidth = UserGetSystemMetrics(SM_CXVSCROLL);
pMetrics.iScrollHeight = UserGetSystemMetrics(SM_CYHSCROLL);
pMetrics.iCaptionWidth = UserGetSystemMetrics(SM_CXSIZE);
pMetrics.iCaptionHeight = UserGetSystemMetrics(SM_CYSIZE);
pMetrics.iSmCaptionWidth = UserGetSystemMetrics(SM_CXSMSIZE);
pMetrics.iSmCaptionHeight = UserGetSystemMetrics(SM_CYSMSIZE);
pMetrics.iMenuWidth = UserGetSystemMetrics(SM_CXMENUSIZE);
pMetrics.iMenuHeight = UserGetSystemMetrics(SM_CYMENUSIZE);
pMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
bInitialized = TRUE;
}
switch(uiAction)
{
case SPI_SETDOUBLECLKWIDTH:
case SPI_SETDOUBLECLKHEIGHT:
case SPI_SETDOUBLECLICKTIME:
case SPI_SETDESKWALLPAPER:
case SPI_GETDESKWALLPAPER:
{
PSYSTEM_CURSORINFO CurInfo;
Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
KernelMode,
0,
&WinStaObject);
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return (DWORD)FALSE;
}
switch(uiAction)
{
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 0;
}
Status = ZwQueryValueKey(KeyHandle, &Tile, KeyValuePartialInformation,
(PVOID)KeyValuePartialInfo, Length, &ResLength);
if(!NT_SUCCESS(Status) || (KeyValuePartialInfo->Type != REG_SZ))
{
ZwClose(KeyHandle);
ExFreePool(KeyValuePartialInfo);
return 0;
}
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 0;
}
Status = ZwQueryValueKey(KeyHandle, &Style, KeyValuePartialInformation,
(PVOID)KeyValuePartialInfo, Length, &ResLength);
if(!NT_SUCCESS(Status) || (KeyValuePartialInfo->Type != REG_SZ))
{
ZwClose(KeyHandle);
ExFreePool(KeyValuePartialInfo);
return 0;
}
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);
return TRUE;
}
case SPI_SETWORKAREA:
{
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:
{
GradientCaptions = (pvParam != NULL);
/* FIXME - should be checked if the color depth is higher than 8bpp? */
return TRUE;
}
case SPI_GETGRADIENTCAPTIONS:
{
HDC hDC;
BOOL Ret = GradientCaptions;
hDC = IntGetScreenDC();
if(hDC)
{
Ret = (NtGdiGetDeviceCaps(hDC, BITSPIXEL) > 8) && Ret;
ASSERT(pvParam);
*((PBOOL)pvParam) = Ret;
return TRUE;
}
return FALSE;
}
case SPI_SETFONTSMOOTHING:
{
IntEnableFontRendering(uiParam != 0);
return TRUE;
}
case SPI_GETFONTSMOOTHING:
{
ASSERT(pvParam);
*((BOOL*)pvParam) = IntIsFontRenderingEnabled();
return TRUE;
}
case SPI_GETICONTITLELOGFONT:
{
ASSERT(pvParam);
*((LOGFONTW*)pvParam) = IconFont;
return TRUE;
}
case SPI_GETNONCLIENTMETRICS:
{
ASSERT(pvParam);
*((NONCLIENTMETRICSW*)pvParam) = pMetrics;
return TRUE;
}
case SPI_GETFOCUSBORDERHEIGHT:
{
ASSERT(pvParam);
*((UINT*)pvParam) = FocusBorderHeight;
return TRUE;
}
case SPI_GETFOCUSBORDERWIDTH:
{
ASSERT(pvParam);
*((UINT*)pvParam) = FocusBorderWidth;
return TRUE;
}
case SPI_SETFOCUSBORDERHEIGHT:
{
FocusBorderHeight = (UINT)pvParam;
return TRUE;
}
case SPI_SETFOCUSBORDERWIDTH:
{
FocusBorderWidth = (UINT)pvParam;
return TRUE;
}
default:
{
DPRINT1("SystemParametersInfo: Unsupported Action 0x%x (uiParam: 0x%x, pvParam: 0x%x, fWinIni: 0x%x)\n",
uiAction, uiParam, pvParam, fWinIni);
return FALSE;
}
}
return FALSE;
}
/*
* @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:
{
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:
{
NONCLIENTMETRICSW metrics;
Status = MmCopyFromCaller(&metrics.cbSize, pvParam, sizeof(UINT));
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.cbSize, sizeof(NONCLIENTMETRICSW));
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return( FALSE);
}
return( TRUE);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?