2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/user32/misc/desktop.c
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
13 #include <wine/debug.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
16 /*********************************************************************
17 * desktop class descriptor
19 #if 0 // Kept for referencing.
20 const struct builtin_class_descr DESKTOP_builtin_class
=
22 WC_DESKTOP
, /* name */
23 CS_DBLCLKS
, /* style */
24 NULL
, /* procA (winproc is Unicode only) */
25 DesktopWndProc
, /* procW */
27 IDC_ARROW
, /* cursor */
28 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
34 DesktopWndProcW(HWND Wnd
,
39 TRACE("Desktop W Class Atom! hWnd 0x%x, Msg %d\n", Wnd
, Msg
);
47 case WM_DISPLAYCHANGE
:
49 case WM_SYSCOLORCHANGE
:
52 NtUserMessageCall( Wnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DESKTOP
, FALSE
);
53 TRACE("Desktop lResult %d\n", lResult
);
57 case WM_PALETTECHANGED
:
58 if (Wnd
== (HWND
)wParam
) break;
59 case WM_QUERYNEWPALETTE
:
61 HDC hdc
= GetWindowDC( Wnd
);
63 ReleaseDC( Wnd
, hdc
);
68 return (LRESULT
)SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
71 return DefWindowProcW(Wnd
, Msg
, wParam
, lParam
);
78 LogFontA2W(LPLOGFONTW pW
, CONST LOGFONTA
*pA
)
80 #define COPYS(f,len) MultiByteToWideChar ( CP_THREAD_ACP, 0, pA->f, len, pW->f, len )
81 #define COPYN(f) pW->f = pA->f
92 COPYN(lfOutPrecision
);
93 COPYN(lfClipPrecision
);
95 COPYN(lfPitchAndFamily
);
96 COPYS(lfFaceName
,LF_FACESIZE
);
104 LogFontW2A(LPLOGFONTA pA
, CONST LOGFONTW
*pW
)
106 #define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
107 #define COPYN(f) pA->f = pW->f
112 COPYN(lfOrientation
);
118 COPYN(lfOutPrecision
);
119 COPYN(lfClipPrecision
);
121 COPYN(lfPitchAndFamily
);
122 COPYS(lfFaceName
,LF_FACESIZE
);
129 RealGetSystemMetrics(int nIndex
)
132 //FIXME("Global Server Data -> %x\n",gpsi);
133 if (nIndex
< 0 || nIndex
>= SM_CMETRICS
) return 0;
134 return gpsi
->aiSysMet
[nIndex
];
141 GetSystemMetrics(int nIndex
)
146 if (!gpsi
) // Fixme! Hax! Need Timos delay load support?
148 return RealGetSystemMetrics(nIndex
);
153 Hook
= BeginIfHookedUserApiHook();
155 /* Bypass SEH and go direct. */
156 if (!Hook
) return RealGetSystemMetrics(nIndex
);
160 Ret
= guah
.GetSystemMetrics(nIndex
);
162 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
175 BOOL WINAPI
SetDeskWallpaper(LPCSTR filename
)
177 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
181 RealSystemParametersInfoA(UINT uiAction
,
189 case SPI_GETNONCLIENTMETRICS
:
191 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
192 NONCLIENTMETRICSW nclmw
;
193 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
195 SetLastError(ERROR_INVALID_PARAMETER
);
198 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
200 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
204 pnclma
->iBorderWidth
= nclmw
.iBorderWidth
;
205 pnclma
->iScrollWidth
= nclmw
.iScrollWidth
;
206 pnclma
->iScrollHeight
= nclmw
.iScrollHeight
;
207 pnclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
208 pnclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
209 pnclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
210 pnclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
211 pnclma
->iMenuWidth
= nclmw
.iMenuWidth
;
212 pnclma
->iMenuHeight
= nclmw
.iMenuHeight
;
213 LogFontW2A(&(pnclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
214 LogFontW2A(&(pnclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
215 LogFontW2A(&(pnclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
216 LogFontW2A(&(pnclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
217 LogFontW2A(&(pnclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
220 case SPI_SETNONCLIENTMETRICS
:
222 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
223 NONCLIENTMETRICSW nclmw
;
224 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
226 SetLastError(ERROR_INVALID_PARAMETER
);
229 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
230 nclmw
.iBorderWidth
= pnclma
->iBorderWidth
;
231 nclmw
.iScrollWidth
= pnclma
->iScrollWidth
;
232 nclmw
.iScrollHeight
= pnclma
->iScrollHeight
;
233 nclmw
.iCaptionWidth
= pnclma
->iCaptionWidth
;
234 nclmw
.iCaptionHeight
= pnclma
->iCaptionHeight
;
235 nclmw
.iSmCaptionWidth
= pnclma
->iSmCaptionWidth
;
236 nclmw
.iSmCaptionHeight
= pnclma
->iSmCaptionHeight
;
237 nclmw
.iMenuWidth
= pnclma
->iMenuWidth
;
238 nclmw
.iMenuHeight
= pnclma
->iMenuHeight
;
239 LogFontA2W(&(nclmw
.lfCaptionFont
), &(pnclma
->lfCaptionFont
));
240 LogFontA2W(&(nclmw
.lfSmCaptionFont
), &(pnclma
->lfSmCaptionFont
));
241 LogFontA2W(&(nclmw
.lfMenuFont
), &(pnclma
->lfMenuFont
));
242 LogFontA2W(&(nclmw
.lfStatusFont
), &(pnclma
->lfStatusFont
));
243 LogFontA2W(&(nclmw
.lfMessageFont
), &(pnclma
->lfMessageFont
));
245 return SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
248 case SPI_GETICONMETRICS
:
250 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
252 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
254 SetLastError(ERROR_INVALID_PARAMETER
);
257 icmw
.cbSize
= sizeof(ICONMETRICSW
);
258 if (!SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
262 picma
->iHorzSpacing
= icmw
.iHorzSpacing
;
263 picma
->iVertSpacing
= icmw
.iVertSpacing
;
264 picma
->iTitleWrap
= icmw
.iTitleWrap
;
265 LogFontW2A(&(picma
->lfFont
), &(icmw
.lfFont
));
268 case SPI_SETICONMETRICS
:
270 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
272 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
274 SetLastError(ERROR_INVALID_PARAMETER
);
277 icmw
.cbSize
= sizeof(ICONMETRICSW
);
278 icmw
.iHorzSpacing
= picma
->iHorzSpacing
;
279 icmw
.iVertSpacing
= picma
->iVertSpacing
;
280 icmw
.iTitleWrap
= picma
->iTitleWrap
;
281 LogFontA2W(&(icmw
.lfFont
), &(picma
->lfFont
));
283 return SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
286 case SPI_GETICONTITLELOGFONT
:
289 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
291 LogFontW2A(pvParam
, &lfw
);
294 case SPI_SETICONTITLELOGFONT
:
296 LPLOGFONTA plfa
= (LPLOGFONTA
)pvParam
;
298 LogFontA2W(&lfw
,plfa
);
299 return SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
);
301 case SPI_GETDESKWALLPAPER
:
305 UNICODE_STRING ustrWallpaper
;
306 ANSI_STRING astrWallpaper
;
308 Ret
= NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, MAX_PATH
, awc
, fWinIni
);
309 RtlInitUnicodeString(&ustrWallpaper
, awc
);
310 RtlUnicodeStringToAnsiString(&astrWallpaper
, &ustrWallpaper
, TRUE
);
312 RtlCopyMemory(pvParam
, astrWallpaper
.Buffer
, uiParam
);
313 RtlFreeAnsiString(&astrWallpaper
);
317 case SPI_SETDESKWALLPAPER
:
319 UNICODE_STRING ustrWallpaper
;
324 if (!RtlCreateUnicodeStringFromAsciiz(&ustrWallpaper
, pvParam
))
326 ERR("RtlCreateUnicodeStringFromAsciiz failed\n");
329 pvParam
= &ustrWallpaper
;
332 Ret
= NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, pvParam
, fWinIni
);
335 RtlFreeUnicodeString(&ustrWallpaper
);
340 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
344 RealSystemParametersInfoW(UINT uiAction
,
352 case SPI_SETDESKWALLPAPER
:
354 UNICODE_STRING ustrWallpaper
;
356 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
357 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
360 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
368 SystemParametersInfoA(UINT uiAction
,
373 BOOL Hook
, Ret
= FALSE
;
377 Hook
= BeginIfHookedUserApiHook();
379 /* Bypass SEH and go direct. */
380 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
384 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
386 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
400 SystemParametersInfoW(UINT uiAction
,
405 BOOL Hook
, Ret
= FALSE
;
409 Hook
= BeginIfHookedUserApiHook();
411 /* Bypass SEH and go direct. */
412 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
416 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
418 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
432 CreateDesktopA(LPCSTR lpszDesktop
,
436 ACCESS_MASK dwDesiredAccess
,
437 LPSECURITY_ATTRIBUTES lpsa
)
439 UNICODE_STRING DesktopNameU
;
441 LPDEVMODEW DevmodeW
= NULL
;
445 /* After conversion, the buffer is zero-terminated */
446 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
450 RtlInitUnicodeString(&DesktopNameU
, NULL
);
454 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
456 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
463 /* Free the string, if it was allocated */
464 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
474 CreateDesktopW(LPCWSTR lpszDesktop
,
478 ACCESS_MASK dwDesiredAccess
,
479 LPSECURITY_ATTRIBUTES lpsa
)
481 OBJECT_ATTRIBUTES oas
;
482 UNICODE_STRING DesktopName
, DesktopDevice
;
485 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
487 /* Retrive WinStation handle. */
488 hWinSta
= NtUserGetProcessWindowStation();
490 /* Initialize the strings. */
491 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
492 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
494 /* Check for process is inherited, set flag if set. */
495 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
497 /* Initialize the attributes for the desktop. */
498 InitializeObjectAttributes( &oas
,
502 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
504 /* Send the request and call to win32k. */
505 hDesktop
= NtUserCreateDesktop( &oas
,
521 HWINSTA WindowStation
,
522 DESKTOPENUMPROCA EnumFunc
,
525 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
535 HWINSTA WindowStation
,
536 DESKTOPENUMPROCW EnumFunc
,
539 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
551 return NtUserGetThreadDesktop(dwThreadId
, 0);
564 ACCESS_MASK dwDesiredAccess
)
566 UNICODE_STRING DesktopNameU
;
571 /* After conversion, the buffer is zero-terminated */
572 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
576 RtlInitUnicodeString(&DesktopNameU
, NULL
);
579 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
584 /* Free the string, if it was allocated */
585 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
600 ACCESS_MASK dwDesiredAccess
)
602 UNICODE_STRING DesktopName
;
603 OBJECT_ATTRIBUTES ObjectAttributes
;
605 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
607 InitializeObjectAttributes(&ObjectAttributes
,
609 OBJ_CASE_INSENSITIVE
,
610 GetProcessWindowStation(),
613 if( fInherit
== TRUE
)
615 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
618 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
626 SetShellWindow(HWND hwndShell
)
628 return SetShellWindowEx(hwndShell
, hwndShell
);
639 pdi
= GetThreadDesktopInfo();
640 if (pdi
) return pdi
->hShellWindow
;