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
23 HINSTANCE hExplorerInstance
;
26 HKEY hkExplorer
= NULL
;
27 DRAWCAPTEMP DrawCapTemp
= NULL
;
30 DEFINE_GUID(CLSID_RebarBandSite
, 0xECD4FC4D, 0x521C, 0x11D0, 0xB7, 0x92, 0x00, 0xA0, 0xC9, 0x03, 0x12, 0xE1);
33 SetWindowStyle(IN HWND hWnd
,
37 LONG PrevStyle
, Style
;
39 ASSERT((~dwStyleMask
& dwStyle
) == 0);
41 PrevStyle
= GetWindowLongPtr(hWnd
,
44 (PrevStyle
& dwStyleMask
) != dwStyle
)
46 Style
= PrevStyle
& ~dwStyleMask
;
49 PrevStyle
= SetWindowLongPtr(hWnd
,
58 SetWindowExStyle(IN HWND hWnd
,
62 LONG PrevStyle
, Style
;
64 ASSERT((~dwStyleMask
& dwStyle
) == 0);
66 PrevStyle
= GetWindowLongPtr(hWnd
,
69 (PrevStyle
& dwStyleMask
) != dwStyle
)
71 Style
= PrevStyle
& ~dwStyleMask
;
74 PrevStyle
= SetWindowLongPtr(hWnd
,
83 LoadPopupMenu(IN HINSTANCE hInstance
,
84 IN LPCTSTR lpMenuName
)
86 HMENU hMenu
, hSubMenu
= NULL
;
88 hMenu
= LoadMenu(hInstance
,
93 hSubMenu
= GetSubMenu(hMenu
,
95 if (hSubMenu
!= NULL
&&
110 FindSubMenu(IN HMENU hMenu
,
116 mii
.cbSize
= sizeof(mii
);
117 mii
.fMask
= MIIM_SUBMENU
;
119 if (GetMenuItemInfo(hMenu
,
131 GetCurrentLoggedOnUserName(OUT LPTSTR szBuffer
,
132 IN DWORD dwBufferSize
)
137 /* Query the user name from the registry */
138 dwSize
= (dwBufferSize
* sizeof(TCHAR
)) - 1;
139 if (RegQueryValueEx(hkExplorer
,
140 TEXT("Logon User Name"),
144 &dwSize
) == ERROR_SUCCESS
&&
145 (dwSize
/ sizeof(TCHAR
)) > 1 &&
146 szBuffer
[0] != _T('\0'))
148 szBuffer
[dwSize
/ sizeof(TCHAR
)] = _T('\0');
152 /* Fall back to GetUserName() */
153 dwSize
= dwBufferSize
;
154 if (!GetUserName(szBuffer
,
157 szBuffer
[0] = _T('\0');
165 FormatMenuString(IN HMENU hMenu
,
175 /* Find the menu item and read the formatting string */
176 mii
.cbSize
= sizeof(mii
);
177 mii
.fMask
= MIIM_STRING
;
178 mii
.dwTypeData
= (LPTSTR
)szBufFmt
;
179 mii
.cch
= sizeof(szBufFmt
) / sizeof(szBufFmt
[0]);
180 if (GetMenuItemInfo(hMenu
,
185 /* Format the string */
186 va_start(vl
, uFlags
);
188 (sizeof(szBuf
) / sizeof(szBuf
[0])) - 1,
192 szBuf
[(sizeof(szBuf
) / sizeof(szBuf
[0])) - 1] = _T('\0');
194 /* Update the menu item */
195 mii
.dwTypeData
= (LPTSTR
)szBuf
;
196 if (SetMenuItemInfo(hMenu
,
209 GetExplorerRegValueSet(IN HKEY hKey
,
213 TCHAR szBuffer
[MAX_PATH
];
215 DWORD dwType
, dwSize
;
219 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"));
225 dwSize
= sizeof(szBuffer
);
226 if (RegOpenKeyEx(hKey
,
230 &hkSubKey
) == ERROR_SUCCESS
)
235 if (RegQueryValueEx(hkSubKey
,
240 &dwSize
) == ERROR_SUCCESS
)
242 if (dwType
== REG_DWORD
&& dwSize
== sizeof(DWORD
))
243 Ret
= *((PDWORD
)szBuffer
) != 0;
245 Ret
= *((PUCHAR
)szBuffer
) != 0;
248 RegCloseKey(hkSubKey
);
255 SetShellReadyEvent(IN LPCTSTR lpEventName
)
259 hEvent
= OpenEvent(EVENT_MODIFY_STATE
,
274 _tWinMain(IN HINSTANCE hInstance
,
275 IN HINSTANCE hPrevInstance
,
279 ITrayWindow
*Tray
= NULL
;
280 HANDLE hShellDesktop
= NULL
;
281 BOOL CreateShellDesktop
= FALSE
;
283 if (RegOpenKey(HKEY_CURRENT_USER
,
284 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"),
285 &hkExplorer
) != ERROR_SUCCESS
)
288 LoadString(hInstance
, IDS_STARTUP_ERROR
, Message
, 256);
289 MessageBox(NULL
, Message
, NULL
, MB_ICONERROR
);
293 hExplorerInstance
= hInstance
;
294 hProcessHeap
= GetProcessHeap();
296 hUser32
= GetModuleHandle(TEXT("USER32.DLL"));
299 DrawCapTemp
= (DRAWCAPTEMP
)GetProcAddress(hUser32
,
300 PROC_NAME_DRAWCAPTIONTEMP
);
303 InitCommonControls();
306 if (GetShellWindow() == NULL
)
307 CreateShellDesktop
= TRUE
;
309 /* FIXME - initialize SSO Thread */
311 if (CreateShellDesktop
)
313 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass())
315 Tray
= CreateTrayWindow();
318 hShellDesktop
= DesktopCreateWindow(Tray
);
321 /* WinXP: Notify msgina to hide the welcome screen */
322 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
323 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
327 /* A shell is already loaded. Parse the command line arguments
328 and unless we need to do something specific simply display
329 the desktop in a separate explorer window */
334 TrayMessageLoop(Tray
);
336 if (hShellDesktop
!= NULL
)
337 DesktopDestroyShellWindow(hShellDesktop
);
339 /* FIXME - shutdown SSO Thread */
343 RegCloseKey(hkExplorer
);