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 (WNDPROC
) 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
);
333 RtlFreeUnicodeString(&ustrWallpaper
);
337 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
341 RealSystemParametersInfoW(UINT uiAction
,
349 case SPI_SETDESKWALLPAPER
:
351 UNICODE_STRING ustrWallpaper
;
353 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
354 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
357 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
365 SystemParametersInfoA(UINT uiAction
,
370 BOOL Hook
, Ret
= FALSE
;
374 Hook
= BeginIfHookedUserApiHook();
376 /* Bypass SEH and go direct. */
377 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
381 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
383 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
397 SystemParametersInfoW(UINT uiAction
,
402 BOOL Hook
, Ret
= FALSE
;
406 Hook
= BeginIfHookedUserApiHook();
408 /* Bypass SEH and go direct. */
409 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
413 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
415 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
429 CreateDesktopA(LPCSTR lpszDesktop
,
433 ACCESS_MASK dwDesiredAccess
,
434 LPSECURITY_ATTRIBUTES lpsa
)
436 UNICODE_STRING DesktopNameU
;
438 LPDEVMODEW DevmodeW
= NULL
;
442 /* After conversion, the buffer is zero-terminated */
443 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
447 RtlInitUnicodeString(&DesktopNameU
, NULL
);
451 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
453 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
460 /* Free the string, if it was allocated */
461 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
471 CreateDesktopW(LPCWSTR lpszDesktop
,
475 ACCESS_MASK dwDesiredAccess
,
476 LPSECURITY_ATTRIBUTES lpsa
)
478 OBJECT_ATTRIBUTES oas
;
479 UNICODE_STRING DesktopName
, DesktopDevice
;
482 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
484 /* Retrive WinStation handle. */
485 hWinSta
= NtUserGetProcessWindowStation();
487 /* Initialize the strings. */
488 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
489 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
491 /* Check for process is inherited, set flag if set. */
492 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
494 /* Initialize the attributes for the desktop. */
495 InitializeObjectAttributes( &oas
,
499 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
501 /* Send the request and call to win32k. */
502 hDesktop
= NtUserCreateDesktop( &oas
,
518 HWINSTA WindowStation
,
519 DESKTOPENUMPROCA EnumFunc
,
522 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
532 HWINSTA WindowStation
,
533 DESKTOPENUMPROCW EnumFunc
,
536 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
548 return NtUserGetThreadDesktop(dwThreadId
, 0);
561 ACCESS_MASK dwDesiredAccess
)
563 UNICODE_STRING DesktopNameU
;
568 /* After conversion, the buffer is zero-terminated */
569 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
573 RtlInitUnicodeString(&DesktopNameU
, NULL
);
576 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
581 /* Free the string, if it was allocated */
582 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
597 ACCESS_MASK dwDesiredAccess
)
599 UNICODE_STRING DesktopName
;
600 OBJECT_ATTRIBUTES ObjectAttributes
;
602 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
604 InitializeObjectAttributes(&ObjectAttributes
,
606 OBJ_CASE_INSENSITIVE
,
607 GetProcessWindowStation(),
610 if( fInherit
== TRUE
)
612 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
615 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
623 SetShellWindow(HWND hwndShell
)
625 return SetShellWindowEx(hwndShell
, hwndShell
);
636 pdi
= GetThreadDesktopInfo();
637 if (pdi
) return pdi
->hShellWindow
;