Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenexplorer.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS Explorer 00003 * 00004 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include <precomp.h> 00022 00023 HINSTANCE hExplorerInstance; 00024 HMODULE hUser32; 00025 HANDLE hProcessHeap; 00026 HKEY hkExplorer = NULL; 00027 DRAWCAPTEMP DrawCapTemp = NULL; 00028 00029 typedef struct _LANGCODEPAGE 00030 { 00031 WORD wLanguage; 00032 WORD wCodePage; 00033 } LANGCODEPAGE, *PLANGCODEPAGE; 00034 00035 LONG 00036 SetWindowStyle(IN HWND hWnd, 00037 IN LONG dwStyleMask, 00038 IN LONG dwStyle) 00039 { 00040 LONG PrevStyle, Style; 00041 00042 ASSERT((~dwStyleMask & dwStyle) == 0); 00043 00044 PrevStyle = GetWindowLongPtr(hWnd, 00045 GWL_STYLE); 00046 if (PrevStyle != 0 && 00047 (PrevStyle & dwStyleMask) != dwStyle) 00048 { 00049 Style = PrevStyle & ~dwStyleMask; 00050 Style |= dwStyle; 00051 00052 PrevStyle = SetWindowLongPtr(hWnd, 00053 GWL_STYLE, 00054 Style); 00055 } 00056 00057 return PrevStyle; 00058 } 00059 00060 LONG 00061 SetWindowExStyle(IN HWND hWnd, 00062 IN LONG dwStyleMask, 00063 IN LONG dwStyle) 00064 { 00065 LONG PrevStyle, Style; 00066 00067 ASSERT((~dwStyleMask & dwStyle) == 0); 00068 00069 PrevStyle = GetWindowLongPtr(hWnd, 00070 GWL_EXSTYLE); 00071 if (PrevStyle != 0 && 00072 (PrevStyle & dwStyleMask) != dwStyle) 00073 { 00074 Style = PrevStyle & ~dwStyleMask; 00075 Style |= dwStyle; 00076 00077 PrevStyle = SetWindowLongPtr(hWnd, 00078 GWL_EXSTYLE, 00079 Style); 00080 } 00081 00082 return PrevStyle; 00083 } 00084 00085 HMENU 00086 LoadPopupMenu(IN HINSTANCE hInstance, 00087 IN LPCTSTR lpMenuName) 00088 { 00089 HMENU hMenu, hSubMenu = NULL; 00090 00091 hMenu = LoadMenu(hInstance, 00092 lpMenuName); 00093 00094 if (hMenu != NULL) 00095 { 00096 hSubMenu = GetSubMenu(hMenu, 00097 0); 00098 if (hSubMenu != NULL && 00099 !RemoveMenu(hMenu, 00100 0, 00101 MF_BYPOSITION)) 00102 { 00103 hSubMenu = NULL; 00104 } 00105 00106 DestroyMenu(hMenu); 00107 } 00108 00109 return hSubMenu; 00110 } 00111 00112 HMENU 00113 FindSubMenu(IN HMENU hMenu, 00114 IN UINT uItem, 00115 IN BOOL fByPosition) 00116 { 00117 MENUITEMINFO mii; 00118 00119 mii.cbSize = sizeof(mii); 00120 mii.fMask = MIIM_SUBMENU; 00121 00122 if (GetMenuItemInfo(hMenu, 00123 uItem, 00124 fByPosition, 00125 &mii)) 00126 { 00127 return mii.hSubMenu; 00128 } 00129 00130 return NULL; 00131 } 00132 00133 BOOL 00134 GetCurrentLoggedOnUserName(OUT LPTSTR szBuffer, 00135 IN DWORD dwBufferSize) 00136 { 00137 DWORD dwType; 00138 DWORD dwSize; 00139 00140 /* Query the user name from the registry */ 00141 dwSize = (dwBufferSize * sizeof(TCHAR)) - 1; 00142 if (RegQueryValueEx(hkExplorer, 00143 TEXT("Logon User Name"), 00144 0, 00145 &dwType, 00146 (LPBYTE)szBuffer, 00147 &dwSize) == ERROR_SUCCESS && 00148 (dwSize / sizeof(TCHAR)) > 1 && 00149 szBuffer[0] != _T('\0')) 00150 { 00151 szBuffer[dwSize / sizeof(TCHAR)] = _T('\0'); 00152 return TRUE; 00153 } 00154 00155 /* Fall back to GetUserName() */ 00156 dwSize = dwBufferSize; 00157 if (!GetUserName(szBuffer, 00158 &dwSize)) 00159 { 00160 szBuffer[0] = _T('\0'); 00161 return FALSE; 00162 } 00163 00164 return TRUE; 00165 } 00166 00167 BOOL 00168 FormatMenuString(IN HMENU hMenu, 00169 IN UINT uPosition, 00170 IN UINT uFlags, 00171 ...) 00172 { 00173 va_list vl; 00174 MENUITEMINFO mii; 00175 TCHAR szBuf[128]; 00176 TCHAR szBufFmt[128]; 00177 00178 /* Find the menu item and read the formatting string */ 00179 mii.cbSize = sizeof(mii); 00180 mii.fMask = MIIM_STRING; 00181 mii.dwTypeData = (LPTSTR)szBufFmt; 00182 mii.cch = sizeof(szBufFmt) / sizeof(szBufFmt[0]); 00183 if (GetMenuItemInfo(hMenu, 00184 uPosition, 00185 uFlags, 00186 &mii)) 00187 { 00188 /* Format the string */ 00189 va_start(vl, uFlags); 00190 _vsntprintf(szBuf, 00191 (sizeof(szBuf) / sizeof(szBuf[0])) - 1, 00192 szBufFmt, 00193 vl); 00194 va_end(vl); 00195 szBuf[(sizeof(szBuf) / sizeof(szBuf[0])) - 1] = _T('\0'); 00196 00197 /* Update the menu item */ 00198 mii.dwTypeData = (LPTSTR)szBuf; 00199 if (SetMenuItemInfo(hMenu, 00200 uPosition, 00201 uFlags, 00202 &mii)) 00203 { 00204 return TRUE; 00205 } 00206 } 00207 00208 return FALSE; 00209 } 00210 00211 BOOL 00212 GetExplorerRegValueSet(IN HKEY hKey, 00213 IN LPCTSTR lpSubKey, 00214 IN LPCTSTR lpValue) 00215 { 00216 TCHAR szBuffer[MAX_PATH]; 00217 HKEY hkSubKey; 00218 DWORD dwType, dwSize; 00219 BOOL Ret = FALSE; 00220 00221 _tcscpy(szBuffer, 00222 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer")); 00223 _tcscat(szBuffer, 00224 _T("\\")); 00225 _tcscat(szBuffer, 00226 lpSubKey); 00227 00228 dwSize = sizeof(szBuffer); 00229 if (RegOpenKeyEx(hKey, 00230 szBuffer, 00231 0, 00232 KEY_QUERY_VALUE, 00233 &hkSubKey) == ERROR_SUCCESS) 00234 { 00235 ZeroMemory(szBuffer, 00236 sizeof(szBuffer)); 00237 00238 if (RegQueryValueEx(hkSubKey, 00239 lpValue, 00240 0, 00241 &dwType, 00242 (LPBYTE)szBuffer, 00243 &dwSize) == ERROR_SUCCESS) 00244 { 00245 if (dwType == REG_DWORD && dwSize == sizeof(DWORD)) 00246 Ret = *((PDWORD)szBuffer) != 0; 00247 else if (dwSize > 0) 00248 Ret = *((PUCHAR)szBuffer) != 0; 00249 } 00250 00251 RegCloseKey(hkSubKey); 00252 } 00253 return Ret; 00254 } 00255 00256 00257 static BOOL 00258 SetShellReadyEvent(IN LPCTSTR lpEventName) 00259 { 00260 HANDLE hEvent; 00261 00262 hEvent = OpenEvent(EVENT_MODIFY_STATE, 00263 FALSE, 00264 lpEventName); 00265 if (hEvent != NULL) 00266 { 00267 SetEvent(hEvent); 00268 00269 CloseHandle(hEvent); 00270 return TRUE; 00271 } 00272 00273 return FALSE; 00274 } 00275 00276 BOOL 00277 GetVersionInfoString(IN TCHAR *szFileName, 00278 IN TCHAR *szVersionInfo, 00279 OUT TCHAR *szBuffer, 00280 IN UINT cbBufLen) 00281 { 00282 LPVOID lpData = NULL; 00283 TCHAR szSubBlock[128]; 00284 TCHAR *lpszLocalBuf = NULL; 00285 LANGID UserLangId; 00286 PLANGCODEPAGE lpTranslate = NULL; 00287 DWORD dwLen; 00288 DWORD dwHandle; 00289 UINT cbTranslate; 00290 UINT cbLen; 00291 BOOL bRet = FALSE; 00292 unsigned int i; 00293 00294 dwLen = GetFileVersionInfoSize(szFileName,&dwHandle); 00295 00296 if (dwLen > 0) 00297 { 00298 lpData = HeapAlloc(hProcessHeap,0,dwLen); 00299 00300 if (lpData != NULL) 00301 { 00302 if (GetFileVersionInfo(szFileName, 00303 0, 00304 dwLen, 00305 lpData) != 0) 00306 { 00307 UserLangId = GetUserDefaultLangID(); 00308 00309 VerQueryValue(lpData, 00310 TEXT("\\VarFileInfo\\Translation"), 00311 (LPVOID *)&lpTranslate, 00312 &cbTranslate); 00313 00314 for (i = 0;i < (cbTranslate / sizeof(LANGCODEPAGE));i++) 00315 { 00316 /* If the bottom eight bits of the language id's 00317 match, use this version information (since this 00318 means that the version information and the users 00319 default language are the same). */ 00320 if ((lpTranslate[i].wLanguage & 0xFF) == 00321 (UserLangId & 0xFF)) 00322 { 00323 wnsprintf(szSubBlock, 00324 sizeof(szSubBlock) / sizeof(szSubBlock[0]), 00325 TEXT("\\StringFileInfo\\%04X%04X\\%s"), 00326 lpTranslate[i].wLanguage, 00327 lpTranslate[i].wCodePage,szVersionInfo); 00328 00329 if (VerQueryValue(lpData, 00330 szSubBlock, 00331 (LPVOID *)&lpszLocalBuf, 00332 &cbLen) != 0) 00333 { 00334 wcsncpy(szBuffer,lpszLocalBuf,cbBufLen); 00335 00336 bRet = TRUE; 00337 break; 00338 } 00339 } 00340 } 00341 } 00342 HeapFree(hProcessHeap,0,lpData); 00343 lpData = NULL; 00344 } 00345 } 00346 00347 return bRet; 00348 } 00349 00350 INT WINAPI 00351 _tWinMain(IN HINSTANCE hInstance, 00352 IN HINSTANCE hPrevInstance, 00353 IN LPTSTR lpCmdLine, 00354 IN INT nCmdShow) 00355 { 00356 ITrayWindow *Tray = NULL; 00357 HANDLE hShellDesktop = NULL; 00358 BOOL CreateShellDesktop = FALSE; 00359 00360 if (RegOpenKey(HKEY_CURRENT_USER, 00361 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), 00362 &hkExplorer) != ERROR_SUCCESS) 00363 { 00364 TCHAR Message[256]; 00365 LoadString(hInstance, IDS_STARTUP_ERROR, Message, 256); 00366 MessageBox(NULL, Message, NULL, MB_ICONERROR); 00367 return 1; 00368 } 00369 00370 hExplorerInstance = hInstance; 00371 hProcessHeap = GetProcessHeap(); 00372 00373 hUser32 = GetModuleHandle(TEXT("USER32.DLL")); 00374 if (hUser32 != NULL) 00375 { 00376 DrawCapTemp = (DRAWCAPTEMP)GetProcAddress(hUser32, 00377 PROC_NAME_DRAWCAPTIONTEMP); 00378 } 00379 00380 InitCommonControls(); 00381 OleInitialize(NULL); 00382 00383 if (GetShellWindow() == NULL) 00384 CreateShellDesktop = TRUE; 00385 00386 /* FIXME - initialize SSO Thread */ 00387 00388 if (CreateShellDesktop) 00389 { 00390 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass()) 00391 { 00392 Tray = CreateTrayWindow(); 00393 00394 if (Tray != NULL) 00395 hShellDesktop = DesktopCreateWindow(Tray); 00396 } 00397 00398 /* WinXP: Notify msgina to hide the welcome screen */ 00399 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent"))) 00400 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent")); 00401 } 00402 else 00403 { 00404 /* A shell is already loaded. Parse the command line arguments 00405 and unless we need to do something specific simply display 00406 the desktop in a separate explorer window */ 00407 /* FIXME */ 00408 } 00409 00410 if (Tray != NULL) 00411 TrayMessageLoop(Tray); 00412 00413 if (hShellDesktop != NULL) 00414 DesktopDestroyShellWindow(hShellDesktop); 00415 00416 /* FIXME - shutdown SSO Thread */ 00417 00418 OleUninitialize(); 00419 00420 RegCloseKey(hkExplorer); 00421 hkExplorer = NULL; 00422 00423 return 0; 00424 } Generated on Sun May 27 2012 04:18:26 for ReactOS by
1.7.6.1
|