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
)
131 //FIXME("Global Server Data -> %x\n",gpsi);
132 if (nIndex
< 0 || nIndex
>= SM_CMETRICS
) return 0;
133 return gpsi
->aiSysMet
[nIndex
];
140 GetSystemMetrics(int nIndex
)
145 if (!gpsi
) // Fixme! Hax! Need Timos delay load support?
147 return RealGetSystemMetrics(nIndex
);
152 Hook
= BeginIfHookedUserApiHook();
154 /* Bypass SEH and go direct. */
155 if (!Hook
) return RealGetSystemMetrics(nIndex
);
159 Ret
= guah
.GetSystemMetrics(nIndex
);
161 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
174 BOOL WINAPI
SetDeskWallpaper(LPCSTR filename
)
176 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
180 RealSystemParametersInfoA(UINT uiAction
,
188 case SPI_GETNONCLIENTMETRICS
:
190 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
191 NONCLIENTMETRICSW nclmw
;
192 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
194 SetLastError(ERROR_INVALID_PARAMETER
);
197 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
199 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
203 pnclma
->iBorderWidth
= nclmw
.iBorderWidth
;
204 pnclma
->iScrollWidth
= nclmw
.iScrollWidth
;
205 pnclma
->iScrollHeight
= nclmw
.iScrollHeight
;
206 pnclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
207 pnclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
208 pnclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
209 pnclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
210 pnclma
->iMenuWidth
= nclmw
.iMenuWidth
;
211 pnclma
->iMenuHeight
= nclmw
.iMenuHeight
;
212 LogFontW2A(&(pnclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
213 LogFontW2A(&(pnclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
214 LogFontW2A(&(pnclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
215 LogFontW2A(&(pnclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
216 LogFontW2A(&(pnclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
219 case SPI_SETNONCLIENTMETRICS
:
221 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
222 NONCLIENTMETRICSW nclmw
;
223 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
225 SetLastError(ERROR_INVALID_PARAMETER
);
228 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
229 nclmw
.iBorderWidth
= pnclma
->iBorderWidth
;
230 nclmw
.iScrollWidth
= pnclma
->iScrollWidth
;
231 nclmw
.iScrollHeight
= pnclma
->iScrollHeight
;
232 nclmw
.iCaptionWidth
= pnclma
->iCaptionWidth
;
233 nclmw
.iCaptionHeight
= pnclma
->iCaptionHeight
;
234 nclmw
.iSmCaptionWidth
= pnclma
->iSmCaptionWidth
;
235 nclmw
.iSmCaptionHeight
= pnclma
->iSmCaptionHeight
;
236 nclmw
.iMenuWidth
= pnclma
->iMenuWidth
;
237 nclmw
.iMenuHeight
= pnclma
->iMenuHeight
;
238 LogFontA2W(&(nclmw
.lfCaptionFont
), &(pnclma
->lfCaptionFont
));
239 LogFontA2W(&(nclmw
.lfSmCaptionFont
), &(pnclma
->lfSmCaptionFont
));
240 LogFontA2W(&(nclmw
.lfMenuFont
), &(pnclma
->lfMenuFont
));
241 LogFontA2W(&(nclmw
.lfStatusFont
), &(pnclma
->lfStatusFont
));
242 LogFontA2W(&(nclmw
.lfMessageFont
), &(pnclma
->lfMessageFont
));
244 return SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
247 case SPI_GETICONMETRICS
:
249 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
251 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
253 SetLastError(ERROR_INVALID_PARAMETER
);
256 icmw
.cbSize
= sizeof(ICONMETRICSW
);
257 if (!SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
261 picma
->iHorzSpacing
= icmw
.iHorzSpacing
;
262 picma
->iVertSpacing
= icmw
.iVertSpacing
;
263 picma
->iTitleWrap
= icmw
.iTitleWrap
;
264 LogFontW2A(&(picma
->lfFont
), &(icmw
.lfFont
));
267 case SPI_SETICONMETRICS
:
269 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
271 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
273 SetLastError(ERROR_INVALID_PARAMETER
);
276 icmw
.cbSize
= sizeof(ICONMETRICSW
);
277 icmw
.iHorzSpacing
= picma
->iHorzSpacing
;
278 icmw
.iVertSpacing
= picma
->iVertSpacing
;
279 icmw
.iTitleWrap
= picma
->iTitleWrap
;
280 LogFontA2W(&(icmw
.lfFont
), &(picma
->lfFont
));
282 return SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
285 case SPI_GETICONTITLELOGFONT
:
288 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
290 LogFontW2A(pvParam
, &lfw
);
293 case SPI_SETICONTITLELOGFONT
:
295 LPLOGFONTA plfa
= (LPLOGFONTA
)pvParam
;
297 LogFontA2W(&lfw
,plfa
);
298 return SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
);
300 case SPI_GETDESKWALLPAPER
:
304 UNICODE_STRING ustrWallpaper
;
305 ANSI_STRING astrWallpaper
;
307 Ret
= NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, MAX_PATH
, awc
, fWinIni
);
308 RtlInitUnicodeString(&ustrWallpaper
, awc
);
309 RtlUnicodeStringToAnsiString(&astrWallpaper
, &ustrWallpaper
, TRUE
);
311 RtlCopyMemory(pvParam
, astrWallpaper
.Buffer
, uiParam
);
312 RtlFreeAnsiString(&astrWallpaper
);
316 case SPI_SETDESKWALLPAPER
:
318 UNICODE_STRING ustrWallpaper
;
323 if (!RtlCreateUnicodeStringFromAsciiz(&ustrWallpaper
, pvParam
))
325 ERR("RtlCreateUnicodeStringFromAsciiz failed\n");
328 pvParam
= &ustrWallpaper
;
331 Ret
= NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, pvParam
, fWinIni
);
334 RtlFreeUnicodeString(&ustrWallpaper
);
339 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
343 RealSystemParametersInfoW(UINT uiAction
,
351 case SPI_SETDESKWALLPAPER
:
353 UNICODE_STRING ustrWallpaper
;
355 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
356 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
359 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
367 SystemParametersInfoA(UINT uiAction
,
372 BOOL Hook
, Ret
= FALSE
;
376 Hook
= BeginIfHookedUserApiHook();
378 /* Bypass SEH and go direct. */
379 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
383 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
385 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
399 SystemParametersInfoW(UINT uiAction
,
404 BOOL Hook
, Ret
= FALSE
;
408 Hook
= BeginIfHookedUserApiHook();
410 /* Bypass SEH and go direct. */
411 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
415 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
417 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
431 CreateDesktopA(LPCSTR lpszDesktop
,
435 ACCESS_MASK dwDesiredAccess
,
436 LPSECURITY_ATTRIBUTES lpsa
)
438 UNICODE_STRING DesktopNameU
;
440 LPDEVMODEW DevmodeW
= NULL
;
444 /* After conversion, the buffer is zero-terminated */
445 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
449 RtlInitUnicodeString(&DesktopNameU
, NULL
);
453 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
455 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
462 /* Free the string, if it was allocated */
463 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
473 CreateDesktopW(LPCWSTR lpszDesktop
,
477 ACCESS_MASK dwDesiredAccess
,
478 LPSECURITY_ATTRIBUTES lpsa
)
480 OBJECT_ATTRIBUTES oas
;
481 UNICODE_STRING DesktopName
, DesktopDevice
;
484 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
486 /* Retrive WinStation handle. */
487 hWinSta
= NtUserGetProcessWindowStation();
489 /* Initialize the strings. */
490 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
491 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
493 /* Check for process is inherited, set flag if set. */
494 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
496 /* Initialize the attributes for the desktop. */
497 InitializeObjectAttributes( &oas
,
501 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
503 /* Send the request and call to win32k. */
504 hDesktop
= NtUserCreateDesktop( &oas
,
520 HWINSTA WindowStation
,
521 DESKTOPENUMPROCA EnumFunc
,
524 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
534 HWINSTA WindowStation
,
535 DESKTOPENUMPROCW EnumFunc
,
538 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
550 USER_API_MESSAGE ApiMessage
;
551 PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest
= &ApiMessage
.Data
.GetThreadConsoleDesktopRequest
;
553 GetThreadConsoleDesktopRequest
->ThreadId
= dwThreadId
;
555 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
557 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX
, UserpGetThreadConsoleDesktop
),
558 sizeof(*GetThreadConsoleDesktopRequest
));
559 if (!NT_SUCCESS(ApiMessage
.Status
))
561 UserSetLastNTError(ApiMessage
.Status
);
565 return NtUserGetThreadDesktop(dwThreadId
,
566 (DWORD
)GetThreadConsoleDesktopRequest
->ConsoleDesktop
);
579 ACCESS_MASK dwDesiredAccess
)
581 UNICODE_STRING DesktopNameU
;
586 /* After conversion, the buffer is zero-terminated */
587 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
591 RtlInitUnicodeString(&DesktopNameU
, NULL
);
594 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
599 /* Free the string, if it was allocated */
600 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
615 ACCESS_MASK dwDesiredAccess
)
617 UNICODE_STRING DesktopName
;
618 OBJECT_ATTRIBUTES ObjectAttributes
;
620 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
622 InitializeObjectAttributes(&ObjectAttributes
,
624 OBJ_CASE_INSENSITIVE
,
625 GetProcessWindowStation(),
630 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
633 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
641 SetShellWindow(HWND hwndShell
)
643 return SetShellWindowEx(hwndShell
, hwndShell
);
654 pdi
= GetThreadDesktopInfo();
655 if (pdi
) return pdi
->hShellWindow
;