4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
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.
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.
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
26 CComPtr
<ITrayWindow
> m_Tray
;
28 DWORD
DesktopThreadProc()
30 CComPtr
<IShellDesktopTray
> pSdt
;
36 hRet
= m_Tray
->QueryInterface(IID_PPV_ARG(IShellDesktopTray
, &pSdt
));
40 hDesktop
= _SHCreateDesktop(pSdt
);
44 if (!SetEvent(m_hEvent
))
46 /* Failed to notify that we initialized successfully, kill ourselves
47 to make the main thread wake up! */
51 _SHDesktopMessageLoop(hDesktop
);
53 /* FIXME: Properly rundown the main thread! */
59 static DWORD CALLBACK
s_DesktopThreadProc(IN OUT LPVOID lpParameter
)
61 return reinterpret_cast<CDesktopThread
*>(lpParameter
)->DesktopThreadProc();
71 HRESULT
Initialize(IN OUT ITrayWindow
*pTray
)
78 m_hEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
82 hThread
= CreateThread(NULL
, 0, s_DesktopThreadProc
, (PVOID
)this, 0, NULL
);
85 CloseHandle(m_hEvent
);
90 Handles
[1] = m_hEvent
;
94 DWORD WaitResult
= MsgWaitForMultipleObjects(_countof(Handles
), Handles
, FALSE
, INFINITE
, QS_ALLEVENTS
);
95 if (WaitResult
== WAIT_OBJECT_0
+ _countof(Handles
))
97 TrayProcessMessages(m_Tray
);
99 else if (WaitResult
!= WAIT_FAILED
&& WaitResult
!= WAIT_OBJECT_0
)
105 CloseHandle(hThread
);
106 CloseHandle(m_hEvent
);
118 DesktopCreateWindow(IN OUT ITrayWindow
*Tray
)
120 CDesktopThread
* pDesktopThread
= new CDesktopThread();
122 HRESULT hres
= pDesktopThread
->Initialize(Tray
);
123 if(FAILED_UNEXPECTEDLY(hres
))
125 delete pDesktopThread
;
129 return pDesktopThread
;
133 DesktopDestroyShellWindow(IN HANDLE hDesktop
)
135 CDesktopThread
* pDesktopThread
= reinterpret_cast<CDesktopThread
*>(hDesktop
);
136 pDesktopThread
->Destroy();