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 */
35 DesktopWndProcW(HWND Wnd
,
40 TRACE("Desktop W Class Atom! hWnd 0x%x, Msg %d\n", Wnd
, Msg
);
48 case WM_DISPLAYCHANGE
:
50 case WM_SYSCOLORCHANGE
:
53 NtUserMessageCall( Wnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DESKTOP
, FALSE
);
54 TRACE("Desktop lResult %d\n", lResult
);
58 case WM_PALETTECHANGED
:
59 if (Wnd
== (HWND
)wParam
) break;
60 case WM_QUERYNEWPALETTE
:
62 HDC hdc
= GetWindowDC( Wnd
);
64 ReleaseDC( Wnd
, hdc
);
69 return (LRESULT
)SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
72 return DefWindowProcW(Wnd
, Msg
, wParam
, lParam
);
79 LogFontA2W(LPLOGFONTW pW
, CONST LOGFONTA
*pA
)
81 #define COPYS(f,len) MultiByteToWideChar ( CP_THREAD_ACP, 0, pA->f, len, pW->f, len )
82 #define COPYN(f) pW->f = pA->f
93 COPYN(lfOutPrecision
);
94 COPYN(lfClipPrecision
);
96 COPYN(lfPitchAndFamily
);
97 COPYS(lfFaceName
,LF_FACESIZE
);
105 LogFontW2A(LPLOGFONTA pA
, CONST LOGFONTW
*pW
)
107 #define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
108 #define COPYN(f) pA->f = pW->f
113 COPYN(lfOrientation
);
119 COPYN(lfOutPrecision
);
120 COPYN(lfClipPrecision
);
122 COPYN(lfPitchAndFamily
);
123 COPYS(lfFaceName
,LF_FACESIZE
);
130 RealGetSystemMetrics(int nIndex
)
133 // FIXME("Global Server Data -> %x\n",gpsi);
134 if (nIndex
< 0 || nIndex
>= SM_CMETRICS
) return 0;
135 return gpsi
->aiSysMet
[nIndex
];
142 GetSystemMetrics(int nIndex
)
147 if (!gpsi
) // Fixme! Hax! Need Timos delay load support?
149 return RealGetSystemMetrics(nIndex
);
154 Hook
= BeginIfHookedUserApiHook();
156 /* Bypass SEH and go direct. */
157 if (!Hook
) return RealGetSystemMetrics(nIndex
);
161 Ret
= guah
.GetSystemMetrics(nIndex
);
163 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
176 BOOL WINAPI
SetDeskWallpaper(LPCSTR filename
)
178 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
182 RealSystemParametersInfoA(UINT uiAction
,
190 case SPI_GETNONCLIENTMETRICS
:
192 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
193 NONCLIENTMETRICSW nclmw
;
194 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
196 SetLastError(ERROR_INVALID_PARAMETER
);
199 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
201 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
205 pnclma
->iBorderWidth
= nclmw
.iBorderWidth
;
206 pnclma
->iScrollWidth
= nclmw
.iScrollWidth
;
207 pnclma
->iScrollHeight
= nclmw
.iScrollHeight
;
208 pnclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
209 pnclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
210 pnclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
211 pnclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
212 pnclma
->iMenuWidth
= nclmw
.iMenuWidth
;
213 pnclma
->iMenuHeight
= nclmw
.iMenuHeight
;
214 LogFontW2A(&(pnclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
215 LogFontW2A(&(pnclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
216 LogFontW2A(&(pnclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
217 LogFontW2A(&(pnclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
218 LogFontW2A(&(pnclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
221 case SPI_SETNONCLIENTMETRICS
:
223 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
224 NONCLIENTMETRICSW nclmw
;
225 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
227 SetLastError(ERROR_INVALID_PARAMETER
);
230 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
231 nclmw
.iBorderWidth
= pnclma
->iBorderWidth
;
232 nclmw
.iScrollWidth
= pnclma
->iScrollWidth
;
233 nclmw
.iScrollHeight
= pnclma
->iScrollHeight
;
234 nclmw
.iCaptionWidth
= pnclma
->iCaptionWidth
;
235 nclmw
.iCaptionHeight
= pnclma
->iCaptionHeight
;
236 nclmw
.iSmCaptionWidth
= pnclma
->iSmCaptionWidth
;
237 nclmw
.iSmCaptionHeight
= pnclma
->iSmCaptionHeight
;
238 nclmw
.iMenuWidth
= pnclma
->iMenuWidth
;
239 nclmw
.iMenuHeight
= pnclma
->iMenuHeight
;
240 LogFontA2W(&(nclmw
.lfCaptionFont
), &(pnclma
->lfCaptionFont
));
241 LogFontA2W(&(nclmw
.lfSmCaptionFont
), &(pnclma
->lfSmCaptionFont
));
242 LogFontA2W(&(nclmw
.lfMenuFont
), &(pnclma
->lfMenuFont
));
243 LogFontA2W(&(nclmw
.lfStatusFont
), &(pnclma
->lfStatusFont
));
244 LogFontA2W(&(nclmw
.lfMessageFont
), &(pnclma
->lfMessageFont
));
246 return SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
249 case SPI_GETICONMETRICS
:
251 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
253 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
255 SetLastError(ERROR_INVALID_PARAMETER
);
258 icmw
.cbSize
= sizeof(ICONMETRICSW
);
259 if (!SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
263 picma
->iHorzSpacing
= icmw
.iHorzSpacing
;
264 picma
->iVertSpacing
= icmw
.iVertSpacing
;
265 picma
->iTitleWrap
= icmw
.iTitleWrap
;
266 LogFontW2A(&(picma
->lfFont
), &(icmw
.lfFont
));
269 case SPI_SETICONMETRICS
:
271 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
273 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
275 SetLastError(ERROR_INVALID_PARAMETER
);
278 icmw
.cbSize
= sizeof(ICONMETRICSW
);
279 icmw
.iHorzSpacing
= picma
->iHorzSpacing
;
280 icmw
.iVertSpacing
= picma
->iVertSpacing
;
281 icmw
.iTitleWrap
= picma
->iTitleWrap
;
282 LogFontA2W(&(icmw
.lfFont
), &(picma
->lfFont
));
284 return SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
287 case SPI_GETICONTITLELOGFONT
:
290 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
292 LogFontW2A(pvParam
, &lfw
);
295 case SPI_SETICONTITLELOGFONT
:
297 LPLOGFONTA plfa
= (LPLOGFONTA
)pvParam
;
299 LogFontA2W(&lfw
,plfa
);
300 return SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
);
302 case SPI_GETDESKWALLPAPER
:
306 UNICODE_STRING ustrWallpaper
;
307 ANSI_STRING astrWallpaper
;
309 Ret
= NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, MAX_PATH
, awc
, fWinIni
);
310 RtlInitUnicodeString(&ustrWallpaper
, awc
);
311 RtlUnicodeStringToAnsiString(&astrWallpaper
, &ustrWallpaper
, TRUE
);
313 RtlCopyMemory(pvParam
, astrWallpaper
.Buffer
, uiParam
);
314 RtlFreeAnsiString(&astrWallpaper
);
318 case SPI_SETDESKWALLPAPER
:
320 UNICODE_STRING ustrWallpaper
;
325 if (!RtlCreateUnicodeStringFromAsciiz(&ustrWallpaper
, pvParam
))
327 ERR("RtlCreateUnicodeStringFromAsciiz failed\n");
330 pvParam
= &ustrWallpaper
;
333 Ret
= NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, pvParam
, fWinIni
);
334 RtlFreeUnicodeString(&ustrWallpaper
);
338 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
342 RealSystemParametersInfoW(UINT uiAction
,
350 case SPI_SETDESKWALLPAPER
:
352 UNICODE_STRING ustrWallpaper
;
354 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
355 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
358 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
366 SystemParametersInfoA(UINT uiAction
,
371 BOOL Hook
, Ret
= FALSE
;
375 Hook
= BeginIfHookedUserApiHook();
377 /* Bypass SEH and go direct. */
378 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
382 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
384 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
398 SystemParametersInfoW(UINT uiAction
,
403 BOOL Hook
, Ret
= FALSE
;
407 Hook
= BeginIfHookedUserApiHook();
409 /* Bypass SEH and go direct. */
410 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
414 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
416 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
430 CreateDesktopA(LPCSTR lpszDesktop
,
434 ACCESS_MASK dwDesiredAccess
,
435 LPSECURITY_ATTRIBUTES lpsa
)
437 UNICODE_STRING DesktopNameU
;
439 LPDEVMODEW DevmodeW
= NULL
;
443 /* After conversion, the buffer is zero-terminated */
444 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
448 RtlInitUnicodeString(&DesktopNameU
, NULL
);
452 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
454 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
461 /* Free the string, if it was allocated */
462 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
472 CreateDesktopW(LPCWSTR lpszDesktop
,
476 ACCESS_MASK dwDesiredAccess
,
477 LPSECURITY_ATTRIBUTES lpsa
)
479 OBJECT_ATTRIBUTES oas
;
480 UNICODE_STRING DesktopName
, DesktopDevice
;
483 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
485 /* Retrive WinStation handle. */
486 hWinSta
= NtUserGetProcessWindowStation();
488 /* Initialize the strings. */
489 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
490 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
492 /* Check for process is inherited, set flag if set. */
493 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
495 /* Initialize the attributes for the desktop. */
496 InitializeObjectAttributes( &oas
,
500 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
502 /* Send the request and call to win32k. */
503 hDesktop
= NtUserCreateDesktop( &oas
,
519 HWINSTA WindowStation
,
520 DESKTOPENUMPROCA EnumFunc
,
523 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
533 HWINSTA WindowStation
,
534 DESKTOPENUMPROCW EnumFunc
,
537 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
549 return NtUserGetThreadDesktop(dwThreadId
, 0);
562 ACCESS_MASK dwDesiredAccess
)
564 UNICODE_STRING DesktopNameU
;
569 /* After conversion, the buffer is zero-terminated */
570 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
574 RtlInitUnicodeString(&DesktopNameU
, NULL
);
577 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
582 /* Free the string, if it was allocated */
583 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
598 ACCESS_MASK dwDesiredAccess
)
600 UNICODE_STRING DesktopName
;
601 OBJECT_ATTRIBUTES ObjectAttributes
;
603 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
605 InitializeObjectAttributes(&ObjectAttributes
,
607 OBJ_CASE_INSENSITIVE
,
608 GetProcessWindowStation(),
611 if( fInherit
== TRUE
)
613 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
616 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
624 SetShellWindow(HWND hwndShell
)
626 return SetShellWindowEx(hwndShell
, hwndShell
);
637 pdi
= GetThreadDesktopInfo();
638 if (pdi
) return pdi
->hShellWindow
;