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 DEFINE_GUID(CLSID_RebarBandSite
, 0xECD4FC4D, 0x521C, 0x11D0, 0xB7, 0x92, 0x00, 0xA0, 0xC9, 0x03, 0x12, 0xE1);
39 SetWindowStyle(IN HWND hWnd
,
43 LONG PrevStyle
, Style
;
45 ASSERT((~dwStyleMask
& dwStyle
) == 0);
47 PrevStyle
= GetWindowLongPtr(hWnd
,
50 (PrevStyle
& dwStyleMask
) != dwStyle
)
52 Style
= PrevStyle
& ~dwStyleMask
;
55 PrevStyle
= SetWindowLongPtr(hWnd
,
64 SetWindowExStyle(IN HWND hWnd
,
68 LONG PrevStyle
, Style
;
70 ASSERT((~dwStyleMask
& dwStyle
) == 0);
72 PrevStyle
= GetWindowLongPtr(hWnd
,
75 (PrevStyle
& dwStyleMask
) != dwStyle
)
77 Style
= PrevStyle
& ~dwStyleMask
;
80 PrevStyle
= SetWindowLongPtr(hWnd
,
89 LoadPopupMenu(IN HINSTANCE hInstance
,
90 IN LPCTSTR lpMenuName
)
92 HMENU hMenu
, hSubMenu
= NULL
;
94 hMenu
= LoadMenu(hInstance
,
99 hSubMenu
= GetSubMenu(hMenu
,
101 if (hSubMenu
!= NULL
&&
116 FindSubMenu(IN HMENU hMenu
,
122 mii
.cbSize
= sizeof(mii
);
123 mii
.fMask
= MIIM_SUBMENU
;
125 if (GetMenuItemInfo(hMenu
,
137 GetCurrentLoggedOnUserName(OUT LPTSTR szBuffer
,
138 IN DWORD dwBufferSize
)
143 /* Query the user name from the registry */
144 dwSize
= (dwBufferSize
* sizeof(TCHAR
)) - 1;
145 if (RegQueryValueEx(hkExplorer
,
146 TEXT("Logon User Name"),
150 &dwSize
) == ERROR_SUCCESS
&&
151 (dwSize
/ sizeof(TCHAR
)) > 1 &&
152 szBuffer
[0] != _T('\0'))
154 szBuffer
[dwSize
/ sizeof(TCHAR
)] = _T('\0');
158 /* Fall back to GetUserName() */
159 dwSize
= dwBufferSize
;
160 if (!GetUserName(szBuffer
,
163 szBuffer
[0] = _T('\0');
171 FormatMenuString(IN HMENU hMenu
,
181 /* Find the menu item and read the formatting string */
182 mii
.cbSize
= sizeof(mii
);
183 mii
.fMask
= MIIM_STRING
;
184 mii
.dwTypeData
= (LPTSTR
)szBufFmt
;
185 mii
.cch
= sizeof(szBufFmt
) / sizeof(szBufFmt
[0]);
186 if (GetMenuItemInfo(hMenu
,
191 /* Format the string */
192 va_start(vl
, uFlags
);
194 (sizeof(szBuf
) / sizeof(szBuf
[0])) - 1,
198 szBuf
[(sizeof(szBuf
) / sizeof(szBuf
[0])) - 1] = _T('\0');
200 /* Update the menu item */
201 mii
.dwTypeData
= (LPTSTR
)szBuf
;
202 if (SetMenuItemInfo(hMenu
,
215 GetExplorerRegValueSet(IN HKEY hKey
,
219 TCHAR szBuffer
[MAX_PATH
];
221 DWORD dwType
, dwSize
;
225 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"));
231 dwSize
= sizeof(szBuffer
);
232 if (RegOpenKeyEx(hKey
,
236 &hkSubKey
) == ERROR_SUCCESS
)
241 if (RegQueryValueEx(hkSubKey
,
246 &dwSize
) == ERROR_SUCCESS
)
248 if (dwType
== REG_DWORD
&& dwSize
== sizeof(DWORD
))
249 Ret
= *((PDWORD
)szBuffer
) != 0;
251 Ret
= *((PUCHAR
)szBuffer
) != 0;
254 RegCloseKey(hkSubKey
);
261 SetShellReadyEvent(IN LPCTSTR lpEventName
)
265 hEvent
= OpenEvent(EVENT_MODIFY_STATE
,
280 GetVersionInfoString(IN TCHAR
*szFileName
,
281 IN TCHAR
*szVersionInfo
,
285 LPVOID lpData
= NULL
;
286 TCHAR szSubBlock
[128];
287 TCHAR
*lpszLocalBuf
= NULL
;
289 PLANGCODEPAGE lpTranslate
= NULL
;
297 dwLen
= GetFileVersionInfoSize(szFileName
,&dwHandle
);
301 lpData
= HeapAlloc(hProcessHeap
,0,dwLen
);
305 if (GetFileVersionInfo(szFileName
,
310 UserLangId
= GetUserDefaultLangID();
312 VerQueryValue(lpData
,
313 TEXT("\\VarFileInfo\\Translation"),
314 (LPVOID
*)&lpTranslate
,
317 for (i
= 0;i
< (cbTranslate
/ sizeof(LANGCODEPAGE
));i
++)
319 /* If the bottom eight bits of the language id's
320 match, use this version information (since this
321 means that the version information and the users
322 default language are the same). */
323 if ((lpTranslate
[i
].wLanguage
& 0xFF) ==
326 wnsprintf(szSubBlock
,
327 sizeof(szSubBlock
) / sizeof(szSubBlock
[0]),
328 TEXT("\\StringFileInfo\\%04X%04X\\%s"),
329 lpTranslate
[i
].wLanguage
,
330 lpTranslate
[i
].wCodePage
,szVersionInfo
);
332 if (VerQueryValue(lpData
,
334 (LPVOID
*)&lpszLocalBuf
,
337 wcsncpy(szBuffer
,lpszLocalBuf
,cbBufLen
);
345 HeapFree(hProcessHeap
,0,lpData
);
354 _tWinMain(IN HINSTANCE hInstance
,
355 IN HINSTANCE hPrevInstance
,
359 ITrayWindow
*Tray
= NULL
;
360 HANDLE hShellDesktop
= NULL
;
361 BOOL CreateShellDesktop
= FALSE
;
363 if (RegOpenKey(HKEY_CURRENT_USER
,
364 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"),
365 &hkExplorer
) != ERROR_SUCCESS
)
368 LoadString(hInstance
, IDS_STARTUP_ERROR
, Message
, 256);
369 MessageBox(NULL
, Message
, NULL
, MB_ICONERROR
);
373 hExplorerInstance
= hInstance
;
374 hProcessHeap
= GetProcessHeap();
376 hUser32
= GetModuleHandle(TEXT("USER32.DLL"));
379 DrawCapTemp
= (DRAWCAPTEMP
)GetProcAddress(hUser32
,
380 PROC_NAME_DRAWCAPTIONTEMP
);
383 InitCommonControls();
386 if (GetShellWindow() == NULL
)
387 CreateShellDesktop
= TRUE
;
389 /* FIXME - initialize SSO Thread */
391 if (CreateShellDesktop
)
393 if (RegisterTrayWindowClass() && RegisterTaskSwitchWndClass())
395 Tray
= CreateTrayWindow();
398 hShellDesktop
= DesktopCreateWindow(Tray
);
401 /* WinXP: Notify msgina to hide the welcome screen */
402 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
403 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
407 /* A shell is already loaded. Parse the command line arguments
408 and unless we need to do something specific simply display
409 the desktop in a separate explorer window */
414 TrayMessageLoop(Tray
);
416 if (hShellDesktop
!= NULL
)
417 DesktopDestroyShellWindow(hShellDesktop
);
419 /* FIXME - shutdown SSO Thread */
423 RegCloseKey(hkExplorer
);