2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: win32ss/user/user32/misc/desktop.c
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
13 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
15 /*********************************************************************
16 * desktop class descriptor
18 #if 0 // Kept for referencing.
19 const struct builtin_class_descr DESKTOP_builtin_class
=
21 WC_DESKTOP
, /* name */
22 CS_DBLCLKS
, /* style */
23 NULL
, /* procA (winproc is Unicode only) */
24 DesktopWndProc
, /* procW */
26 IDC_ARROW
, /* cursor */
27 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
33 DesktopWndProcW(HWND Wnd
,
38 TRACE("Desktop W Class Atom! hWnd 0x%x, Msg %d\n", Wnd
, Msg
);
46 case WM_DISPLAYCHANGE
:
48 case WM_SYSCOLORCHANGE
:
51 NtUserMessageCall( Wnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DESKTOP
, FALSE
);
52 TRACE("Desktop lResult %d\n", lResult
);
56 case WM_PALETTECHANGED
:
57 if (Wnd
== (HWND
)wParam
) break;
58 case WM_QUERYNEWPALETTE
:
60 HDC hdc
= GetWindowDC( Wnd
);
62 ReleaseDC( Wnd
, hdc
);
67 return (LRESULT
)SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
70 return DefWindowProcW(Wnd
, Msg
, wParam
, lParam
);
77 LogFontA2W(LPLOGFONTW pW
, CONST LOGFONTA
*pA
)
79 #define COPYS(f,len) MultiByteToWideChar ( CP_THREAD_ACP, 0, pA->f, len, pW->f, len )
80 #define COPYN(f) pW->f = pA->f
91 COPYN(lfOutPrecision
);
92 COPYN(lfClipPrecision
);
94 COPYN(lfPitchAndFamily
);
95 COPYS(lfFaceName
,LF_FACESIZE
);
103 LogFontW2A(LPLOGFONTA pA
, CONST LOGFONTW
*pW
)
105 #define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
106 #define COPYN(f) pA->f = pW->f
111 COPYN(lfOrientation
);
117 COPYN(lfOutPrecision
);
118 COPYN(lfClipPrecision
);
120 COPYN(lfPitchAndFamily
);
121 COPYS(lfFaceName
,LF_FACESIZE
);
128 RealGetSystemMetrics(int nIndex
)
130 //FIXME("Global Server Data -> %x\n",gpsi);
131 if (nIndex
< 0 || nIndex
>= SM_CMETRICS
) return 0;
132 return gpsi
->aiSysMet
[nIndex
];
139 GetSystemMetrics(int nIndex
)
144 if (!gpsi
) // Fixme! Hax! Need Timos delay load support?
146 return RealGetSystemMetrics(nIndex
);
151 Hook
= BeginIfHookedUserApiHook();
153 /* Bypass SEH and go direct. */
154 if (!Hook
) return RealGetSystemMetrics(nIndex
);
158 Ret
= guah
.GetSystemMetrics(nIndex
);
160 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
173 BOOL WINAPI
SetDeskWallpaper(LPCSTR filename
)
175 return SystemParametersInfoA(SPI_SETDESKWALLPAPER
,0,(PVOID
)filename
,TRUE
);
179 RealSystemParametersInfoA(UINT uiAction
,
187 case SPI_GETNONCLIENTMETRICS
:
189 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
190 NONCLIENTMETRICSW nclmw
;
191 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
193 SetLastError(ERROR_INVALID_PARAMETER
);
196 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
198 if (!SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
202 pnclma
->iBorderWidth
= nclmw
.iBorderWidth
;
203 pnclma
->iScrollWidth
= nclmw
.iScrollWidth
;
204 pnclma
->iScrollHeight
= nclmw
.iScrollHeight
;
205 pnclma
->iCaptionWidth
= nclmw
.iCaptionWidth
;
206 pnclma
->iCaptionHeight
= nclmw
.iCaptionHeight
;
207 pnclma
->iSmCaptionWidth
= nclmw
.iSmCaptionWidth
;
208 pnclma
->iSmCaptionHeight
= nclmw
.iSmCaptionHeight
;
209 pnclma
->iMenuWidth
= nclmw
.iMenuWidth
;
210 pnclma
->iMenuHeight
= nclmw
.iMenuHeight
;
211 LogFontW2A(&(pnclma
->lfCaptionFont
), &(nclmw
.lfCaptionFont
));
212 LogFontW2A(&(pnclma
->lfSmCaptionFont
), &(nclmw
.lfSmCaptionFont
));
213 LogFontW2A(&(pnclma
->lfMenuFont
), &(nclmw
.lfMenuFont
));
214 LogFontW2A(&(pnclma
->lfStatusFont
), &(nclmw
.lfStatusFont
));
215 LogFontW2A(&(pnclma
->lfMessageFont
), &(nclmw
.lfMessageFont
));
218 case SPI_SETNONCLIENTMETRICS
:
220 LPNONCLIENTMETRICSA pnclma
= (LPNONCLIENTMETRICSA
)pvParam
;
221 NONCLIENTMETRICSW nclmw
;
222 if(pnclma
->cbSize
!= sizeof(NONCLIENTMETRICSA
))
224 SetLastError(ERROR_INVALID_PARAMETER
);
227 nclmw
.cbSize
= sizeof(NONCLIENTMETRICSW
);
228 nclmw
.iBorderWidth
= pnclma
->iBorderWidth
;
229 nclmw
.iScrollWidth
= pnclma
->iScrollWidth
;
230 nclmw
.iScrollHeight
= pnclma
->iScrollHeight
;
231 nclmw
.iCaptionWidth
= pnclma
->iCaptionWidth
;
232 nclmw
.iCaptionHeight
= pnclma
->iCaptionHeight
;
233 nclmw
.iSmCaptionWidth
= pnclma
->iSmCaptionWidth
;
234 nclmw
.iSmCaptionHeight
= pnclma
->iSmCaptionHeight
;
235 nclmw
.iMenuWidth
= pnclma
->iMenuWidth
;
236 nclmw
.iMenuHeight
= pnclma
->iMenuHeight
;
237 LogFontA2W(&(nclmw
.lfCaptionFont
), &(pnclma
->lfCaptionFont
));
238 LogFontA2W(&(nclmw
.lfSmCaptionFont
), &(pnclma
->lfSmCaptionFont
));
239 LogFontA2W(&(nclmw
.lfMenuFont
), &(pnclma
->lfMenuFont
));
240 LogFontA2W(&(nclmw
.lfStatusFont
), &(pnclma
->lfStatusFont
));
241 LogFontA2W(&(nclmw
.lfMessageFont
), &(pnclma
->lfMessageFont
));
243 return SystemParametersInfoW(uiAction
, sizeof(NONCLIENTMETRICSW
),
246 case SPI_GETICONMETRICS
:
248 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
250 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
252 SetLastError(ERROR_INVALID_PARAMETER
);
255 icmw
.cbSize
= sizeof(ICONMETRICSW
);
256 if (!SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
260 picma
->iHorzSpacing
= icmw
.iHorzSpacing
;
261 picma
->iVertSpacing
= icmw
.iVertSpacing
;
262 picma
->iTitleWrap
= icmw
.iTitleWrap
;
263 LogFontW2A(&(picma
->lfFont
), &(icmw
.lfFont
));
266 case SPI_SETICONMETRICS
:
268 LPICONMETRICSA picma
= (LPICONMETRICSA
)pvParam
;
270 if(picma
->cbSize
!= sizeof(ICONMETRICSA
))
272 SetLastError(ERROR_INVALID_PARAMETER
);
275 icmw
.cbSize
= sizeof(ICONMETRICSW
);
276 icmw
.iHorzSpacing
= picma
->iHorzSpacing
;
277 icmw
.iVertSpacing
= picma
->iVertSpacing
;
278 icmw
.iTitleWrap
= picma
->iTitleWrap
;
279 LogFontA2W(&(icmw
.lfFont
), &(picma
->lfFont
));
281 return SystemParametersInfoW(uiAction
, sizeof(ICONMETRICSW
),
284 case SPI_GETICONTITLELOGFONT
:
287 if (!SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
))
289 LogFontW2A(pvParam
, &lfw
);
292 case SPI_SETICONTITLELOGFONT
:
294 LPLOGFONTA plfa
= (LPLOGFONTA
)pvParam
;
296 LogFontA2W(&lfw
,plfa
);
297 return SystemParametersInfoW(uiAction
, 0, &lfw
, fWinIni
);
299 case SPI_GETDESKWALLPAPER
:
303 UNICODE_STRING ustrWallpaper
;
304 ANSI_STRING astrWallpaper
;
306 Ret
= NtUserSystemParametersInfo(SPI_GETDESKWALLPAPER
, MAX_PATH
, awc
, fWinIni
);
307 RtlInitUnicodeString(&ustrWallpaper
, awc
);
308 RtlInitEmptyAnsiString(&astrWallpaper
, pvParam
, uiParam
);
309 RtlUnicodeStringToAnsiString(&astrWallpaper
, &ustrWallpaper
, FALSE
);
313 case SPI_SETDESKWALLPAPER
:
315 UNICODE_STRING ustrWallpaper
;
320 if (!RtlCreateUnicodeStringFromAsciiz(&ustrWallpaper
, pvParam
))
322 ERR("RtlCreateUnicodeStringFromAsciiz failed\n");
325 pvParam
= &ustrWallpaper
;
328 Ret
= NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, pvParam
, fWinIni
);
331 RtlFreeUnicodeString(&ustrWallpaper
);
336 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
340 RealSystemParametersInfoW(UINT uiAction
,
348 case SPI_SETDESKWALLPAPER
:
350 UNICODE_STRING ustrWallpaper
;
352 RtlInitUnicodeString(&ustrWallpaper
, pvParam
);
353 return NtUserSystemParametersInfo(SPI_SETDESKWALLPAPER
, uiParam
, &ustrWallpaper
, fWinIni
);
356 return NtUserSystemParametersInfo(uiAction
, uiParam
, pvParam
, fWinIni
);
364 SystemParametersInfoA(UINT uiAction
,
369 BOOL Hook
, Ret
= FALSE
;
373 Hook
= BeginIfHookedUserApiHook();
375 /* Bypass SEH and go direct. */
376 if (!Hook
) return RealSystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
380 Ret
= guah
.SystemParametersInfoA(uiAction
, uiParam
, pvParam
, fWinIni
);
382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
396 SystemParametersInfoW(UINT uiAction
,
401 BOOL Hook
, Ret
= FALSE
;
405 Hook
= BeginIfHookedUserApiHook();
407 /* Bypass SEH and go direct. */
408 if (!Hook
) return RealSystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
412 Ret
= guah
.SystemParametersInfoW(uiAction
, uiParam
, pvParam
, fWinIni
);
414 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
428 CreateDesktopA(LPCSTR lpszDesktop
,
432 ACCESS_MASK dwDesiredAccess
,
433 LPSECURITY_ATTRIBUTES lpsa
)
435 UNICODE_STRING DesktopNameU
;
437 LPDEVMODEW DevmodeW
= NULL
;
441 /* After conversion, the buffer is zero-terminated */
442 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
446 RtlInitUnicodeString(&DesktopNameU
, NULL
);
450 DevmodeW
= GdiConvertToDevmodeW(pDevmode
);
452 hDesktop
= CreateDesktopW(DesktopNameU
.Buffer
,
459 /* Free the string, if it was allocated */
460 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
470 CreateDesktopW(LPCWSTR lpszDesktop
,
474 ACCESS_MASK dwDesiredAccess
,
475 LPSECURITY_ATTRIBUTES lpsa
)
477 OBJECT_ATTRIBUTES oas
;
478 UNICODE_STRING DesktopName
, DesktopDevice
;
481 ULONG Attributes
= (OBJ_OPENIF
|OBJ_CASE_INSENSITIVE
);
483 /* Retrive WinStation handle. */
484 hWinSta
= NtUserGetProcessWindowStation();
486 /* Initialize the strings. */
487 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
488 RtlInitUnicodeString(&DesktopDevice
, lpszDevice
);
490 /* Check for process is inherited, set flag if set. */
491 if (lpsa
&& lpsa
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
493 /* Initialize the attributes for the desktop. */
494 InitializeObjectAttributes( &oas
,
498 lpsa
? lpsa
->lpSecurityDescriptor
: NULL
);
500 /* Send the request and call to win32k. */
501 hDesktop
= NtUserCreateDesktop( &oas
,
517 HWINSTA WindowStation
,
518 DESKTOPENUMPROCA EnumFunc
,
521 return EnumNamesA(WindowStation
, EnumFunc
, Context
, TRUE
);
531 HWINSTA WindowStation
,
532 DESKTOPENUMPROCW EnumFunc
,
535 return EnumNamesW(WindowStation
, EnumFunc
, Context
, TRUE
);
547 USER_API_MESSAGE ApiMessage
;
548 PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest
= &ApiMessage
.Data
.GetThreadConsoleDesktopRequest
;
550 GetThreadConsoleDesktopRequest
->ThreadId
= dwThreadId
;
552 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
554 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX
, UserpGetThreadConsoleDesktop
),
555 sizeof(*GetThreadConsoleDesktopRequest
));
556 if (!NT_SUCCESS(ApiMessage
.Status
))
558 UserSetLastNTError(ApiMessage
.Status
);
562 return NtUserGetThreadDesktop(dwThreadId
,
563 (DWORD
)GetThreadConsoleDesktopRequest
->ConsoleDesktop
);
576 ACCESS_MASK dwDesiredAccess
)
578 UNICODE_STRING DesktopNameU
;
583 /* After conversion, the buffer is zero-terminated */
584 RtlCreateUnicodeStringFromAsciiz(&DesktopNameU
, lpszDesktop
);
588 RtlInitUnicodeString(&DesktopNameU
, NULL
);
591 hDesktop
= OpenDesktopW(DesktopNameU
.Buffer
,
596 /* Free the string, if it was allocated */
597 if (lpszDesktop
) RtlFreeUnicodeString(&DesktopNameU
);
612 ACCESS_MASK dwDesiredAccess
)
614 UNICODE_STRING DesktopName
;
615 OBJECT_ATTRIBUTES ObjectAttributes
;
617 RtlInitUnicodeString(&DesktopName
, lpszDesktop
);
619 InitializeObjectAttributes(&ObjectAttributes
,
621 OBJ_CASE_INSENSITIVE
,
622 GetProcessWindowStation(),
627 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
630 return NtUserOpenDesktop(&ObjectAttributes
, dwFlags
, dwDesiredAccess
);
638 SetShellWindow(HWND hwndShell
)
640 return SetShellWindowEx(hwndShell
, hwndShell
);
651 pdi
= GetThreadDesktopInfo();
652 if (pdi
) return pdi
->hShellWindow
;