3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/misc/desktop.c
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
16 LogFontW2A(LPLOGFONTA pA
, CONST LOGFONTW
*pW
)
18 #define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
19 #define COPYN(f) pA->f = pW->f
30 COPYN(lfOutPrecision
);
31 COPYN(lfClipPrecision
);
33 COPYN(lfPitchAndFamily
);
34 COPYS(lfFaceName
,LF_FACESIZE
);
44 GetSystemMetrics(int nIndex
)
46 return(NtUserGetSystemMetrics(nIndex
));
53 BOOL STDCALL
SetDeskWallpaper(LPCSTR filename
)
55 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
61 SystemParametersInfoA(UINT uiAction
,
68 case SPI_SETDOUBLECLKWIDTH
:
69 case SPI_SETDOUBLECLKHEIGHT
:
70 case SPI_SETDOUBLECLICKTIME
:
71 case SPI_SETGRADIENTCAPTIONS
:
72 case SPI_SETFONTSMOOTHING
:
73 case SPI_SETFOCUSBORDERHEIGHT
:
74 case SPI_SETFOCUSBORDERWIDTH
:
77 case SPI_GETFONTSMOOTHING
:
78 case SPI_GETGRADIENTCAPTIONS
:
79 case SPI_GETFOCUSBORDERHEIGHT
:
80 case SPI_GETFOCUSBORDERWIDTH
:
82 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
84 case SPI_GETNONCLIENTMETRICS
:
86 LPNONCLIENTMETRICSA nclma
= (LPNONCLIENTMETRICSA
)pvParam
;
87 NONCLIENTMETRICSW nclmw
;
88 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
90 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
94 nclma
->iBorderWidth
= nclmw
.iBorderWidth
;
95 nclma
->iScrollWidth
= nclmw
.iScrollWidth
;
96 nclma
->iScrollHeight
= nclmw
.iScrollHeight
;
97 nclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
98 nclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
99 nclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
100 nclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
101 nclma
->iMenuWidth
= nclmw
.iMenuWidth
;
102 nclma
->iMenuHeight
= nclmw
.iMenuHeight
;
103 LogFontW2A(&(nclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
104 LogFontW2A(&(nclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
105 LogFontW2A(&(nclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
106 LogFontW2A(&(nclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
107 LogFontW2A(&(nclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
110 case SPI_GETICONTITLELOGFONT
:
113 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
115 LogFontW2A(pvParam
, &lfw
);
118 case SPI_GETDESKWALLPAPER
:
124 /* Get the desktop bitmap handle, this does NOT return the file name! */
125 if(!NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, 0, &hbmWallpaper
, 0))
127 /* Return an empty string, no wallpapaper is set */
128 *(CHAR
*)pvParam
= '\0';
133 /* FIXME - Read the registry key for now, but what happens if the wallpaper was
134 changed without SPIF_UPDATEINIFILE?! */
135 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
136 L
"Control Panel\\Desktop",
137 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
141 if(RegQueryValueExA(hKey
,
146 &Size
) == ERROR_SUCCESS
155 case SPI_SETDESKWALLPAPER
:
157 HBITMAP hNewWallpaper
;
159 LPSTR lpWallpaper
= (LPSTR
)pvParam
;
161 if(lpWallpaper
!= NULL
&& *lpWallpaper
!= '\0')
163 hNewWallpaper
= LoadImageA(0, lpWallpaper
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
164 if(hNewWallpaper
== NULL
)
171 hNewWallpaper
= NULL
;
175 /* Set the wallpaper bitmap */
176 if(!NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, &hNewWallpaper
, fWinIni
& SPIF_SENDCHANGE
))
178 if(hNewWallpaper
!= NULL
)
179 DeleteObject(hNewWallpaper
);
182 /* Do not use the bitmap handle anymore, it doesn't belong to our process anymore! */
185 if(fWinIni
& SPIF_UPDATEINIFILE
)
187 /* Save the path to the file in the registry */
189 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
190 L
"Control Panel\\Desktop",
191 0, KEY_SET_VALUE
, &hKey
) == ERROR_SUCCESS
)
193 Ret
= RegSetValueExA(hKey
, "Wallpaper", 0, REG_SZ
, (LPBYTE
)(lpWallpaper
!= NULL
? lpWallpaper
: ""),
194 (lpWallpaper
!= NULL
? (lstrlenA(lpWallpaper
) + 1) * sizeof(CHAR
) : sizeof(CHAR
)) == ERROR_SUCCESS
);
199 RedrawWindow(GetShellWindow(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ERASE
);
213 SystemParametersInfoW(UINT uiAction
,
220 case SPI_GETDESKWALLPAPER
:
226 /* Get the desktop bitmap handle, this does NOT return the file name! */
227 if(!NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, 0, &hbmWallpaper
, 0))
229 /* Return an empty string, no wallpapaper is set */
230 *(WCHAR
*)pvParam
= L
'\0';
235 /* FIXME - Read the registry key for now, but what happens if the wallpaper was
236 changed without SPIF_UPDATEINIFILE?! */
237 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
238 L
"Control Panel\\Desktop",
239 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
242 Size
= uiParam
* sizeof(WCHAR
);
243 if(RegQueryValueExW(hKey
,
248 &Size
) == ERROR_SUCCESS
257 case SPI_SETDESKWALLPAPER
:
259 HBITMAP hNewWallpaper
;
261 LPWSTR lpWallpaper
= (LPWSTR
)pvParam
;
263 if(lpWallpaper
!= NULL
&& *lpWallpaper
!= L
'\0')
265 hNewWallpaper
= LoadImageW(0, lpWallpaper
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
267 if(hNewWallpaper
== NULL
)
274 hNewWallpaper
= NULL
;
278 /* Set the wallpaper bitmap */
279 if(!NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, &hNewWallpaper
, fWinIni
& SPIF_SENDCHANGE
))
281 if(hNewWallpaper
!= NULL
)
282 DeleteObject(hNewWallpaper
);
285 /* Do not use the bitmap handle anymore, it doesn't belong to our process anymore! */
287 if(fWinIni
& SPIF_UPDATEINIFILE
)
289 /* Save the path to the file in the registry */
292 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
293 L
"Control Panel\\Desktop",
294 0, KEY_SET_VALUE
, &hKey
) == ERROR_SUCCESS
)
296 Ret
= (RegSetValueExW(hKey
, L
"Wallpaper", 0, REG_SZ
, (lpWallpaper
!= NULL
? (LPBYTE
)lpWallpaper
: (LPBYTE
)L
""),
297 (lpWallpaper
!= NULL
? (lstrlenW(lpWallpaper
) + 1) * sizeof(WCHAR
) : sizeof(WCHAR
))) == ERROR_SUCCESS
);
302 RedrawWindow(GetShellWindow(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ERASE
);
307 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
319 return NtUserCloseDesktop(hDesktop
);
327 CreateDesktopA(LPCSTR lpszDesktop
,
331 ACCESS_MASK dwDesiredAccess
,
332 LPSECURITY_ATTRIBUTES lpsa
)
334 ANSI_STRING DesktopNameA
;
335 UNICODE_STRING DesktopNameU
;
339 if (lpszDesktop
!= NULL
)
341 RtlInitAnsiString(&DesktopNameA
, (LPSTR
)lpszDesktop
);
342 RtlAnsiStringToUnicodeString(&DesktopNameU
, &DesktopNameA
, TRUE
);
346 RtlInitUnicodeString(&DesktopNameU
, NULL
);
349 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
351 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
358 RtlFreeUnicodeString(&DesktopNameU
);
367 CreateDesktopW(LPCWSTR lpszDesktop
,
371 ACCESS_MASK dwDesiredAccess
,
372 LPSECURITY_ATTRIBUTES lpsa
)
374 UNICODE_STRING DesktopName
;
378 hWinSta
= NtUserGetProcessWindowStation();
380 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
382 hDesktop
= NtUserCreateDesktop(&DesktopName
,
398 HWINSTA WindowStation
,
399 DESKTOPENUMPROCA EnumFunc
,
402 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
412 HWINSTA WindowStation
,
413 DESKTOPENUMPROCW EnumFunc
,
416 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
428 return NtUserGetThreadDesktop(dwThreadId
, 0);
441 ACCESS_MASK dwDesiredAccess
)
443 ANSI_STRING DesktopNameA
;
444 UNICODE_STRING DesktopNameU
;
447 if (lpszDesktop
!= NULL
) {
448 RtlInitAnsiString(&DesktopNameA
, lpszDesktop
);
449 RtlAnsiStringToUnicodeString(&DesktopNameU
, &DesktopNameA
, TRUE
);
451 RtlInitUnicodeString(&DesktopNameU
, NULL
);
454 hDesktop
= OpenDesktopW(
460 RtlFreeUnicodeString(&DesktopNameU
);
475 ACCESS_MASK dwDesiredAccess
)
477 UNICODE_STRING DesktopName
;
479 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
481 return NtUserOpenDesktop(
496 ACCESS_MASK dwDesiredAccess
)
498 return NtUserOpenInputDesktop(
513 return NtUserPaintDesktop(hdc
);
525 return NtUserSetThreadDesktop(hDesktop
);
537 return NtUserSwitchDesktop(hDesktop
);
545 SetShellWindowEx(HWND hwndShell
, HWND hwndShellListView
)
547 return NtUserSetShellWindowEx(hwndShell
, hwndShellListView
);
555 SetShellWindow(HWND hwndShell
)
557 return SetShellWindowEx(hwndShell
, hwndShell
);
567 return NtUserGetShellWindow();