2004-11-20 16:46:06 +00:00
|
|
|
/* $Id: desktopbg.c,v 1.11 2004/11/20 16:46:05 weiden Exp $
|
2003-12-07 23:02:57 +00:00
|
|
|
*
|
|
|
|
* reactos/subsys/csrss/win32csr/desktopbg.c
|
|
|
|
*
|
|
|
|
* Desktop background window functions
|
|
|
|
*
|
|
|
|
* ReactOS Operating System
|
|
|
|
*/
|
|
|
|
|
2004-04-09 20:03:21 +00:00
|
|
|
/*
|
|
|
|
* There is a problem with size of LPC_MESSAGE structure. In the old ReactOS
|
|
|
|
* headers it doesn't contain the data field and so it has a different size.
|
|
|
|
* We must use this workaround to get our Data field 0-sized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winnt.h>
|
|
|
|
#undef ANYSIZE_ARRAY
|
|
|
|
#define ANYSIZE_ARRAY 0
|
|
|
|
#include <ddk/ntapi.h>
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <csrss/csrss.h>
|
|
|
|
|
|
|
|
#include "api.h"
|
|
|
|
#include "desktopbg.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#define DESKTOP_WINDOW_ATOM 32880
|
|
|
|
|
|
|
|
#ifndef WM_APP
|
|
|
|
#define WM_APP 0x8000
|
|
|
|
#endif
|
|
|
|
#define PM_SHOW_DESKTOP (WM_APP + 1)
|
|
|
|
#define PM_HIDE_DESKTOP (WM_APP + 2)
|
|
|
|
|
|
|
|
typedef struct tagDTBG_THREAD_DATA
|
|
|
|
{
|
|
|
|
HDESK Desktop;
|
|
|
|
HANDLE Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
} DTBG_THREAD_DATA, *PDTBG_THREAD_DATA;
|
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
typedef struct tagPRIVATE_NOTIFY_DESKTOP
|
|
|
|
{
|
|
|
|
NMHDR hdr;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct /* PM_SHOW_DESKTOP */
|
|
|
|
{
|
|
|
|
int Width;
|
|
|
|
int Height;
|
|
|
|
} ShowDesktop;
|
|
|
|
};
|
|
|
|
} PRIVATE_NOTIFY_DESKTOP, *PPRIVATE_NOTIFY_DESKTOP;
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
static BOOL Initialized = FALSE;
|
2004-01-11 17:31:16 +00:00
|
|
|
static HWND VisibleDesktopWindow = NULL;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(Msg)
|
|
|
|
{
|
2004-05-08 19:35:32 +00:00
|
|
|
case WM_ERASEBKGND:
|
2004-08-17 14:57:52 +00:00
|
|
|
return 1;
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
case WM_PAINT:
|
2004-08-17 14:57:52 +00:00
|
|
|
{
|
|
|
|
PAINTSTRUCT PS;
|
|
|
|
RECT rc;
|
|
|
|
HDC hDC;
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
if(GetUpdateRect(Wnd, &rc, FALSE) &&
|
|
|
|
(hDC = BeginPaint(Wnd, &PS)))
|
2003-12-13 16:04:36 +00:00
|
|
|
{
|
2004-08-17 14:57:52 +00:00
|
|
|
PaintDesktop(hDC);
|
2003-12-13 16:04:36 +00:00
|
|
|
EndPaint(Wnd, &PS);
|
|
|
|
}
|
2004-08-17 14:57:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-08 19:35:32 +00:00
|
|
|
case WM_SETCURSOR:
|
2004-08-17 14:57:52 +00:00
|
|
|
return (LRESULT) SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
|
|
|
|
|
2004-05-08 19:35:32 +00:00
|
|
|
case WM_NCCREATE:
|
2004-08-17 14:57:52 +00:00
|
|
|
return (LRESULT) TRUE;
|
|
|
|
|
2004-05-08 19:35:32 +00:00
|
|
|
case WM_CREATE:
|
2004-08-17 14:57:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam;
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
/* Use WM_NOTIFY for private messages since it can't be sent between
|
|
|
|
processes! */
|
|
|
|
switch(nmh->hdr.code)
|
|
|
|
{
|
|
|
|
case PM_SHOW_DESKTOP:
|
|
|
|
{
|
|
|
|
LRESULT Result;
|
|
|
|
|
|
|
|
Result = ! SetWindowPos(Wnd,
|
|
|
|
NULL, 0, 0,
|
|
|
|
nmh->ShowDesktop.Width,
|
|
|
|
nmh->ShowDesktop.Height,
|
2004-09-24 15:07:38 +00:00
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
2004-08-17 14:57:52 +00:00
|
|
|
UpdateWindow(Wnd);
|
|
|
|
VisibleDesktopWindow = Wnd;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PM_HIDE_DESKTOP:
|
|
|
|
{
|
|
|
|
LRESULT Result;
|
|
|
|
|
|
|
|
Result = ! SetWindowPos(Wnd,
|
|
|
|
NULL, 0, 0, 0, 0,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE |
|
|
|
|
SWP_HIDEWINDOW);
|
|
|
|
UpdateWindow(Wnd);
|
|
|
|
VisibleDesktopWindow = NULL;
|
|
|
|
return Result;
|
|
|
|
}
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
default:
|
|
|
|
DPRINT("Unknown notification code 0x%x sent to the desktop window!\n", nmh->code);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-12-07 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
return 0;
|
2003-12-07 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL FASTCALL
|
|
|
|
DtbgInit()
|
|
|
|
{
|
|
|
|
WNDCLASSEXW Class;
|
|
|
|
ATOM ClassAtom;
|
|
|
|
|
2004-11-20 16:46:06 +00:00
|
|
|
/*
|
2003-12-07 23:02:57 +00:00
|
|
|
* Create the desktop window class
|
|
|
|
*/
|
|
|
|
Class.cbSize = sizeof(WNDCLASSEXW);
|
|
|
|
Class.style = 0;
|
|
|
|
Class.lpfnWndProc = DtbgWindowProc;
|
|
|
|
Class.cbClsExtra = 0;
|
|
|
|
Class.cbWndExtra = 0;
|
|
|
|
Class.hInstance = (HINSTANCE) GetModuleHandleW(NULL);
|
|
|
|
Class.hIcon = NULL;
|
|
|
|
Class.hCursor = NULL;
|
2003-12-22 15:30:21 +00:00
|
|
|
Class.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND);
|
2003-12-07 23:02:57 +00:00
|
|
|
Class.lpszMenuName = NULL;
|
|
|
|
Class.lpszClassName = (LPCWSTR) DESKTOP_WINDOW_ATOM;
|
|
|
|
ClassAtom = RegisterClassExW(&Class);
|
|
|
|
if ((ATOM) 0 == ClassAtom)
|
|
|
|
{
|
2004-01-11 17:31:16 +00:00
|
|
|
DPRINT1("Unable to register desktop background class (error %d)\n",
|
2003-12-07 23:02:57 +00:00
|
|
|
GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-01-11 17:31:16 +00:00
|
|
|
VisibleDesktopWindow = NULL;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD STDCALL
|
|
|
|
DtbgDesktopThread(PVOID Data)
|
|
|
|
{
|
|
|
|
HWND BackgroundWnd;
|
|
|
|
MSG msg;
|
|
|
|
PDTBG_THREAD_DATA ThreadData = (PDTBG_THREAD_DATA) Data;
|
|
|
|
|
|
|
|
if (! SetThreadDesktop(ThreadData->Desktop))
|
|
|
|
{
|
2004-01-11 17:31:16 +00:00
|
|
|
DPRINT1("Failed to set thread desktop\n");
|
2003-12-07 23:02:57 +00:00
|
|
|
ThreadData->Status = STATUS_UNSUCCESSFUL;
|
|
|
|
SetEvent(ThreadData->Event);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
BackgroundWnd = CreateWindowW((LPCWSTR) DESKTOP_WINDOW_ATOM,
|
|
|
|
L"",
|
2004-01-17 15:18:25 +00:00
|
|
|
WS_POPUP | WS_CLIPCHILDREN,
|
2003-12-07 23:02:57 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(HINSTANCE) GetModuleHandleW(NULL),
|
|
|
|
NULL);
|
|
|
|
if (NULL == BackgroundWnd)
|
|
|
|
{
|
2004-01-11 17:31:16 +00:00
|
|
|
DPRINT1("Failed to create desktop background window\n");
|
2003-12-07 23:02:57 +00:00
|
|
|
ThreadData->Status = STATUS_UNSUCCESSFUL;
|
|
|
|
SetEvent(ThreadData->Event);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadData->Status = STATUS_SUCCESS;
|
|
|
|
SetEvent(ThreadData->Event);
|
|
|
|
|
|
|
|
while (GetMessageW(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_API(CsrCreateDesktop)
|
|
|
|
{
|
|
|
|
DTBG_THREAD_DATA ThreadData;
|
|
|
|
HANDLE ThreadHandle;
|
|
|
|
|
|
|
|
DPRINT("CsrCreateDesktop\n");
|
|
|
|
|
|
|
|
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
|
2004-04-09 20:03:21 +00:00
|
|
|
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
|
|
|
if (! Initialized)
|
|
|
|
{
|
|
|
|
Initialized = TRUE;
|
|
|
|
if (! DtbgInit())
|
|
|
|
{
|
|
|
|
return Reply->Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-20 16:46:06 +00:00
|
|
|
/*
|
|
|
|
* the desktop handle we got from win32k is in the scope of CSRSS so we can just use it
|
|
|
|
*/
|
|
|
|
ThreadData.Desktop = Request->Data.CreateDesktopRequest.DesktopHandle;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
|
|
|
ThreadData.Event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
if (NULL == ThreadData.Event)
|
|
|
|
{
|
2004-01-11 17:31:16 +00:00
|
|
|
DPRINT1("Failed to create event (error %d)\n", GetLastError());
|
2003-12-07 23:02:57 +00:00
|
|
|
return Reply->Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
ThreadHandle = CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
DtbgDesktopThread,
|
|
|
|
(PVOID) &ThreadData,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (NULL == ThreadHandle)
|
|
|
|
{
|
|
|
|
CloseHandle(ThreadData.Event);
|
2004-01-11 17:31:16 +00:00
|
|
|
DPRINT1("Failed to create desktop window thread.\n");
|
2003-12-07 23:02:57 +00:00
|
|
|
return Reply->Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
CloseHandle(ThreadHandle);
|
|
|
|
|
|
|
|
WaitForSingleObject(ThreadData.Event, INFINITE);
|
|
|
|
CloseHandle(ThreadData.Event);
|
|
|
|
|
|
|
|
Reply->Status = ThreadData.Status;
|
|
|
|
|
|
|
|
return Reply->Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_API(CsrShowDesktop)
|
|
|
|
{
|
2004-08-17 14:57:52 +00:00
|
|
|
PRIVATE_NOTIFY_DESKTOP nmh;
|
2003-12-07 23:02:57 +00:00
|
|
|
DPRINT("CsrShowDesktop\n");
|
|
|
|
|
|
|
|
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
|
2004-04-09 20:03:21 +00:00
|
|
|
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
nmh.hdr.hwndFrom = Request->Data.ShowDesktopRequest.DesktopWindow;
|
|
|
|
nmh.hdr.idFrom = 0;
|
|
|
|
nmh.hdr.code = PM_SHOW_DESKTOP;
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
nmh.ShowDesktop.Width = (int)Request->Data.ShowDesktopRequest.Width;
|
|
|
|
nmh.ShowDesktop.Height = (int)Request->Data.ShowDesktopRequest.Height;
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
Reply->Status = SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
2004-08-17 14:57:52 +00:00
|
|
|
WM_NOTIFY,
|
|
|
|
(WPARAM)nmh.hdr.hwndFrom,
|
|
|
|
(LPARAM)&nmh)
|
2003-12-07 23:02:57 +00:00
|
|
|
? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
|
|
|
|
|
|
|
|
return Reply->Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_API(CsrHideDesktop)
|
|
|
|
{
|
2004-08-17 14:57:52 +00:00
|
|
|
PRIVATE_NOTIFY_DESKTOP nmh;
|
2003-12-07 23:02:57 +00:00
|
|
|
DPRINT("CsrHideDesktop\n");
|
|
|
|
|
|
|
|
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
|
2004-04-09 20:03:21 +00:00
|
|
|
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
|
2003-12-07 23:02:57 +00:00
|
|
|
|
2004-08-17 14:57:52 +00:00
|
|
|
nmh.hdr.hwndFrom = Request->Data.ShowDesktopRequest.DesktopWindow;
|
|
|
|
nmh.hdr.idFrom = 0;
|
|
|
|
nmh.hdr.code = PM_HIDE_DESKTOP;
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
Reply->Status = SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
2004-08-17 14:57:52 +00:00
|
|
|
WM_NOTIFY,
|
|
|
|
(WPARAM)nmh.hdr.hwndFrom,
|
|
|
|
(LPARAM)&nmh)
|
2003-12-07 23:02:57 +00:00
|
|
|
? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
|
|
|
|
|
|
|
|
return Reply->Status;
|
|
|
|
}
|
|
|
|
|
2004-01-11 17:31:16 +00:00
|
|
|
BOOL FASTCALL
|
|
|
|
DtbgIsDesktopVisible(VOID)
|
|
|
|
{
|
|
|
|
if (NULL != VisibleDesktopWindow && ! IsWindowVisible(VisibleDesktopWindow))
|
|
|
|
{
|
|
|
|
VisibleDesktopWindow = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL != VisibleDesktopWindow;
|
|
|
|
}
|
|
|
|
|
2003-12-07 23:02:57 +00:00
|
|
|
/* EOF */
|