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
22 #include <shlwapi_undoc.h>
25 HINSTANCE hExplorerInstance
;
28 HKEY hkExplorer
= NULL
;
29 DRAWCAPTEMP DrawCapTemp
= NULL
;
31 typedef struct _LANGCODEPAGE
35 } LANGCODEPAGE
, *PLANGCODEPAGE
;
38 SetWindowStyle(IN HWND hWnd
,
42 LONG PrevStyle
, Style
;
44 ASSERT((~dwStyleMask
& dwStyle
) == 0);
46 PrevStyle
= GetWindowLong(hWnd
,
49 (PrevStyle
& dwStyleMask
) != dwStyle
)
51 Style
= PrevStyle
& ~dwStyleMask
;
54 PrevStyle
= SetWindowLong(hWnd
,
63 SetWindowExStyle(IN HWND hWnd
,
67 LONG PrevStyle
, Style
;
69 ASSERT((~dwStyleMask
& dwStyle
) == 0);
71 PrevStyle
= GetWindowLong(hWnd
,
74 (PrevStyle
& dwStyleMask
) != dwStyle
)
76 Style
= PrevStyle
& ~dwStyleMask
;
79 PrevStyle
= SetWindowLong(hWnd
,
88 LoadPopupMenu(IN HINSTANCE hInstance
,
89 IN LPCTSTR lpMenuName
)
91 HMENU hMenu
, hSubMenu
= NULL
;
93 hMenu
= LoadMenu(hInstance
,
98 hSubMenu
= GetSubMenu(hMenu
,
100 if (hSubMenu
!= NULL
&&
115 FindSubMenu(IN HMENU hMenu
,
121 mii
.cbSize
= sizeof(mii
);
122 mii
.fMask
= MIIM_SUBMENU
;
124 if (GetMenuItemInfo(hMenu
,
136 GetCurrentLoggedOnUserName(OUT LPTSTR szBuffer
,
137 IN DWORD dwBufferSize
)
142 /* Query the user name from the registry */
143 dwSize
= (dwBufferSize
* sizeof(TCHAR
)) - 1;
144 if (RegQueryValueEx(hkExplorer
,
145 TEXT("Logon User Name"),
149 &dwSize
) == ERROR_SUCCESS
&&
150 (dwSize
/ sizeof(TCHAR
)) > 1 &&
151 szBuffer
[0] != _T('\0'))
153 szBuffer
[dwSize
/ sizeof(TCHAR
)] = _T('\0');
157 /* Fall back to GetUserName() */
158 dwSize
= dwBufferSize
;
159 if (!GetUserName(szBuffer
,
162 szBuffer
[0] = _T('\0');
170 FormatMenuString(IN HMENU hMenu
,
180 /* Find the menu item and read the formatting string */
181 mii
.cbSize
= sizeof(mii
);
182 mii
.fMask
= MIIM_STRING
;
183 mii
.dwTypeData
= (LPTSTR
)szBufFmt
;
184 mii
.cch
= sizeof(szBufFmt
) / sizeof(szBufFmt
[0]);
185 if (GetMenuItemInfo(hMenu
,
190 /* Format the string */
191 va_start(vl
, uFlags
);
193 (sizeof(szBuf
) / sizeof(szBuf
[0])) - 1,
197 szBuf
[(sizeof(szBuf
) / sizeof(szBuf
[0])) - 1] = _T('\0');
199 /* Update the menu item */
200 mii
.dwTypeData
= (LPTSTR
)szBuf
;
201 if (SetMenuItemInfo(hMenu
,
214 GetExplorerRegValueSet(IN HKEY hKey
,
218 TCHAR szBuffer
[MAX_PATH
];
220 DWORD dwType
, dwSize
;
223 StringCbCopy(szBuffer
, sizeof(szBuffer
),
224 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"));
225 if (FAILED(StringCbCat(szBuffer
, sizeof(szBuffer
),
228 if (FAILED(StringCbCat(szBuffer
, sizeof(szBuffer
),
232 dwSize
= sizeof(szBuffer
);
233 if (RegOpenKeyEx(hKey
,
237 &hkSubKey
) == ERROR_SUCCESS
)
242 if (RegQueryValueEx(hkSubKey
,
247 &dwSize
) == ERROR_SUCCESS
)
249 if (dwType
== REG_DWORD
&& dwSize
== sizeof(DWORD
))
250 Ret
= *((PDWORD
)szBuffer
) != 0;
252 Ret
= *((PUCHAR
)szBuffer
) != 0;
255 RegCloseKey(hkSubKey
);
262 SetShellReadyEvent(IN LPCTSTR lpEventName
)
266 hEvent
= OpenEvent(EVENT_MODIFY_STATE
,
281 GetVersionInfoString(IN TCHAR
*szFileName
,
282 IN TCHAR
*szVersionInfo
,
286 LPVOID lpData
= NULL
;
287 TCHAR szSubBlock
[128];
288 TCHAR
*lpszLocalBuf
= NULL
;
290 PLANGCODEPAGE lpTranslate
= NULL
;
298 dwLen
= GetFileVersionInfoSize(szFileName
, &dwHandle
);
302 lpData
= HeapAlloc(hProcessHeap
, 0, dwLen
);
306 if (GetFileVersionInfo(szFileName
,
311 UserLangId
= GetUserDefaultLangID();
313 VerQueryValue(lpData
,
314 TEXT("\\VarFileInfo\\Translation"),
315 (LPVOID
*)&lpTranslate
,
318 for (i
= 0; i
< cbTranslate
/ sizeof(LANGCODEPAGE
); i
++)
320 /* If the bottom eight bits of the language id's
321 match, use this version information (since this
322 means that the version information and the users
323 default language are the same). */
324 if ((lpTranslate
[i
].wLanguage
& 0xFF) ==
327 wnsprintf(szSubBlock
,
328 sizeof(szSubBlock
) / sizeof(szSubBlock
[0]),
329 TEXT("\\StringFileInfo\\%04X%04X\\%s"),
330 lpTranslate
[i
].wLanguage
,
331 lpTranslate
[i
].wCodePage
,
334 if (VerQueryValue(lpData
,
336 (LPVOID
*)&lpszLocalBuf
,
339 _tcsncpy(szBuffer
, lpszLocalBuf
, cbBufLen
/ sizeof(*szBuffer
));
347 HeapFree(hProcessHeap
, 0, lpData
);
356 HideMinimizedWindows(IN BOOL bHide
)
360 mm
.cbSize
= sizeof(mm
);
361 if (!SystemParametersInfo(SPI_GETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0))
363 ERR("SystemParametersInfo failed with %lu\n", GetLastError());
367 mm
.iArrange
|= ARW_HIDE
;
369 mm
.iArrange
&= ~ARW_HIDE
;
370 if (!SystemParametersInfo(SPI_SETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0))
371 ERR("SystemParametersInfo failed with %lu\n", GetLastError());
375 _tWinMain(IN HINSTANCE hInstance
,
376 IN HINSTANCE hPrevInstance
,
380 ITrayWindow
*Tray
= NULL
;
381 HANDLE hShellDesktop
= NULL
;
382 BOOL CreateShellDesktop
= FALSE
;
384 DbgPrint("Explorer starting... Commandline: %S\n", lpCmdLine
);
387 * Set our shutdown parameters: we want to shutdown the very last,
388 * but before any TaskMgr instance (which has a shutdown level of 1).
390 SetProcessShutdownParameters(2, 0);
392 if (GetShellWindow() == NULL
)
393 CreateShellDesktop
= TRUE
;
395 if (!CreateShellDesktop
)
397 EXPLORER_CMDLINE_PARSE_RESULTS parseResults
= { 0 };
399 if (SHExplorerParseCmdLine(&parseResults
))
400 return SHCreateFromDesktop(&parseResults
);
402 if (parseResults
.strPath
)
403 SHFree(parseResults
.strPath
);
405 if (parseResults
.pidlPath
)
406 ILFree(parseResults
.pidlPath
);
408 if (parseResults
.pidlRoot
)
409 ILFree(parseResults
.pidlRoot
);
413 if (RegOpenKey(HKEY_CURRENT_USER
,
414 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"),
415 &hkExplorer
) != ERROR_SUCCESS
)
418 LoadString(hInstance
, IDS_STARTUP_ERROR
, Message
, 256);
419 MessageBox(NULL
, Message
, NULL
, MB_ICONERROR
);
423 hExplorerInstance
= hInstance
;
424 hProcessHeap
= GetProcessHeap();
425 LoadAdvancedSettings();
427 hUser32
= GetModuleHandle(TEXT("USER32.DLL"));
430 DrawCapTemp
= (DRAWCAPTEMP
)GetProcAddress(hUser32
,
431 PROC_NAME_DRAWCAPTIONTEMP
);
434 InitCommonControls();
437 ProcessStartupItems();
439 /* Initialize shell dde support */
442 /* Initialize shell icons */
445 /* Initialize CLSID_ShellWindows class */
448 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass())
450 Tray
= CreateTrayWindow();
451 /* This not only hides the minimized window captions in the bottom
452 left screen corner, but is also needed in order to receive
453 HSHELL_* notification messages (which are required for taskbar
454 buttons to work right) */
455 HideMinimizedWindows(TRUE
);
458 hShellDesktop
= DesktopCreateWindow(Tray
);
461 /* WinXP: Notify msgina to hide the welcome screen */
462 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
463 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
467 RegisterHotKey(NULL
, IDHK_RUN
, MOD_WIN
, 'R');
468 TrayMessageLoop(Tray
);
469 HideMinimizedWindows(FALSE
);
470 ITrayWindow_Release(Tray
);
471 UnregisterTrayWindowClass();
474 if (hShellDesktop
!= NULL
)
475 DesktopDestroyShellWindow(hShellDesktop
);
477 /* FIXME - shutdown SSO Thread */
481 RegCloseKey(hkExplorer
);