mirror of
https://github.com/reactos/reactos.git
synced 2025-06-23 09:20:18 +00:00
Cleanup in desktopbg.c, inspired by BeastL (slyhome|AT|ipnet|DOT|ua), bug #4985.
svn path=/trunk/; revision=44474
This commit is contained in:
parent
b1e100ebd8
commit
ae89fc3761
1 changed files with 223 additions and 203 deletions
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
|
|
||||||
#include "w32csr.h"
|
#include "w32csr.h"
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
@ -26,24 +27,25 @@ typedef struct tagDTBG_THREAD_DATA
|
||||||
typedef struct tagPRIVATE_NOTIFY_DESKTOP
|
typedef struct tagPRIVATE_NOTIFY_DESKTOP
|
||||||
{
|
{
|
||||||
NMHDR hdr;
|
NMHDR hdr;
|
||||||
union
|
|
||||||
{
|
|
||||||
struct /* PM_SHOW_DESKTOP */
|
struct /* PM_SHOW_DESKTOP */
|
||||||
{
|
{
|
||||||
int Width;
|
int Width;
|
||||||
int Height;
|
int Height;
|
||||||
} ShowDesktop;
|
} ShowDesktop;
|
||||||
};
|
|
||||||
} PRIVATE_NOTIFY_DESKTOP, *PPRIVATE_NOTIFY_DESKTOP;
|
} PRIVATE_NOTIFY_DESKTOP, *PPRIVATE_NOTIFY_DESKTOP;
|
||||||
|
|
||||||
static BOOL BgInitialized = FALSE;
|
static BOOL BgInitialized = FALSE;
|
||||||
static HWND VisibleDesktopWindow = NULL;
|
static HWND VisibleDesktopWindow = NULL;
|
||||||
|
|
||||||
static LRESULT CALLBACK
|
static
|
||||||
DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
LRESULT
|
||||||
|
CALLBACK
|
||||||
|
DtbgWindowProc(HWND Wnd,
|
||||||
|
UINT Msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
PAINTSTRUCT PS;
|
PAINTSTRUCT PS;
|
||||||
HDC hDC;
|
|
||||||
|
|
||||||
switch (Msg)
|
switch (Msg)
|
||||||
{
|
{
|
||||||
|
@ -52,11 +54,9 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
if (BeginPaint(Wnd, &PS))
|
||||||
if((hDC = BeginPaint(Wnd, &PS)))
|
|
||||||
EndPaint(Wnd, &PS);
|
EndPaint(Wnd, &PS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
case WM_SETCURSOR:
|
case WM_SETCURSOR:
|
||||||
return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
|
return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
|
||||||
|
@ -65,8 +65,6 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||||
return (LRESULT)TRUE;
|
return (LRESULT)TRUE;
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
return 0;
|
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -74,19 +72,21 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam;
|
PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam;
|
||||||
|
|
||||||
/* Use WM_NOTIFY for private messages since it can't be sent between
|
/* Use WM_NOTIFY for private messages since
|
||||||
processes! */
|
* it can't be sent between processes!
|
||||||
|
*/
|
||||||
switch (nmh->hdr.code)
|
switch (nmh->hdr.code)
|
||||||
{
|
{
|
||||||
case PM_SHOW_DESKTOP:
|
case PM_SHOW_DESKTOP:
|
||||||
{
|
{
|
||||||
LRESULT Result;
|
LRESULT Result;
|
||||||
|
|
||||||
Result = ! SetWindowPos(Wnd,
|
Result = !SetWindowPos(Wnd, NULL, 0, 0,
|
||||||
NULL, 0, 0,
|
|
||||||
nmh->ShowDesktop.Width,
|
nmh->ShowDesktop.Width,
|
||||||
nmh->ShowDesktop.Height,
|
nmh->ShowDesktop.Height,
|
||||||
SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
SWP_NOACTIVATE | SWP_NOZORDER |
|
||||||
|
SWP_SHOWWINDOW);
|
||||||
|
|
||||||
UpdateWindow(Wnd);
|
UpdateWindow(Wnd);
|
||||||
VisibleDesktopWindow = Wnd;
|
VisibleDesktopWindow = Wnd;
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -96,17 +96,18 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
LRESULT Result;
|
LRESULT Result;
|
||||||
|
|
||||||
Result = ! SetWindowPos(Wnd,
|
Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0,
|
||||||
NULL, 0, 0, 0, 0,
|
SWP_NOACTIVATE | SWP_NOZORDER |
|
||||||
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE |
|
SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
|
||||||
SWP_HIDEWINDOW);
|
|
||||||
UpdateWindow(Wnd);
|
UpdateWindow(Wnd);
|
||||||
VisibleDesktopWindow = NULL;
|
VisibleDesktopWindow = NULL;
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINT("Unknown notification code 0x%x sent to the desktop window!\n", nmh->hdr.code);
|
DPRINT("Unknown notification code 0x%x sent to the desktop window!\n",
|
||||||
|
nmh->hdr.code);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,8 +119,10 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL FASTCALL
|
static
|
||||||
DtbgInit()
|
BOOL
|
||||||
|
FASTCALL
|
||||||
|
DtbgInit(VOID)
|
||||||
{
|
{
|
||||||
WNDCLASSEXW Class;
|
WNDCLASSEXW Class;
|
||||||
ATOM ClassAtom;
|
ATOM ClassAtom;
|
||||||
|
@ -139,18 +142,23 @@ DtbgInit()
|
||||||
Class.lpszMenuName = NULL;
|
Class.lpszMenuName = NULL;
|
||||||
Class.lpszClassName = (LPCWSTR)DESKTOP_WINDOW_ATOM;
|
Class.lpszClassName = (LPCWSTR)DESKTOP_WINDOW_ATOM;
|
||||||
ClassAtom = RegisterClassExW(&Class);
|
ClassAtom = RegisterClassExW(&Class);
|
||||||
if ((ATOM) 0 == ClassAtom)
|
|
||||||
|
if (ClassAtom == INVALID_ATOM)
|
||||||
{
|
{
|
||||||
DPRINT1("Unable to register desktop background class (error %d)\n",
|
DPRINT1("Unable to register desktop background class (error %d)\n",
|
||||||
GetLastError());
|
GetLastError());
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VisibleDesktopWindow = NULL;
|
VisibleDesktopWindow = NULL;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD WINAPI
|
static
|
||||||
|
DWORD
|
||||||
|
WINAPI
|
||||||
DtbgDesktopThread(PVOID Data)
|
DtbgDesktopThread(PVOID Data)
|
||||||
{
|
{
|
||||||
HWND BackgroundWnd;
|
HWND BackgroundWnd;
|
||||||
|
@ -164,17 +172,15 @@ DtbgDesktopThread(PVOID Data)
|
||||||
SetEvent(ThreadData->Event);
|
SetEvent(ThreadData->Event);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackgroundWnd = CreateWindowW((LPCWSTR)DESKTOP_WINDOW_ATOM,
|
BackgroundWnd = CreateWindowW((LPCWSTR)DESKTOP_WINDOW_ATOM,
|
||||||
L"",
|
L"",
|
||||||
WS_POPUP | WS_CLIPCHILDREN,
|
WS_POPUP | WS_CLIPCHILDREN,
|
||||||
0,
|
0, 0, 0, 0,
|
||||||
0,
|
NULL, NULL,
|
||||||
0,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
(HINSTANCE)GetModuleHandleW(NULL),
|
(HINSTANCE)GetModuleHandleW(NULL),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (NULL == BackgroundWnd)
|
if (NULL == BackgroundWnd)
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create desktop background window\n");
|
DPRINT1("Failed to create desktop background window\n");
|
||||||
|
@ -208,35 +214,39 @@ CSR_API(CsrCreateDesktop)
|
||||||
if (!BgInitialized)
|
if (!BgInitialized)
|
||||||
{
|
{
|
||||||
BgInitialized = TRUE;
|
BgInitialized = TRUE;
|
||||||
|
|
||||||
if (!DtbgInit())
|
if (!DtbgInit())
|
||||||
{
|
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the desktop handle we got from win32k is in the scope of CSRSS so we can just use it
|
* 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;
|
ThreadData.Desktop = Request->Data.CreateDesktopRequest.DesktopHandle;
|
||||||
|
|
||||||
ThreadData.Event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
ThreadData.Event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
||||||
|
|
||||||
if (NULL == ThreadData.Event)
|
if (NULL == ThreadData.Event)
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create event (error %d)\n", GetLastError());
|
DPRINT1("Failed to create event (error %d)\n", GetLastError());
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadHandle = CreateThread(NULL,
|
ThreadHandle = CreateThread(NULL,
|
||||||
0,
|
0,
|
||||||
DtbgDesktopThread,
|
DtbgDesktopThread,
|
||||||
(PVOID)&ThreadData,
|
(PVOID)&ThreadData,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (NULL == ThreadHandle)
|
if (NULL == ThreadHandle)
|
||||||
{
|
{
|
||||||
CloseHandle(ThreadData.Event);
|
CloseHandle(ThreadData.Event);
|
||||||
DPRINT1("Failed to create desktop window thread.\n");
|
DPRINT1("Failed to create desktop window thread.\n");
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(ThreadHandle);
|
CloseHandle(ThreadHandle);
|
||||||
|
|
||||||
WaitForSingleObject(ThreadData.Event, INFINITE);
|
WaitForSingleObject(ThreadData.Event, INFINITE);
|
||||||
|
@ -260,11 +270,15 @@ CSR_API(CsrShowDesktop)
|
||||||
nmh.ShowDesktop.Width = (int)Request->Data.ShowDesktopRequest.Width;
|
nmh.ShowDesktop.Width = (int)Request->Data.ShowDesktopRequest.Width;
|
||||||
nmh.ShowDesktop.Height = (int)Request->Data.ShowDesktopRequest.Height;
|
nmh.ShowDesktop.Height = (int)Request->Data.ShowDesktopRequest.Height;
|
||||||
|
|
||||||
return SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
if (SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
||||||
WM_NOTIFY,
|
WM_NOTIFY,
|
||||||
(WPARAM)nmh.hdr.hwndFrom,
|
(WPARAM)nmh.hdr.hwndFrom,
|
||||||
(LPARAM)&nmh)
|
(LPARAM)&nmh))
|
||||||
? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
|
{
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSR_API(CsrHideDesktop)
|
CSR_API(CsrHideDesktop)
|
||||||
|
@ -279,22 +293,28 @@ CSR_API(CsrHideDesktop)
|
||||||
nmh.hdr.idFrom = 0;
|
nmh.hdr.idFrom = 0;
|
||||||
nmh.hdr.code = PM_HIDE_DESKTOP;
|
nmh.hdr.code = PM_HIDE_DESKTOP;
|
||||||
|
|
||||||
return SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
if (SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow,
|
||||||
WM_NOTIFY,
|
WM_NOTIFY,
|
||||||
(WPARAM)nmh.hdr.hwndFrom,
|
(WPARAM)nmh.hdr.hwndFrom,
|
||||||
(LPARAM)&nmh)
|
(LPARAM)&nmh))
|
||||||
? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
|
{
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL FASTCALL
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
FASTCALL
|
||||||
DtbgIsDesktopVisible(VOID)
|
DtbgIsDesktopVisible(VOID)
|
||||||
{
|
{
|
||||||
if (NULL != VisibleDesktopWindow && ! IsWindowVisible(VisibleDesktopWindow))
|
if (VisibleDesktopWindow != NULL &&
|
||||||
|
!IsWindowVisible(VisibleDesktopWindow))
|
||||||
{
|
{
|
||||||
VisibleDesktopWindow = NULL;
|
VisibleDesktopWindow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL != VisibleDesktopWindow;
|
return VisibleDesktopWindow != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue