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
14 #include <wine/debug.h>
15 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
17 /*********************************************************************
18 * desktop class descriptor
20 #if 0 // Kept for referencing.
21 const struct builtin_class_descr DESKTOP_builtin_class
=
23 WC_DESKTOP
, /* name */
24 CS_DBLCLKS
, /* style */
25 NULL
, /* procA (winproc is Unicode only) */
26 (WNDPROC
) DesktopWndProc
, /* procW */
28 IDC_ARROW
, /* cursor */
29 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
34 DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
36 TRACE("Desktop Class Atom! hWnd 0x%x, Msg %d\n", hwnd
, message
);
37 if (message
== WM_NCCREATE
) return TRUE
;
38 return 0; /* all other messages are ignored */
43 LogFontA2W(LPLOGFONTW pW
, CONST LOGFONTA
*pA
)
45 #define COPYS(f,len) MultiByteToWideChar ( CP_THREAD_ACP, 0, pA->f, len, pW->f, len )
46 #define COPYN(f) pW->f = pA->f
57 COPYN(lfOutPrecision
);
58 COPYN(lfClipPrecision
);
60 COPYN(lfPitchAndFamily
);
61 COPYS(lfFaceName
,LF_FACESIZE
);
69 LogFontW2A(LPLOGFONTA pA
, CONST LOGFONTW
*pW
)
71 #define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
72 #define COPYN(f) pA->f = pW->f
83 COPYN(lfOutPrecision
);
84 COPYN(lfClipPrecision
);
86 COPYN(lfPitchAndFamily
);
87 COPYS(lfFaceName
,LF_FACESIZE
);
94 RealGetSystemMetrics(int nIndex
)
97 // FIXME("Global Server Data -> %x\n",gpsi);
98 if (nIndex
< 0 || nIndex
>= SM_CMETRICS
) return 0;
99 return gpsi
->aiSysMet
[nIndex
];
106 GetSystemMetrics(int nIndex
)
111 if (!gpsi
) // Fixme! Hax! Need Timos delay load support?
113 return RealGetSystemMetrics(nIndex
);
118 Hook
= BeginIfHookedUserApiHook();
120 /* Bypass SEH and go direct. */
121 if (!Hook
) return RealGetSystemMetrics(nIndex
);
125 Ret
= guah
.GetSystemMetrics(nIndex
);
127 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
140 BOOL WINAPI
SetDeskWallpaper(LPCSTR filename
)
142 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
146 RealSystemParametersInfoA(UINT uiAction
,
154 case SPI_GETNONCLIENTMETRICS
:
156 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
157 NONCLIENTMETRICSW nclmw
;
158 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
160 SetLastError(ERROR_INVALID_PARAMETER
);
163 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
165 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
169 pnclma
->iBorderWidth
= nclmw
.iBorderWidth
;
170 pnclma
->iScrollWidth
= nclmw
.iScrollWidth
;
171 pnclma
->iScrollHeight
= nclmw
.iScrollHeight
;
172 pnclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
173 pnclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
174 pnclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
175 pnclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
176 pnclma
->iMenuWidth
= nclmw
.iMenuWidth
;
177 pnclma
->iMenuHeight
= nclmw
.iMenuHeight
;
178 LogFontW2A(&(pnclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
179 LogFontW2A(&(pnclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
180 LogFontW2A(&(pnclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
181 LogFontW2A(&(pnclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
182 LogFontW2A(&(pnclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
185 case SPI_SETNONCLIENTMETRICS
:
187 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
188 NONCLIENTMETRICSW nclmw
;
189 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
191 SetLastError(ERROR_INVALID_PARAMETER
);
194 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
195 nclmw
.iBorderWidth
= pnclma
->iBorderWidth
;
196 nclmw
.iScrollWidth
= pnclma
->iScrollWidth
;
197 nclmw
.iScrollHeight
= pnclma
->iScrollHeight
;
198 nclmw
.iCaptionWidth
= pnclma
->iCaptionWidth
;
199 nclmw
.iCaptionHeight
= pnclma
->iCaptionHeight
;
200 nclmw
.iSmCaptionWidth
= pnclma
->iSmCaptionWidth
;
201 nclmw
.iSmCaptionHeight
= pnclma
->iSmCaptionHeight
;
202 nclmw
.iMenuWidth
= pnclma
->iMenuWidth
;
203 nclmw
.iMenuHeight
= pnclma
->iMenuHeight
;
204 LogFontA2W(&(nclmw
.lfCaptionFont
), &(pnclma
->lfCaptionFont
));
205 LogFontA2W(&(nclmw
.lfSmCaptionFont
), &(pnclma
->lfSmCaptionFont
));
206 LogFontA2W(&(nclmw
.lfMenuFont
), &(pnclma
->lfMenuFont
));
207 LogFontA2W(&(nclmw
.lfStatusFont
), &(pnclma
->lfStatusFont
));
208 LogFontA2W(&(nclmw
.lfMessageFont
), &(pnclma
->lfMessageFont
));
210 return SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
213 case SPI_GETICONMETRICS
:
215 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
217 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
219 SetLastError(ERROR_INVALID_PARAMETER
);
222 icmw
.cbSize
= sizeof(ICONMETRICSW
);
223 if (!SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
227 picma
->iHorzSpacing
= icmw
.iHorzSpacing
;
228 picma
->iVertSpacing
= icmw
.iVertSpacing
;
229 picma
->iTitleWrap
= icmw
.iTitleWrap
;
230 LogFontW2A(&(picma
->lfFont
), &(icmw
.lfFont
));
233 case SPI_SETICONMETRICS
:
235 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
237 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
239 SetLastError(ERROR_INVALID_PARAMETER
);
242 icmw
.cbSize
= sizeof(ICONMETRICSW
);
243 icmw
.iHorzSpacing
= picma
->iHorzSpacing
;
244 icmw
.iVertSpacing
= picma
->iVertSpacing
;
245 icmw
.iTitleWrap
= picma
->iTitleWrap
;
246 LogFontA2W(&(icmw
.lfFont
), &(picma
->lfFont
));
248 return SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
251 case SPI_GETICONTITLELOGFONT
:
254 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
256 LogFontW2A(pvParam
, &lfw
);
259 case SPI_SETICONTITLELOGFONT
:
261 LPLOGFONTA plfa
= (LPLOGFONTA
)pvParam
;
263 LogFontA2W(&lfw
,plfa
);
264 return SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
);
266 case SPI_GETDESKWALLPAPER
:
270 UNICODE_STRING ustrWallpaper
;
271 ANSI_STRING astrWallpaper
;
273 Ret
= NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, MAX_PATH
, awc
, fWinIni
);
274 RtlInitUnicodeString(&ustrWallpaper
, awc
);
275 RtlUnicodeStringToAnsiString(&astrWallpaper
, &ustrWallpaper
, TRUE
);
277 RtlCopyMemory(pvParam
, astrWallpaper
.Buffer
, uiParam
);
278 RtlFreeAnsiString(&astrWallpaper
);
282 case SPI_SETDESKWALLPAPER
:
285 UNICODE_STRING ustrWallpaper
;
290 Status
= RtlCreateUnicodeStringFromAsciiz(&ustrWallpaper
, pvParam
);
291 if (!NT_SUCCESS(Status
))
293 ERR("Status = 0x%x\n", Status
);
296 pvParam
= &ustrWallpaper
;
299 Ret
= NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, pvParam
, fWinIni
);
300 RtlFreeUnicodeString(&ustrWallpaper
);
304 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
308 RealSystemParametersInfoW(UINT uiAction
,
316 case SPI_SETDESKWALLPAPER
:
318 UNICODE_STRING ustrWallpaper
;
320 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
321 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
324 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
332 SystemParametersInfoA(UINT uiAction
,
337 BOOL Hook
, Ret
= FALSE
;
341 Hook
= BeginIfHookedUserApiHook();
343 /* Bypass SEH and go direct. */
344 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
348 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
350 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
364 SystemParametersInfoW(UINT uiAction
,
369 BOOL Hook
, Ret
= FALSE
;
373 Hook
= BeginIfHookedUserApiHook();
375 /* Bypass SEH and go direct. */
376 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
380 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
396 CreateDesktopA(LPCSTR lpszDesktop
,
400 ACCESS_MASK dwDesiredAccess
,
401 LPSECURITY_ATTRIBUTES lpsa
)
403 UNICODE_STRING DesktopNameU
;
405 LPDEVMODEW DevmodeW
= NULL
;
409 /* After conversion, the buffer is zero-terminated */
410 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
414 RtlInitUnicodeString(&DesktopNameU
, NULL
);
418 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
420 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
427 /* Free the string, if it was allocated */
428 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
438 CreateDesktopW(LPCWSTR lpszDesktop
,
442 ACCESS_MASK dwDesiredAccess
,
443 LPSECURITY_ATTRIBUTES lpsa
)
445 OBJECT_ATTRIBUTES oas
;
446 UNICODE_STRING DesktopName
, DesktopDevice
;
449 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
451 /* Retrive WinStation handle. */
452 hWinSta
= NtUserGetProcessWindowStation();
454 /* Initialize the strings. */
455 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
456 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
458 /* Check for process is inherited, set flag if set. */
459 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
461 /* Initialize the attributes for the desktop. */
462 InitializeObjectAttributes( &oas
,
466 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
468 /* Send the request and call to win32k. */
469 hDesktop
= NtUserCreateDesktop( &oas
,
485 HWINSTA WindowStation
,
486 DESKTOPENUMPROCA EnumFunc
,
489 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
499 HWINSTA WindowStation
,
500 DESKTOPENUMPROCW EnumFunc
,
503 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
515 return NtUserGetThreadDesktop(dwThreadId
, 0);
528 ACCESS_MASK dwDesiredAccess
)
530 UNICODE_STRING DesktopNameU
;
535 /* After conversion, the buffer is zero-terminated */
536 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
540 RtlInitUnicodeString(&DesktopNameU
, NULL
);
543 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
548 /* Free the string, if it was allocated */
549 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
564 ACCESS_MASK dwDesiredAccess
)
566 UNICODE_STRING DesktopName
;
567 OBJECT_ATTRIBUTES ObjectAttributes
;
569 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
571 InitializeObjectAttributes(&ObjectAttributes
,
573 OBJ_CASE_INSENSITIVE
,
574 GetProcessWindowStation(),
577 if( fInherit
== TRUE
)
579 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
582 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
590 SetShellWindow(HWND hwndShell
)
592 return SetShellWindowEx(hwndShell
, hwndShell
);
603 pdi
= GetThreadDesktopInfo();
604 if (pdi
) return pdi
->hShellWindow
;