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
;
29 typedef struct _LANGCODEPAGE
33 } LANGCODEPAGE
, *PLANGCODEPAGE
;
36 SetWindowStyle(IN HWND hWnd
,
40 LONG PrevStyle
, Style
;
42 ASSERT((~dwStyleMask
& dwStyle
) == 0);
44 PrevStyle
= GetWindowLong(hWnd
,
47 (PrevStyle
& dwStyleMask
) != dwStyle
)
49 Style
= PrevStyle
& ~dwStyleMask
;
52 PrevStyle
= SetWindowLong(hWnd
,
61 SetWindowExStyle(IN HWND hWnd
,
65 LONG PrevStyle
, Style
;
67 ASSERT((~dwStyleMask
& dwStyle
) == 0);
69 PrevStyle
= GetWindowLong(hWnd
,
72 (PrevStyle
& dwStyleMask
) != dwStyle
)
74 Style
= PrevStyle
& ~dwStyleMask
;
77 PrevStyle
= SetWindowLong(hWnd
,
86 LoadPopupMenu(IN HINSTANCE hInstance
,
87 IN LPCTSTR lpMenuName
)
89 HMENU hMenu
, hSubMenu
= NULL
;
91 hMenu
= LoadMenu(hInstance
,
96 hSubMenu
= GetSubMenu(hMenu
,
98 if (hSubMenu
!= NULL
&&
113 FindSubMenu(IN HMENU hMenu
,
119 mii
.cbSize
= sizeof(mii
);
120 mii
.fMask
= MIIM_SUBMENU
;
122 if (GetMenuItemInfo(hMenu
,
134 GetCurrentLoggedOnUserName(OUT LPTSTR szBuffer
,
135 IN DWORD dwBufferSize
)
140 /* Query the user name from the registry */
141 dwSize
= (dwBufferSize
* sizeof(TCHAR
)) - 1;
142 if (RegQueryValueEx(hkExplorer
,
143 TEXT("Logon User Name"),
147 &dwSize
) == ERROR_SUCCESS
&&
148 (dwSize
/ sizeof(TCHAR
)) > 1 &&
149 szBuffer
[0] != _T('\0'))
151 szBuffer
[dwSize
/ sizeof(TCHAR
)] = _T('\0');
155 /* Fall back to GetUserName() */
156 dwSize
= dwBufferSize
;
157 if (!GetUserName(szBuffer
,
160 szBuffer
[0] = _T('\0');
168 FormatMenuString(IN HMENU hMenu
,
178 /* Find the menu item and read the formatting string */
179 mii
.cbSize
= sizeof(mii
);
180 mii
.fMask
= MIIM_STRING
;
181 mii
.dwTypeData
= (LPTSTR
)szBufFmt
;
182 mii
.cch
= sizeof(szBufFmt
) / sizeof(szBufFmt
[0]);
183 if (GetMenuItemInfo(hMenu
,
188 /* Format the string */
189 va_start(vl
, uFlags
);
191 (sizeof(szBuf
) / sizeof(szBuf
[0])) - 1,
195 szBuf
[(sizeof(szBuf
) / sizeof(szBuf
[0])) - 1] = _T('\0');
197 /* Update the menu item */
198 mii
.dwTypeData
= (LPTSTR
)szBuf
;
199 if (SetMenuItemInfo(hMenu
,
212 GetExplorerRegValueSet(IN HKEY hKey
,
216 TCHAR szBuffer
[MAX_PATH
];
218 DWORD dwType
, dwSize
;
222 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"));
228 dwSize
= sizeof(szBuffer
);
229 if (RegOpenKeyEx(hKey
,
233 &hkSubKey
) == ERROR_SUCCESS
)
238 if (RegQueryValueEx(hkSubKey
,
243 &dwSize
) == ERROR_SUCCESS
)
245 if (dwType
== REG_DWORD
&& dwSize
== sizeof(DWORD
))
246 Ret
= *((PDWORD
)szBuffer
) != 0;
248 Ret
= *((PUCHAR
)szBuffer
) != 0;
251 RegCloseKey(hkSubKey
);
258 SetShellReadyEvent(IN LPCTSTR lpEventName
)
262 hEvent
= OpenEvent(EVENT_MODIFY_STATE
,
277 GetVersionInfoString(IN TCHAR
*szFileName
,
278 IN TCHAR
*szVersionInfo
,
282 LPVOID lpData
= NULL
;
283 TCHAR szSubBlock
[128];
284 TCHAR
*lpszLocalBuf
= NULL
;
286 PLANGCODEPAGE lpTranslate
= NULL
;
294 dwLen
= GetFileVersionInfoSize(szFileName
, &dwHandle
);
298 lpData
= HeapAlloc(hProcessHeap
, 0, dwLen
);
302 if (GetFileVersionInfo(szFileName
,
307 UserLangId
= GetUserDefaultLangID();
309 VerQueryValue(lpData
,
310 TEXT("\\VarFileInfo\\Translation"),
311 (LPVOID
*)&lpTranslate
,
314 for (i
= 0; i
< cbTranslate
/ sizeof(LANGCODEPAGE
); i
++)
316 /* If the bottom eight bits of the language id's
317 match, use this version information (since this
318 means that the version information and the users
319 default language are the same). */
320 if ((lpTranslate
[i
].wLanguage
& 0xFF) ==
323 wnsprintf(szSubBlock
,
324 sizeof(szSubBlock
) / sizeof(szSubBlock
[0]),
325 TEXT("\\StringFileInfo\\%04X%04X\\%s"),
326 lpTranslate
[i
].wLanguage
,
327 lpTranslate
[i
].wCodePage
,
330 if (VerQueryValue(lpData
,
332 (LPVOID
*)&lpszLocalBuf
,
335 wcsncpy(szBuffer
, lpszLocalBuf
, cbBufLen
);
343 HeapFree(hProcessHeap
, 0, lpData
);
352 _tWinMain(IN HINSTANCE hInstance
,
353 IN HINSTANCE hPrevInstance
,
357 ITrayWindow
*Tray
= NULL
;
358 HANDLE hShellDesktop
= NULL
;
359 BOOL CreateShellDesktop
= FALSE
;
361 if (RegOpenKey(HKEY_CURRENT_USER
,
362 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"),
363 &hkExplorer
) != ERROR_SUCCESS
)
366 LoadString(hInstance
, IDS_STARTUP_ERROR
, Message
, 256);
367 MessageBox(NULL
, Message
, NULL
, MB_ICONERROR
);
371 hExplorerInstance
= hInstance
;
372 hProcessHeap
= GetProcessHeap();
373 LoadAdvancedSettings();
375 hUser32
= GetModuleHandle(TEXT("USER32.DLL"));
378 DrawCapTemp
= (DRAWCAPTEMP
)GetProcAddress(hUser32
,
379 PROC_NAME_DRAWCAPTIONTEMP
);
382 InitCommonControls();
385 if (GetShellWindow() == NULL
)
386 CreateShellDesktop
= TRUE
;
388 /* FIXME - initialize SSO Thread */
390 if (CreateShellDesktop
)
392 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass())
394 Tray
= CreateTrayWindow();
397 hShellDesktop
= DesktopCreateWindow(Tray
);
400 /* WinXP: Notify msgina to hide the welcome screen */
401 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
402 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
406 /* A shell is already loaded. Parse the command line arguments
407 and unless we need to do something specific simply display
408 the desktop in a separate explorer window */
414 RegisterHotKey(NULL
, IDHK_RUN
, MOD_WIN
, 'R');
415 TrayMessageLoop(Tray
);
416 ITrayWindow_Release(Tray
);
417 UnregisterTrayWindowClass();
420 if (hShellDesktop
!= NULL
)
421 DesktopDestroyShellWindow(hShellDesktop
);
423 /* FIXME - shutdown SSO Thread */
427 RegCloseKey(hkExplorer
);