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
27 CComPtr
<ITrayWindow
> m_Tray
;
29 DWORD
DesktopThreadProc()
31 CComPtr
<IShellDesktopTray
> pSdt
;
37 hRet
= m_Tray
->QueryInterface(IID_PPV_ARG(IShellDesktopTray
, &pSdt
));
41 hDesktop
= _SHCreateDesktop(pSdt
);
45 if (!SetEvent(m_hEvent
))
47 /* Failed to notify that we initialized successfully, kill ourselves
48 to make the main thread wake up! */
52 _SHDesktopMessageLoop(hDesktop
);
54 /* FIXME: Properly rundown the main thread! */
60 static DWORD CALLBACK
s_DesktopThreadProc(IN OUT LPVOID lpParameter
)
62 return reinterpret_cast<CDesktopThread
*>(lpParameter
)->DesktopThreadProc();
73 HANDLE
Initialize(IN OUT ITrayWindow
*pTray
)
80 m_hEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
84 hThread
= CreateThread(NULL
, 0, s_DesktopThreadProc
, (PVOID
)this, 0, NULL
);
87 CloseHandle(m_hEvent
);
92 Handles
[1] = m_hEvent
;
96 DWORD WaitResult
= MsgWaitForMultipleObjects(_countof(Handles
), Handles
, FALSE
, INFINITE
, QS_ALLEVENTS
);
97 if (WaitResult
== WAIT_OBJECT_0
+ _countof(Handles
))
99 TrayProcessMessages(m_Tray
);
101 else if (WaitResult
!= WAIT_FAILED
&& WaitResult
!= WAIT_OBJECT_0
)
107 CloseHandle(hThread
);
108 CloseHandle(m_hEvent
);
110 // FIXME: Never assigned, will always return default value (NULL).
119 } * g_pDesktopWindowInstance
;
122 DesktopCreateWindow(IN OUT ITrayWindow
*Tray
)
124 if (!g_pDesktopWindowInstance
)
126 g_pDesktopWindowInstance
= new CDesktopThread();
129 if (!g_pDesktopWindowInstance
)
132 return g_pDesktopWindowInstance
->Initialize(Tray
);
136 DesktopDestroyShellWindow(IN HANDLE hDesktop
)
138 if (g_pDesktopWindowInstance
)
140 g_pDesktopWindowInstance
->Destroy();