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 _tcsncpy(szBuffer
, lpszLocalBuf
, cbBufLen
/ sizeof(*szBuffer
));
343 HeapFree(hProcessHeap
, 0, lpData
);
352 HideMinimizedWindows(IN BOOL bHide
)
356 mm
.cbSize
= sizeof(mm
);
357 if (!SystemParametersInfo(SPI_GETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0))
359 DbgPrint("SystemParametersInfo failed with %lu\n", GetLastError());
363 mm
.iArrange
|= ARW_HIDE
;
365 mm
.iArrange
&= ~ARW_HIDE
;
366 if (!SystemParametersInfo(SPI_SETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0))
367 DbgPrint("SystemParametersInfo failed with %lu\n", GetLastError());
371 _tWinMain(IN HINSTANCE hInstance
,
372 IN HINSTANCE hPrevInstance
,
376 ITrayWindow
*Tray
= NULL
;
377 HANDLE hShellDesktop
= NULL
;
378 BOOL CreateShellDesktop
= FALSE
;
380 if (RegOpenKey(HKEY_CURRENT_USER
,
381 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"),
382 &hkExplorer
) != ERROR_SUCCESS
)
385 LoadString(hInstance
, IDS_STARTUP_ERROR
, Message
, 256);
386 MessageBox(NULL
, Message
, NULL
, MB_ICONERROR
);
390 hExplorerInstance
= hInstance
;
391 hProcessHeap
= GetProcessHeap();
392 LoadAdvancedSettings();
394 hUser32
= GetModuleHandle(TEXT("USER32.DLL"));
397 DrawCapTemp
= (DRAWCAPTEMP
)GetProcAddress(hUser32
,
398 PROC_NAME_DRAWCAPTIONTEMP
);
401 InitCommonControls();
404 ProcessStartupItems();
406 if (GetShellWindow() == NULL
)
407 CreateShellDesktop
= TRUE
;
409 /* FIXME - initialize SSO Thread */
411 if (CreateShellDesktop
)
413 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass())
415 Tray
= CreateTrayWindow();
416 /* This not only hides the minimized window captions in the bottom
417 left screen corner, but is also needed in order to receive
418 HSHELL_* notification messages (which are required for taskbar
419 buttons to work right) */
420 HideMinimizedWindows(TRUE
);
423 hShellDesktop
= DesktopCreateWindow(Tray
);
426 /* WinXP: Notify msgina to hide the welcome screen */
427 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
428 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
432 /* A shell is already loaded. Parse the command line arguments
433 and unless we need to do something specific simply display
434 the desktop in a separate explorer window */
440 RegisterHotKey(NULL
, IDHK_RUN
, MOD_WIN
, 'R');
441 TrayMessageLoop(Tray
);
442 HideMinimizedWindows(FALSE
);
443 ITrayWindow_Release(Tray
);
444 UnregisterTrayWindowClass();
447 if (hShellDesktop
!= NULL
)
448 DesktopDestroyShellWindow(hShellDesktop
);
450 /* FIXME - shutdown SSO Thread */
454 RegCloseKey(hkExplorer
);