ReactOS 0.4.15-dev-7788-g1ad9096
desktop.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Explorer
3 *
4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "precomp.h"
22
24{
25private:
30
32 static DWORD WINAPI s_DesktopThreadProc(LPVOID lpParameter);
33
34public:
37
38 HRESULT Initialize(ITrayWindow* pTray);
39 void Destroy();
40};
41
42/*******************************************************************/
43
45 m_Tray(NULL),
46 m_hInitEvent(NULL),
47 m_hThread(NULL),
48 m_ThreadId(0)
49{
50}
51
53{
54 Destroy();
55}
56
58{
59 HANDLE Handles[2];
60
61 if (!pTray || m_Tray)
62 {
63 return E_FAIL;
64 }
65
67 if (!m_hInitEvent)
68 {
69 return E_FAIL;
70 }
71
72 m_Tray = pTray;
74
75 if (!m_hThread)
76 {
79
80 m_Tray = NULL;
81
82 return E_FAIL;
83 }
84
85 Handles[0] = m_hThread;
86 Handles[1] = m_hInitEvent;
87
88 for (;;)
89 {
90 DWORD WaitResult = MsgWaitForMultipleObjects(_countof(Handles), Handles, FALSE, INFINITE, QS_ALLEVENTS);
91
92 if (WaitResult == WAIT_OBJECT_0 + _countof(Handles))
93 {
95 }
96 else if (WaitResult != WAIT_FAILED && WaitResult != WAIT_OBJECT_0)
97 {
98 break;
99 }
100 else
101 {
103 m_hThread = NULL;
104 m_ThreadId = 0;
105
108
109 m_Tray = NULL;
110
111 return E_FAIL;
112 }
113 }
114 return S_OK;
115}
116
118{
119 if (m_hThread)
120 {
121 DWORD WaitResult = WaitForSingleObject(m_hThread, 0);
122 if (WaitResult == WAIT_TIMEOUT)
123 {
124 /* Send WM_QUIT message to the thread and wait for it to terminate */
127 }
128
130 m_hThread = NULL;
131 m_ThreadId = 0;
132 }
133
134 if (m_hInitEvent)
135 {
138 }
139
140 m_Tray = NULL;
141}
142
144{
146 HANDLE hDesktop;
147 HRESULT hRet;
148 DWORD dwResult = 1;
149
151
152 hRet = m_Tray->QueryInterface(IID_PPV_ARG(IShellDesktopTray, &pSdt));
153 if (!SUCCEEDED(hRet))
154 {
155 goto Cleanup;
156 }
157
158 hDesktop = _SHCreateDesktop(pSdt);
159 if (!hDesktop)
160 {
161 goto Cleanup;
162 }
163
165 {
166 /* Failed to notify that we initialized successfully, kill ourselves
167 * to make the main thread wake up! */
168 goto Cleanup;
169 }
170
171 _SHDesktopMessageLoop(hDesktop);
172 dwResult = 0;
173
174Cleanup:
176 return dwResult;
177}
178
180{
181 CDesktopThread* pDesktopThread = static_cast<CDesktopThread*>(lpParameter);
182 return pDesktopThread->DesktopThreadProc();
183}
184
185/*******************************************************************/
186
187HANDLE
188DesktopCreateWindow(IN OUT ITrayWindow *Tray)
189{
190 CDesktopThread* pDesktopThread = new CDesktopThread();
191
192 HRESULT hres = pDesktopThread->Initialize(Tray);
194 {
195 delete pDesktopThread;
196 return NULL;
197 }
198
199 return pDesktopThread;
200}
201
202VOID
204{
205 CDesktopThread* pDesktopThread = reinterpret_cast<CDesktopThread*>(hDesktop);
206 delete pDesktopThread;
207}
VOID DesktopDestroyShellWindow(IN HANDLE hDesktop)
Definition: desktop.cpp:203
HANDLE DesktopCreateWindow(IN OUT ITrayWindow *Tray)
Definition: desktop.cpp:188
VOID TrayProcessMessages(IN OUT ITrayWindow *Tray)
BOOL WINAPI _SHDesktopMessageLoop(HANDLE hDesktop)
Definition: rshell.cpp:81
HANDLE WINAPI _SHCreateDesktop(IShellDesktopTray *ShellDesk)
Definition: rshell.cpp:52
DWORD DesktopThreadProc()
Definition: desktop.cpp:143
HRESULT Initialize(ITrayWindow *pTray)
Definition: desktop.cpp:57
void Destroy()
Definition: desktop.cpp:117
HANDLE m_hInitEvent
Definition: desktop.cpp:27
DWORD m_ThreadId
Definition: desktop.cpp:29
CComPtr< ITrayWindow > m_Tray
Definition: desktop.cpp:26
static DWORD WINAPI s_DesktopThreadProc(LPVOID lpParameter)
Definition: desktop.cpp:179
HANDLE m_hThread
Definition: desktop.cpp:28
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:169
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:230
static const WCHAR Cleanup[]
Definition: register.c:80
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT hres
Definition: protocol.c:465
#define _countof(array)
Definition: sndvol32.h:68
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WAIT_FAILED
Definition: winbase.h:413
#define WINAPI
Definition: msvc.h:6
#define WM_QUIT
Definition: winuser.h:1623
#define QS_ALLEVENTS
Definition: winuser.h:902
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
BOOL WINAPI PostThreadMessageW(_In_ DWORD, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static void Initialize()
Definition: xlate.c:212
#define IID_PPV_ARG(Itype, ppType)