[RSHELL]
[reactos.git] / base / shell / explorer-new / desktop.c
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
23 typedef struct _DESKCREATEINFO
24 {
25 HANDLE hEvent;
26 ITrayWindow *Tray;
27 HANDLE hDesktop;
28 } DESKCREATEINFO, *PDESKCREATEINFO;
29
30 static DWORD CALLBACK
31 DesktopThreadProc(IN OUT LPVOID lpParameter)
32 {
33 volatile DESKCREATEINFO *DeskCreateInfo = (volatile DESKCREATEINFO *)lpParameter;
34 IShellDesktopTray *pSdt;
35 HANDLE hDesktop;
36 HRESULT hRet;
37
38 OleInitialize(NULL);
39
40 hRet = ITrayWindow_QueryInterface(DeskCreateInfo->Tray,
41 &IID_IShellDesktopTray,
42 (PVOID*)&pSdt);
43 if (!SUCCEEDED(hRet))
44 return 1;
45
46 hDesktop = SHCreateDesktop(pSdt);
47
48 IShellDesktopTray_Release(pSdt);
49 if (hDesktop == NULL)
50 return 1;
51
52 (void)InterlockedExchangePointer(&DeskCreateInfo->hDesktop,
53 hDesktop);
54
55 if (!SetEvent(DeskCreateInfo->hEvent))
56 {
57 /* Failed to notify that we initialized successfully, kill ourselves
58 to make the main thread wake up! */
59 return 1;
60 }
61
62 SHDesktopMessageLoop(hDesktop);
63
64 /* FIXME: Properly rundown the main thread! */
65 ExitProcess(0);
66
67 return 0;
68 }
69
70 HANDLE
71 DesktopCreateWindow(IN OUT ITrayWindow *Tray)
72 {
73 HANDLE hThread;
74 HANDLE hEvent;
75 DWORD DesktopThreadId;
76 HANDLE hDesktop = NULL;
77 HANDLE Handles[2];
78 DWORD WaitResult;
79
80 hEvent = CreateEvent(NULL,
81 FALSE,
82 FALSE,
83 NULL);
84 if (hEvent != NULL)
85 {
86 volatile DESKCREATEINFO DeskCreateInfo;
87
88 DeskCreateInfo.hEvent = hEvent;
89 DeskCreateInfo.Tray = Tray;
90 DeskCreateInfo.hDesktop = NULL;
91
92 hThread = CreateThread(NULL,
93 0,
94 DesktopThreadProc,
95 (PVOID)&DeskCreateInfo,
96 0,
97 &DesktopThreadId);
98 if (hThread != NULL)
99 {
100 Handles[0] = hThread;
101 Handles[1] = hEvent;
102
103 for (;;)
104 {
105 WaitResult = MsgWaitForMultipleObjects(sizeof(Handles) / sizeof(Handles[0]),
106 Handles,
107 FALSE,
108 INFINITE,
109 QS_ALLEVENTS);
110 if (WaitResult == WAIT_OBJECT_0 + (sizeof(Handles) / sizeof(Handles[0])))
111 TrayProcessMessages(Tray);
112 else if (WaitResult != WAIT_FAILED && WaitResult != WAIT_OBJECT_0)
113 {
114 hDesktop = DeskCreateInfo.hDesktop;
115 break;
116 }
117 }
118
119 CloseHandle(hThread);
120 }
121
122 CloseHandle(hEvent);
123 }
124
125 return hDesktop;
126 }
127
128 VOID
129 DesktopDestroyShellWindow(IN HANDLE hDesktop)
130 {
131 return;
132 }