ReactOS  0.4.13-dev-259-g5ca9c9c
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 {
27 
29  {
31  HANDLE hDesktop;
32  HRESULT hRet;
33 
35 
36  hRet = m_Tray->QueryInterface(IID_PPV_ARG(IShellDesktopTray, &pSdt));
37  if (!SUCCEEDED(hRet))
38  return 1;
39 
40  hDesktop = _SHCreateDesktop(pSdt);
41  if (hDesktop == NULL)
42  return 1;
43 
44  if (!SetEvent(m_hEvent))
45  {
46  /* Failed to notify that we initialized successfully, kill ourselves
47  to make the main thread wake up! */
48  return 1;
49  }
50 
51  _SHDesktopMessageLoop(hDesktop);
52 
53  /* FIXME: Properly rundown the main thread! */
54  ExitProcess(0);
55 
56  return 0;
57  }
58 
60  {
61  return reinterpret_cast<CDesktopThread*>(lpParameter)->DesktopThreadProc();
62  }
63 
64 public:
66  m_hEvent(NULL),
67  m_Tray(NULL)
68  {
69  }
70 
71  HRESULT Initialize(IN OUT ITrayWindow *pTray)
72  {
74  HANDLE Handles[2];
75 
76  m_Tray = pTray;
77 
79  if (!m_hEvent)
80  return E_FAIL;
81 
83  if (!hThread)
84  {
86  return E_FAIL;
87  }
88 
89  Handles[0] = hThread;
90  Handles[1] = m_hEvent;
91 
92  for (;;)
93  {
94  DWORD WaitResult = MsgWaitForMultipleObjects(_countof(Handles), Handles, FALSE, INFINITE, QS_ALLEVENTS);
95  if (WaitResult == WAIT_OBJECT_0 + _countof(Handles))
96  {
98  }
99  else if (WaitResult != WAIT_FAILED && WaitResult != WAIT_OBJECT_0)
100  {
101  break;
102  }
103  }
104 
107 
108  return S_OK;
109  }
110 
111  void Destroy()
112  {
113  return;
114  }
115 };
116 
117 HANDLE
118 DesktopCreateWindow(IN OUT ITrayWindow *Tray)
119 {
120  CDesktopThread* pDesktopThread = new CDesktopThread();
121 
122  HRESULT hres = pDesktopThread->Initialize(Tray);
124  {
125  delete pDesktopThread;
126  return NULL;
127  }
128 
129  return pDesktopThread;
130 }
131 
132 VOID
134 {
135  CDesktopThread* pDesktopThread = reinterpret_cast<CDesktopThread*>(hDesktop);
136  pDesktopThread->Destroy();
137 }
#define IN
Definition: typedefs.h:38
#define CloseHandle
Definition: compat.h:398
CComPtr< ITrayWindow > m_Tray
Definition: desktop.cpp:26
#define _countof(array)
Definition: fontsub.cpp:30
VOID TrayProcessMessages(IN OUT ITrayWindow *Tray)
#define CALLBACK
Definition: compat.h:27
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
static DWORD CALLBACK s_DesktopThreadProc(IN OUT LPVOID lpParameter)
Definition: desktop.cpp:59
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
VOID DesktopDestroyShellWindow(IN HANDLE hDesktop)
Definition: desktop.cpp:133
DWORD DesktopThreadProc()
Definition: desktop.cpp:28
BOOL WINAPI _SHDesktopMessageLoop(HANDLE hDesktop)
Definition: rshell.cpp:81
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:111
smooth NULL
Definition: ftsmooth.c:416
#define QS_ALLEVENTS
Definition: winuser.h:873
HANDLE m_hEvent
Definition: desktop.cpp:25
#define WAIT_OBJECT_0
Definition: winbase.h:387
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:394
HANDLE WINAPI _SHCreateDesktop(IShellDesktopTray *ShellDesk)
Definition: rshell.cpp:52
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
LPVOID lpParameter
Definition: kernel32.h:234
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:172
#define S_OK
Definition: intsafe.h:59
HANDLE DesktopCreateWindow(IN OUT ITrayWindow *Tray)
Definition: desktop.cpp:118
HANDLE hThread
Definition: wizard.c:27
#define OUT
Definition: typedefs.h:39
HRESULT Initialize(IN OUT ITrayWindow *pTray)
Definition: desktop.cpp:71
#define INFINITE
Definition: serial.h:102
#define SUCCEEDED(hr)
Definition: intsafe.h:57
void Destroy()
Definition: desktop.cpp:111