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 #include <browseui_undoc.h> 23 24 HINSTANCE hExplorerInstance; 25 HANDLE hProcessHeap; 26 HKEY hkExplorer = NULL; 27 28 class CExplorerModule : public CComModule 29 { 30 public: 31 }; 32 33 BEGIN_OBJECT_MAP(ObjectMap) 34 END_OBJECT_MAP() 35 36 CExplorerModule gModule; 37 CAtlWinModule gWinModule; 38 39 static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize) 40 { 41 if (bInitialize) 42 { 43 gModule.Init(ObjectMap, hInstance, NULL); 44 } 45 else 46 { 47 gModule.Term(); 48 } 49 } 50 51 #if !WIN7_DEBUG_MODE 52 static BOOL 53 SetShellReadyEvent(IN LPCWSTR lpEventName) 54 { 55 HANDLE hEvent; 56 57 hEvent = OpenEventW(EVENT_MODIFY_STATE, FALSE, lpEventName); 58 if (hEvent != NULL) 59 { 60 SetEvent(hEvent); 61 62 CloseHandle(hEvent); 63 return TRUE; 64 } 65 66 return FALSE; 67 } 68 69 static VOID 70 HideMinimizedWindows(IN BOOL bHide) 71 { 72 MINIMIZEDMETRICS mm; 73 74 mm.cbSize = sizeof(mm); 75 if (!SystemParametersInfoW(SPI_GETMINIMIZEDMETRICS, sizeof(mm), &mm, 0)) 76 { 77 ERR("SystemParametersInfoW failed with %lu\n", GetLastError()); 78 return; 79 } 80 if (bHide) 81 mm.iArrange |= ARW_HIDE; 82 else 83 mm.iArrange &= ~ARW_HIDE; 84 if (!SystemParametersInfoW(SPI_SETMINIMIZEDMETRICS, sizeof(mm), &mm, 0)) 85 ERR("SystemParametersInfoW failed with %lu\n", GetLastError()); 86 } 87 #endif 88 89 #if !WIN7_COMPAT_MODE 90 static INT 91 StartWithCommandLine(IN HINSTANCE hInstance) 92 { 93 BOOL b = FALSE; 94 EXPLORER_CMDLINE_PARSE_RESULTS parseResults = { 0 }; 95 96 if (SHExplorerParseCmdLine(&parseResults)) 97 b = SHCreateFromDesktop(&parseResults); 98 99 if (parseResults.strPath) 100 SHFree(parseResults.strPath); 101 102 if (parseResults.pidlPath) 103 ILFree(parseResults.pidlPath); 104 105 if (parseResults.pidlRoot) 106 ILFree(parseResults.pidlRoot); 107 108 return b; 109 } 110 #endif 111 112 static INT 113 StartWithDesktop(IN HINSTANCE hInstance) 114 { 115 InitializeAtlModule(hInstance, TRUE); 116 117 if (RegOpenKeyW(HKEY_CURRENT_USER, 118 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", 119 &hkExplorer) != ERROR_SUCCESS) 120 { 121 WCHAR Message[256]; 122 LoadStringW(hInstance, IDS_STARTUP_ERROR, Message, _countof(Message)); 123 MessageBox(NULL, Message, NULL, MB_ICONERROR); 124 return 1; 125 } 126 127 hExplorerInstance = hInstance; 128 hProcessHeap = GetProcessHeap(); 129 130 g_TaskbarSettings.Load(); 131 132 InitCommonControls(); 133 OleInitialize(NULL); 134 135 #if !WIN7_DEBUG_MODE 136 ProcessStartupItems(); 137 #endif 138 139 #if !WIN7_COMPAT_MODE 140 /* Initialize shell dde support */ 141 _ShellDDEInit(TRUE); 142 #endif 143 144 /* Initialize shell icons */ 145 FileIconInit(TRUE); 146 147 /* Initialize CLSID_ShellWindows class */ 148 _WinList_Init(); 149 150 CComPtr<ITrayWindow> Tray; 151 CreateTrayWindow(&Tray); 152 153 #if !WIN7_DEBUG_MODE 154 /* This not only hides the minimized window captions in the bottom 155 left screen corner, but is also needed in order to receive 156 HSHELL_* notification messages (which are required for taskbar 157 buttons to work right) */ 158 HideMinimizedWindows(TRUE); 159 160 HANDLE hShellDesktop = NULL; 161 if (Tray != NULL) 162 hShellDesktop = DesktopCreateWindow(Tray); 163 164 /* WinXP: Notify msgina to hide the welcome screen */ 165 if (!SetShellReadyEvent(L"msgina: ShellReadyEvent")) 166 SetShellReadyEvent(L"Global\\msgina: ShellReadyEvent"); 167 #endif 168 169 if (Tray != NULL) 170 { 171 TrayMessageLoop(Tray); 172 #if !WIN7_DEBUG_MODE 173 HideMinimizedWindows(FALSE); 174 #endif 175 } 176 177 #if !WIN7_DEBUG_MODE 178 if (hShellDesktop != NULL) 179 DesktopDestroyShellWindow(hShellDesktop); 180 #endif 181 182 OleUninitialize(); 183 184 RegCloseKey(hkExplorer); 185 hkExplorer = NULL; 186 187 InitializeAtlModule(hInstance, FALSE); 188 189 return 0; 190 } 191 192 INT WINAPI 193 _tWinMain(IN HINSTANCE hInstance, 194 IN HINSTANCE hPrevInstance, 195 IN LPTSTR lpCmdLine, 196 IN INT nCmdShow) 197 { 198 /* 199 * Set our shutdown parameters: we want to shutdown the very last, 200 * but before any TaskMgr instance (which has a shutdown level of 1). 201 */ 202 SetProcessShutdownParameters(2, 0); 203 204 InitRSHELL(); 205 206 #if !WIN7_COMPAT_MODE 207 BOOL CreateShellDesktop = FALSE; 208 209 TRACE("Explorer starting... Commandline: %S\n", lpCmdLine); 210 211 if (GetShellWindow() == NULL) 212 CreateShellDesktop = TRUE; 213 214 if (!CreateShellDesktop) 215 { 216 return StartWithCommandLine(hInstance); 217 } 218 #endif 219 220 return StartWithDesktop(hInstance); 221 } 222