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 #include <rosrtl/devmode.h>
17 #include <rosrtl/logfont.h>
25 GetSystemMetrics(int nIndex
)
27 return(NtUserGetSystemMetrics(nIndex
));
34 BOOL STDCALL
SetDeskWallpaper(LPCSTR filename
)
36 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
42 SystemParametersInfoA(UINT uiAction
,
49 case SPI_SETDOUBLECLKWIDTH
:
50 case SPI_SETDOUBLECLKHEIGHT
:
51 case SPI_SETDOUBLECLICKTIME
:
52 case SPI_SETGRADIENTCAPTIONS
:
53 case SPI_SETFONTSMOOTHING
:
54 case SPI_SETFOCUSBORDERHEIGHT
:
55 case SPI_SETFOCUSBORDERWIDTH
:
58 case SPI_GETFONTSMOOTHING
:
59 case SPI_GETGRADIENTCAPTIONS
:
60 case SPI_GETFOCUSBORDERHEIGHT
:
61 case SPI_GETFOCUSBORDERWIDTH
:
63 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
65 case SPI_GETNONCLIENTMETRICS
:
67 LPNONCLIENTMETRICSA nclma
= (LPNONCLIENTMETRICSA
)pvParam
;
68 NONCLIENTMETRICSW nclmw
;
69 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
71 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
75 nclma
->iBorderWidth
= nclmw
.iBorderWidth
;
76 nclma
->iScrollWidth
= nclmw
.iScrollWidth
;
77 nclma
->iScrollHeight
= nclmw
.iScrollHeight
;
78 nclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
79 nclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
80 nclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
81 nclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
82 nclma
->iMenuWidth
= nclmw
.iMenuWidth
;
83 nclma
->iMenuHeight
= nclmw
.iMenuHeight
;
84 RosRtlLogFontW2A(&(nclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
85 RosRtlLogFontW2A(&(nclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
86 RosRtlLogFontW2A(&(nclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
87 RosRtlLogFontW2A(&(nclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
88 RosRtlLogFontW2A(&(nclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
91 case SPI_GETICONTITLELOGFONT
:
94 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
96 RosRtlLogFontW2A(pvParam
, &lfw
);
99 case SPI_GETDESKWALLPAPER
:
105 /* Get the desktop bitmap handle, this does NOT return the file name! */
106 if(!NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, 0, &hbmWallpaper
, 0))
108 /* Return an empty string, no wallpapaper is set */
109 *(CHAR
*)pvParam
= '\0';
114 /* FIXME - Read the registry key for now, but what happens if the wallpaper was
115 changed without SPIF_UPDATEINIFILE?! */
116 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
117 L
"Control Panel\\Desktop",
118 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
122 if(RegQueryValueExA(hKey
,
127 &Size
) == ERROR_SUCCESS
136 case SPI_SETDESKWALLPAPER
:
138 HBITMAP hNewWallpaper
;
140 LPSTR lpWallpaper
= (LPSTR
)pvParam
;
142 if(lpWallpaper
!= NULL
&& *lpWallpaper
!= '\0')
144 hNewWallpaper
= LoadImageA(0, lpWallpaper
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
145 if(hNewWallpaper
== NULL
)
152 hNewWallpaper
= NULL
;
156 /* Set the wallpaper bitmap */
157 if(!NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, &hNewWallpaper
, fWinIni
& SPIF_SENDCHANGE
))
159 if(hNewWallpaper
!= NULL
)
160 DeleteObject(hNewWallpaper
);
163 /* Do not use the bitmap handle anymore, it doesn't belong to our process anymore! */
166 if(fWinIni
& SPIF_UPDATEINIFILE
)
168 /* Save the path to the file in the registry */
170 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
171 L
"Control Panel\\Desktop",
172 0, KEY_SET_VALUE
, &hKey
) == ERROR_SUCCESS
)
174 Ret
= RegSetValueExA(hKey
, "Wallpaper", 0, REG_SZ
, (LPBYTE
)(lpWallpaper
!= NULL
? lpWallpaper
: ""),
175 (lpWallpaper
!= NULL
? (lstrlenA(lpWallpaper
) + 1) * sizeof(CHAR
) : sizeof(CHAR
)) == ERROR_SUCCESS
);
180 RedrawWindow(GetDesktopWindow(), NULL
, NULL
, RDW_INVALIDATE
| RDW_UPDATENOW
);
194 SystemParametersInfoW(UINT uiAction
,
201 case SPI_GETDESKWALLPAPER
:
207 /* Get the desktop bitmap handle, this does NOT return the file name! */
208 if(!NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, 0, &hbmWallpaper
, 0))
210 /* Return an empty string, no wallpapaper is set */
211 *(WCHAR
*)pvParam
= L
'\0';
216 /* FIXME - Read the registry key for now, but what happens if the wallpaper was
217 changed without SPIF_UPDATEINIFILE?! */
218 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
219 L
"Control Panel\\Desktop",
220 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
223 Size
= uiParam
* sizeof(WCHAR
);
224 if(RegQueryValueExW(hKey
,
229 &Size
) == ERROR_SUCCESS
238 case SPI_SETDESKWALLPAPER
:
240 HBITMAP hNewWallpaper
;
242 LPWSTR lpWallpaper
= (LPWSTR
)pvParam
;
244 if(lpWallpaper
!= NULL
&& *lpWallpaper
!= L
'\0')
246 hNewWallpaper
= LoadImageW(0, lpWallpaper
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
248 if(hNewWallpaper
== NULL
)
255 hNewWallpaper
= NULL
;
259 /* Set the wallpaper bitmap */
260 if(!NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, &hNewWallpaper
, fWinIni
& SPIF_SENDCHANGE
))
262 if(hNewWallpaper
!= NULL
)
263 DeleteObject(hNewWallpaper
);
266 /* Do not use the bitmap handle anymore, it doesn't belong to our process anymore! */
268 if(fWinIni
& SPIF_UPDATEINIFILE
)
270 /* Save the path to the file in the registry */
273 if(RegOpenKeyExW(HKEY_CURRENT_USER
,
274 L
"Control Panel\\Desktop",
275 0, KEY_SET_VALUE
, &hKey
) == ERROR_SUCCESS
)
277 Ret
= RegSetValueExW(hKey
, L
"Wallpaper", 0, REG_SZ
, (lpWallpaper
!= NULL
? (LPBYTE
)lpWallpaper
: (LPBYTE
)L
""),
278 (lpWallpaper
!= NULL
? (lstrlenW(lpWallpaper
) + 1) * sizeof(WCHAR
) : sizeof(WCHAR
)) == ERROR_SUCCESS
);
283 RedrawWindow(GetDesktopWindow(), NULL
, NULL
, RDW_INVALIDATE
| RDW_UPDATENOW
);
288 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
300 return NtUserCloseDesktop(hDesktop
);
308 CreateDesktopA(LPCSTR lpszDesktop
,
312 ACCESS_MASK dwDesiredAccess
,
313 LPSECURITY_ATTRIBUTES lpsa
)
315 ANSI_STRING DesktopNameA
;
316 UNICODE_STRING DesktopNameU
;
320 if (lpszDesktop
!= NULL
)
322 RtlInitAnsiString(&DesktopNameA
, (LPSTR
)lpszDesktop
);
323 RtlAnsiStringToUnicodeString(&DesktopNameU
, &DesktopNameA
, TRUE
);
327 RtlInitUnicodeString(&DesktopNameU
, NULL
);
330 RosRtlDevModeA2W ( &DevmodeW
, pDevmode
);
332 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
339 RtlFreeUnicodeString(&DesktopNameU
);
348 CreateDesktopW(LPCWSTR lpszDesktop
,
352 ACCESS_MASK dwDesiredAccess
,
353 LPSECURITY_ATTRIBUTES lpsa
)
355 UNICODE_STRING DesktopName
;
359 hWinSta
= NtUserGetProcessWindowStation();
361 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
363 hDesktop
= NtUserCreateDesktop(&DesktopName
,
379 HWINSTA WindowStation
,
380 DESKTOPENUMPROCA EnumFunc
,
383 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
393 HWINSTA WindowStation
,
394 DESKTOPENUMPROCW EnumFunc
,
397 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
409 return NtUserGetThreadDesktop(dwThreadId
, 0);
422 ACCESS_MASK dwDesiredAccess
)
424 ANSI_STRING DesktopNameA
;
425 UNICODE_STRING DesktopNameU
;
428 if (lpszDesktop
!= NULL
) {
429 RtlInitAnsiString(&DesktopNameA
, lpszDesktop
);
430 RtlAnsiStringToUnicodeString(&DesktopNameU
, &DesktopNameA
, TRUE
);
432 RtlInitUnicodeString(&DesktopNameU
, NULL
);
435 hDesktop
= OpenDesktopW(
441 RtlFreeUnicodeString(&DesktopNameU
);
456 ACCESS_MASK dwDesiredAccess
)
458 UNICODE_STRING DesktopName
;
460 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
462 return NtUserOpenDesktop(
477 ACCESS_MASK dwDesiredAccess
)
479 return NtUserOpenInputDesktop(
494 return NtUserPaintDesktop(hdc
);
506 return NtUserSetThreadDesktop(hDesktop
);
518 return NtUserSwitchDesktop(hDesktop
);
526 SetShellWindowEx(HWND hwndShell
, HWND hwndShellListView
)
528 return NtUserSetShellWindowEx(hwndShell
, hwndShellListView
);
536 SetShellWindow(HWND hwndShell
)
538 return SetShellWindowEx(hwndShell
, hwndShell
);
548 return NtUserGetShellWindow();