static INT StartWithDesktop(IN HINSTANCE hInstance) { InitializeAtlModule(hInstance, TRUE); if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", &hkExplorer) != ERROR_SUCCESS) { WCHAR Message[256]; LoadStringW(hInstance, IDS_STARTUP_ERROR, Message, _countof(Message)); MessageBox(NULL, Message, NULL, MB_ICONERROR); return 1; } hExplorerInstance = hInstance; hProcessHeap = GetProcessHeap(); g_TaskbarSettings.Load(); InitCommonControls(); OleInitialize(NULL); #if !WIN7_COMPAT_MODE /* Initialize shell dde support */ _ShellDDEInit(TRUE); #endif /* Initialize shell icons */ FileIconInit(TRUE); /* Initialize CLSID_ShellWindows class */ _WinList_Init(); CComPtr<ITrayWindow> Tray; CreateTrayWindow(&Tray); #if !WIN7_DEBUG_MODE /* This not only hides the minimized window captions in the bottom left screen corner, but is also needed in order to receive HSHELL_* notification messages (which are required for taskbar buttons to work right) */ HideMinimizedWindows(TRUE); HANDLE hShellDesktop = NULL; if (Tray != NULL) hShellDesktop = DesktopCreateWindow(Tray); /* WinXP: Notify msgina to hide the welcome screen */ if (!SetShellReadyEvent(L"msgina: ShellReadyEvent")) SetShellReadyEvent(L"Global\\msgina: ShellReadyEvent"); if (DoStartStartupItems(Tray)) { ProcessStartupItems(); DoFinishStartupItems(); } #endif if (Tray != NULL) { TrayMessageLoop(Tray); #if !WIN7_DEBUG_MODE HideMinimizedWindows(FALSE); #endif } #if !WIN7_DEBUG_MODE if (hShellDesktop != NULL) DesktopDestroyShellWindow(hShellDesktop); #endif OleUninitialize(); RegCloseKey(hkExplorer); hkExplorer = NULL; InitializeAtlModule(hInstance, FALSE); return 0; }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { WCHAR szWindowClass[] = L"ROSAPPMGR"; HANDLE hMutex = NULL; HACCEL KeyBrd; MSG Msg; InitializeAtlModule(hInstance, TRUE); switch (GetUserDefaultUILanguage()) { case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT): SetProcessDefaultLayout(LAYOUT_RTL); break; default: break; } hInst = hInstance; hMutex = CreateMutexW(NULL, FALSE, szWindowClass); if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS)) { /* If already started, it is found its window */ HWND hWindow = FindWindowW(szWindowClass, NULL); /* Activate window */ ShowWindow(hWindow, SW_SHOWNORMAL); SetForegroundWindow(hWindow); return 1; } if (!LoadSettings()) { FillDefaultSettings(&SettingsInfo); } InitLogs(); InitCommonControls(); hMainWnd = CreateMainWindow(); if (!hMainWnd) goto Exit; /* Maximize it if we must */ ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd)); UpdateWindow(hMainWnd); if (SettingsInfo.bUpdateAtStart) UpdateAppsDB(); /* Load the menu hotkeys */ KeyBrd = LoadAccelerators(NULL, MAKEINTRESOURCE(HOTKEYS)); /* Message Loop */ while (GetMessage(&Msg, NULL, 0, 0)) { if (!TranslateAccelerator(hMainWnd, KeyBrd, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } Exit: if (hMutex) CloseHandle(hMutex); InitializeAtlModule(hInstance, FALSE); return 0; }