int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int retCode = 1; // by default it's error #ifdef DEBUG // Memory leak detection (only enable _CRTDBG_LEAK_CHECK_DF for // regular termination so that leaks aren't checked on exceptions, // aborts, etc. where some clean-up might not take place) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF); //_CrtSetBreakAlloc(421); TryLoadMemTrace(); #endif //BenchMD5(); DisableDataExecution(); // ensure that C functions behave consistently under all OS locales // (use Win32 functions where localized input or output is desired) setlocale(LC_ALL, "C"); RunUnitTests(); // don't show system-provided dialog boxes when accessing files on drives // that are not mounted (e.g. a: drive without floppy or cd rom drive // without a cd). SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); srand((unsigned int)time(NULL)); // don't bother sending crash reports when running under Wine // as they're not helpful if (!RunningUnderWine()) { ScopedMem<TCHAR> symDir; ScopedMem<TCHAR> tmpDir(path::GetTempPath()); if (tmpDir) symDir.Set(path::Join(tmpDir, _T("SumatraPDF-symbols"))); else symDir.Set(AppGenDataFilename(_T("SumatraPDF-symbols"))); ScopedMem<TCHAR> crashDumpPath(AppGenDataFilename(CRASH_DUMP_FILE_NAME)); InstallCrashHandler(crashDumpPath, symDir); } ScopedOle ole; InitAllCommonControls(); ScopedGdiPlus gdiPlus(true); mui::Initialize(); uimsg::Initialize(); ScopedMem<TCHAR> prefsFilename(GetPrefsFileName()); if (!file::Exists(prefsFilename)) { // guess the ui language on first start CurrLangNameSet(Trans::GuessLanguage()); gFavorites = new Favorites(); } else { assert(gFavorites == NULL); Prefs::Load(prefsFilename, gGlobalPrefs, gFileHistory, &gFavorites); CurrLangNameSet(gGlobalPrefs.currentLanguage); } prefsFilename.Set(NULL); CommandLineInfo i; GetCommandLineInfo(i); if (i.showConsole) RedirectIOToConsole(); if (i.makeDefault) AssociateExeWithPdfExtension(); if (i.pathsToBenchmark.Count() > 0) { BenchFileOrDir(i.pathsToBenchmark); if (i.showConsole) system("pause"); } if (i.exitImmediately) goto Exit; gCrashOnOpen = i.crashOnOpen; gGlobalPrefs.bgColor = i.bgColor; gGlobalPrefs.fwdSearch.offset = i.fwdSearch.offset; gGlobalPrefs.fwdSearch.width = i.fwdSearch.width; gGlobalPrefs.fwdSearch.color = i.fwdSearch.color; gGlobalPrefs.fwdSearch.permanent = i.fwdSearch.permanent; gGlobalPrefs.escToExit = i.escToExit; gGlobalPrefs.cbxR2L = i.cbxR2L; gPolicyRestrictions = GetPolicies(i.restrictedUse); gRenderCache.colorRange[0] = i.colorRange[0]; gRenderCache.colorRange[1] = i.colorRange[1]; DebugGdiPlusDevice(gUseGdiRenderer); DebugAlternateChmEngine(!gUseEbookUI); if (i.inverseSearchCmdLine) { str::ReplacePtr(&gGlobalPrefs.inverseSearchCmdLine, i.inverseSearchCmdLine); gGlobalPrefs.enableTeXEnhancements = true; } CurrLangNameSet(i.lang); if (!RegisterWinClass(hInstance)) goto Exit; if (!InstanceInit(hInstance, nCmdShow)) goto Exit; if (i.hwndPluginParent) { if (!SetupPluginMode(i)) goto Exit; } if (i.printerName) { // note: this prints all PDF files. Another option would be to // print only the first one for (size_t n = 0; n < i.fileNames.Count(); n++) { bool ok = PrintFile(i.fileNames.At(n), i.printerName, !i.silent, i.printSettings); if (!ok) retCode++; } --retCode; // was 1 if no print failures, turn 1 into 0 goto Exit; } if (i.fileNames.Count() == 0 && gGlobalPrefs.rememberOpenedFiles && gGlobalPrefs.showStartPage) { // make the shell prepare the image list, so that it's ready when the first window's loaded SHFILEINFO sfi; SHGetFileInfo(_T(".pdf"), 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); } WindowInfo *win = NULL; bool isFirstWin = true; for (size_t n = 0; n < i.fileNames.Count(); n++) { if (i.reuseInstance && !i.printDialog) { OpenUsingDde(i.fileNames.At(n), i, isFirstWin); } else { win = LoadOnStartup(i.fileNames.At(n), i, isFirstWin); if (!win) { retCode++; continue; } if (i.printDialog) OnMenuPrint(win, i.exitOnPrint); } isFirstWin = false; } if (i.fileNames.Count() > 0 && isFirstWin) { // failed to create any window, even though there // were files to load (or show a failure message for) goto Exit; } if (i.reuseInstance && !i.printDialog || i.printDialog && i.exitOnPrint) goto Exit; if (isFirstWin) { win = CreateAndShowWindowInfo(); if (!win) goto Exit; } UpdateUITextForLanguage(); // needed for RTL languages if (isFirstWin) UpdateToolbarAndScrollbarState(*win); // Make sure that we're still registered as default, // if the user has explicitly told us to be if (gGlobalPrefs.pdfAssociateShouldAssociate && win) RegisterForPdfExtentions(win->hwndFrame); if (gGlobalPrefs.enableAutoUpdate && gWindows.Count() > 0) AutoUpdateCheckAsync(gWindows.At(0)->hwndFrame, true); #ifndef THREAD_BASED_FILEWATCH const UINT_PTR timerID = SetTimer(NULL, -1, FILEWATCH_DELAY_IN_MS, NULL); #endif if (i.stressTestPath) { gIsStressTesting = true; StartStressTest(win, i.stressTestPath, i.stressTestFilter, i.stressTestRanges, i.stressTestCycles, &gRenderCache); } retCode = RunMessageLoop(); #ifndef THREAD_BASED_FILEWATCH KillTimer(NULL, timerID); #endif CleanUpThumbnailCache(gFileHistory); Exit: while (gWindows.Count() > 0) { DeleteWindowInfo(gWindows.At(0)); } while (gEbookWindows.Count() > 0) { DeleteEbookWindow(gEbookWindows.At(0), true); } #ifndef DEBUG // leave all the remaining clean-up to the OS // (as recommended for a quick exit) ExitProcess(retCode); #endif DeleteObject(gBrushNoDocBg); DeleteObject(gBrushLogoBg); DeleteObject(gBrushAboutBg); DeleteObject(gDefaultGuiFont); DeleteBitmap(gBitmapReloadingCue); delete gFavorites; mui::Destroy(); DrainUiMsgQueue(); uimsg::Destroy(); // it's still possible to crash after this (destructors of static classes, // atexit() code etc.) point, but it's very unlikely if (!RunningUnderWine()) UninstallCrashHandler(); #ifdef DEBUG // output leaks after all destructors of static objects have run _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif return retCode; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int retCode = 1; // by default it's error #ifdef DEBUG // Memory leak detection (only enable _CRTDBG_LEAK_CHECK_DF for // regular termination so that leaks aren't checked on exceptions, // aborts, etc. where some clean-up might not take place) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF); //_CrtSetBreakAlloc(421); TryLoadMemTrace(); #endif DisableDataExecution(); // ensure that C functions behave consistently under all OS locales // (use Win32 functions where localized input or output is desired) setlocale(LC_ALL, "C"); // don't show system-provided dialog boxes when accessing files on drives // that are not mounted (e.g. a: drive without floppy or cd rom drive // without a cd). SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); #if defined(DEBUG) || defined(SVN_PRE_RELEASE_VER) if (str::StartsWith(lpCmdLine, "/tester")) { extern int TesterMain(); // in Tester.cpp return TesterMain(); } if (str::StartsWith(lpCmdLine, "/regress")) { extern int RegressMain(); // in Regress.cpp return RegressMain(); } #endif #ifdef SUPPORTS_AUTO_UPDATE if (str::StartsWith(lpCmdLine, "-autoupdate")) { bool quit = AutoUpdateMain(); if (quit) return 0; } #endif srand((unsigned int)time(NULL)); // load uiautomationcore.dll before installing crash handler (i.e. initializing // dbghelp.dll), so that we get function names/offsets in GetCallstack() uia::Initialize(); #ifdef DEBUG dbghelp::RememberCallstackLogs(); #endif SetupCrashHandler(); ScopedOle ole; InitAllCommonControls(); ScopedGdiPlus gdiPlus(true); mui::Initialize(); uitask::Initialize(); prefs::Load(); CommandLineInfo i(GetCommandLine()); SetCurrentLang(i.lang ? i.lang : gGlobalPrefs->uiLanguage); // This allows ad-hoc comparison of gdi, gdi+ and gdi+ quick when used // in layout #if 0 RedirectIOToConsole(); BenchEbookLayout(L"C:\\kjk\\downloads\\pg12.mobi"); system("pause"); goto Exit; #endif if (i.showConsole) { RedirectIOToConsole(); RedirectDllIOToConsole(); } if (i.makeDefault) AssociateExeWithPdfExtension(); if (i.pathsToBenchmark.Count() > 0) { BenchFileOrDir(i.pathsToBenchmark); if (i.showConsole) system("pause"); } if (i.exitImmediately) goto Exit; gCrashOnOpen = i.crashOnOpen; gPolicyRestrictions = GetPolicies(i.restrictedUse); GetFixedPageUiColors(gRenderCache.textColor, gRenderCache.backgroundColor); DebugGdiPlusDevice(gUseGdiRenderer); if (!RegisterWinClass()) goto Exit; CrashIf(hInstance != GetModuleHandle(NULL)); if (!InstanceInit(nCmdShow)) goto Exit; if (i.hwndPluginParent) { if (!SetupPluginMode(i)) goto Exit; } if (i.printerName) { // note: this prints all PDF files. Another option would be to // print only the first one for (size_t n = 0; n < i.fileNames.Count(); n++) { bool ok = PrintFile(i.fileNames.At(n), i.printerName, !i.silent, i.printSettings); if (!ok) retCode++; } --retCode; // was 1 if no print failures, turn 1 into 0 goto Exit; } bool showStartPage = i.fileNames.Count() == 0 && gGlobalPrefs->rememberOpenedFiles && gGlobalPrefs->showStartPage; if (showStartPage) { // make the shell prepare the image list, so that it's ready when the first window's loaded SHFILEINFO sfi; SHGetFileInfo(L".pdf", 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); } if (gGlobalPrefs->reopenOnce) { WStrVec moreFileNames; ParseCmdLine(gGlobalPrefs->reopenOnce, moreFileNames); moreFileNames.Reverse(); for (WCHAR **fileName = moreFileNames.IterStart(); fileName; fileName = moreFileNames.IterNext()) { i.fileNames.Append(*fileName); } moreFileNames.RemoveAt(0, moreFileNames.Count()); str::ReplacePtr(&gGlobalPrefs->reopenOnce, NULL); } HANDLE hMutex = NULL; HWND hPrevWnd = NULL; if (i.printDialog || i.stressTestPath || gPluginMode) { // TODO: pass print request through to previous instance? } else if (i.reuseDdeInstance) { hPrevWnd = FindWindow(FRAME_CLASS_NAME, NULL); } else if (gGlobalPrefs->reuseInstance || gGlobalPrefs->useTabs) { hPrevWnd = FindPrevInstWindow(&hMutex); } if (hPrevWnd) { for (size_t n = 0; n < i.fileNames.Count(); n++) { OpenUsingDde(hPrevWnd, i.fileNames.At(n), i, 0 == n); } goto Exit; } WindowInfo *win = NULL; for (size_t n = 0; n < i.fileNames.Count(); n++) { win = LoadOnStartup(i.fileNames.At(n), i, !win); if (!win) { retCode++; continue; } if (i.printDialog) OnMenuPrint(win, i.exitWhenDone); } if (i.fileNames.Count() > 0 && !win) { // failed to create any window, even though there // were files to load (or show a failure message for) goto Exit; } if (i.printDialog && i.exitWhenDone) goto Exit; if (!win) { win = CreateAndShowWindowInfo(); if (!win) goto Exit; } UpdateUITextForLanguage(); // needed for RTL languages if (win->IsAboutWindow()) { // TODO: shouldn't CreateAndShowWindowInfo take care of this? UpdateToolbarAndScrollbarState(*win); } // Make sure that we're still registered as default, // if the user has explicitly told us to be if (gGlobalPrefs->associatedExtensions) RegisterForPdfExtentions(win->hwndFrame); if (i.stressTestPath) { // don't save file history and preference changes gPolicyRestrictions = (gPolicyRestrictions | Perm_RestrictedUse) & ~Perm_SavePreferences; RebuildMenuBarForWindow(win); StartStressTest(&i, win, &gRenderCache); } if (gGlobalPrefs->checkForUpdates) UpdateCheckAsync(win, true); // only hide newly missing files when showing the start page on startup if (showStartPage && gFileHistory.Get(0)) { gFileExistenceChecker = new FileExistenceChecker(); gFileExistenceChecker->Start(); } // call this once it's clear whether Perm_SavePreferences has been granted prefs::RegisterForFileChanges(); retCode = RunMessageLoop(); SafeCloseHandle(&hMutex); CleanUpThumbnailCache(gFileHistory); Exit: prefs::UnregisterForFileChanges(); while (gWindows.Count() > 0) { DeleteWindowInfo(gWindows.At(0)); } #ifndef DEBUG // leave all the remaining clean-up to the OS // (as recommended for a quick exit) ExitProcess(retCode); #else DeleteObject(GetDefaultGuiFont()); DeleteBitmap(gBitmapReloadingCue); DeleteSplitterBrush(); // wait for FileExistenceChecker to terminate // (which should be necessary only very rarely) while (gFileExistenceChecker) { Sleep(10); uitask::DrainQueue(); } mui::Destroy(); uitask::Destroy(); trans::Destroy(); SaveCallstackLogs(); dbghelp::FreeCallstackLogs(); // must be after uitask::Destroy() because we might have queued prefs::Reload() // which crashes if gGlobalPrefs is freed gFileHistory.UpdateStatesSource(NULL); DeleteGlobalPrefs(gGlobalPrefs); // it's still possible to crash after this (destructors of static classes, // atexit() code etc.) point, but it's very unlikely UninstallCrashHandler(); // output leaks after all destructors of static objects have run _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); return retCode; #endif }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int retCode = 1; // by default it's error #ifdef DEBUG // Memory leak detection (only enable _CRTDBG_LEAK_CHECK_DF for // regular termination so that leaks aren't checked on exceptions, // aborts, etc. where some clean-up might not take place) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF); //_CrtSetBreakAlloc(421); TryLoadMemTrace(); #endif DisableDataExecution(); // ensure that C functions behave consistently under all OS locales // (use Win32 functions where localized input or output is desired) setlocale(LC_ALL, "C"); // don't show system-provided dialog boxes when accessing files on drives // that are not mounted (e.g. a: drive without floppy or cd rom drive // without a cd). SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); #if defined(DEBUG) || defined(SVN_PRE_RELEASE_VER) if (str::StartsWith(lpCmdLine, "/tester")) { extern int TesterMain(); // in Tester.cpp return TesterMain(); } if (str::StartsWith(lpCmdLine, "/regress")) { extern int RegressMain(); // in Regress.cpp return RegressMain(); } #endif #ifdef SUPPORTS_AUTO_UPDATE if (str::StartsWith(lpCmdLine, "-autoupdate")) { bool quit = AutoUpdateMain(); if (quit) return 0; } #endif RunUnitTests(); srand((unsigned int)time(NULL)); { ScopedMem<WCHAR> symDir; ScopedMem<WCHAR> tmpDir(path::GetTempPath()); if (tmpDir) symDir.Set(path::Join(tmpDir, L"SumatraPDF-symbols")); else symDir.Set(AppGenDataFilename(L"SumatraPDF-symbols")); ScopedMem<WCHAR> crashDumpPath(AppGenDataFilename(CRASH_DUMP_FILE_NAME)); InstallCrashHandler(crashDumpPath, symDir); } ScopedOle ole; InitAllCommonControls(); ScopedGdiPlus gdiPlus(true); mui::Initialize(); uitask::Initialize(); LoadPrefs(); CommandLineInfo i; GetCommandLineInfo(i); SetCurrentLang(i.lang ? i.lang : gGlobalPrefs->currLangCode); if (i.showConsole) RedirectIOToConsole(); if (i.makeDefault) AssociateExeWithPdfExtension(); if (i.pathsToBenchmark.Count() > 0) { BenchFileOrDir(i.pathsToBenchmark); if (i.showConsole) system("pause"); } if (i.exitImmediately) goto Exit; gCrashOnOpen = i.crashOnOpen; gUserPrefs->mainWindowBackground = i.bgColor; if (gUserPrefs->forwardSearch.highlightColor != i.forwardSearch.highlightColor || gUserPrefs->forwardSearch.highlightOffset != i.forwardSearch.highlightOffset || gUserPrefs->forwardSearch.highlightPermanent != i.forwardSearch.highlightPermanent || gUserPrefs->forwardSearch.highlightWidth != i.forwardSearch.highlightWidth) { gGlobalPrefs->enableTeXEnhancements = true; } gUserPrefs->forwardSearch = i.forwardSearch; gUserPrefs->escToExit = i.escToExit; gGlobalPrefs->cbxR2L = i.cbxR2L; gPolicyRestrictions = GetPolicies(i.restrictedUse); gRenderCache.colorRange[0] = i.colorRange[0]; gRenderCache.colorRange[1] = i.colorRange[1]; DebugGdiPlusDevice(gUseGdiRenderer); DebugAlternateChmEngine(gUserPrefs->ebookUI.traditionalEbookUI); if (i.inverseSearchCmdLine) { str::ReplacePtr(&gGlobalPrefs->inverseSearchCmdLine, i.inverseSearchCmdLine); gGlobalPrefs->enableTeXEnhancements = true; } if (!RegisterWinClass(hInstance)) goto Exit; if (!InstanceInit(hInstance, nCmdShow)) goto Exit; if (i.hwndPluginParent) { if (!SetupPluginMode(i)) goto Exit; } if (i.printerName) { // note: this prints all PDF files. Another option would be to // print only the first one for (size_t n = 0; n < i.fileNames.Count(); n++) { bool ok = PrintFile(i.fileNames.At(n), i.printerName, !i.silent, i.printSettings); if (!ok) retCode++; } --retCode; // was 1 if no print failures, turn 1 into 0 goto Exit; } if (i.fileNames.Count() == 0 && gGlobalPrefs->rememberOpenedFiles && gGlobalPrefs->showStartPage) { // make the shell prepare the image list, so that it's ready when the first window's loaded SHFILEINFO sfi; SHGetFileInfo(L".pdf", 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); } if (!i.reuseInstance && gUserPrefs->reuseInstance && FindWindow(FRAME_CLASS_NAME, 0)) i.reuseInstance = true; WindowInfo *win = NULL; bool isFirstWin = true; for (size_t n = 0; n < i.fileNames.Count(); n++) { if (i.reuseInstance && !i.printDialog) { OpenUsingDde(i.fileNames.At(n), i, isFirstWin); } else { win = LoadOnStartup(i.fileNames.At(n), i, isFirstWin); if (!win) { retCode++; continue; } if (i.printDialog) OnMenuPrint(win, i.exitWhenDone); } isFirstWin = false; } if (i.fileNames.Count() > 0 && isFirstWin) { // failed to create any window, even though there // were files to load (or show a failure message for) goto Exit; } if (i.reuseInstance && !i.printDialog || i.printDialog && i.exitWhenDone) goto Exit; if (isFirstWin) { win = CreateAndShowWindowInfo(); if (!win) goto Exit; } UpdateUITextForLanguage(); // needed for RTL languages if (isFirstWin) UpdateToolbarAndScrollbarState(*win); // Make sure that we're still registered as default, // if the user has explicitly told us to be if (gGlobalPrefs->pdfAssociateShouldAssociate && win) RegisterForPdfExtentions(win->hwndFrame); if (gGlobalPrefs->enableAutoUpdate && gWindows.Count() > 0) AutoUpdateCheckAsync(gWindows.At(0)->hwndFrame, true); if (i.stressTestPath) StartStressTest(&i, win, &gRenderCache); if (gFileHistory.Get(0)) { gFileExistenceChecker = new FileExistenceChecker(); gFileExistenceChecker->Start(); } retCode = RunMessageLoop(); CleanUpThumbnailCache(gFileHistory); Exit: while (gWindows.Count() > 0) { DeleteWindowInfo(gWindows.At(0)); } while (gEbookWindows.Count() > 0) { DeleteEbookWindow(gEbookWindows.At(0), true); } #ifndef DEBUG // leave all the remaining clean-up to the OS // (as recommended for a quick exit) ExitProcess(retCode); #else CrashIf(gFileExistenceChecker); DeleteObject(gBrushNoDocBg); DeleteObject(gBrushLogoBg); DeleteObject(gBrushAboutBg); DeleteObject(gDefaultGuiFont); DeleteBitmap(gBitmapReloadingCue); gFileHistory.UpdateStatesSource(NULL); DeleteGlobalPrefs(gGlobalPrefs); mui::Destroy(); uitask::Destroy(); trans::Destroy(); // it's still possible to crash after this (destructors of static classes, // atexit() code etc.) point, but it's very unlikely UninstallCrashHandler(); // output leaks after all destructors of static objects have run _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); return retCode; #endif }
static INT_PTR CALLBACK Dialog_Settings_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { GlobalPrefs *prefs; switch (msg) { case WM_INITDIALOG: prefs = (GlobalPrefs *)lParam; assert(prefs); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)prefs); // Fill the page layouts into the select box SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Automatic")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Single Page")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Facing")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Book View")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous Facing")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous Book View")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_SETCURSEL, prefs->defaultDisplayModeEnum - DM_FIRST, 0); SetupZoomComboBox(hDlg, IDC_DEFAULT_ZOOM, false, prefs->defaultZoomFloat); CheckDlgButton(hDlg, IDC_DEFAULT_SHOW_TOC, prefs->showToc ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT, prefs->rememberStatePerDocument ? BST_CHECKED : BST_UNCHECKED); EnableWindow(GetDlgItem(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT), prefs->rememberOpenedFiles); CheckDlgButton(hDlg, IDC_USE_SYS_COLORS, prefs->useSysColors ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CHECK_FOR_UPDATES, prefs->checkForUpdates ? BST_CHECKED : BST_UNCHECKED); EnableWindow(GetDlgItem(hDlg, IDC_CHECK_FOR_UPDATES), HasPermission(Perm_InternetAccess)); CheckDlgButton(hDlg, IDC_REMEMBER_OPENED_FILES, prefs->rememberOpenedFiles ? BST_CHECKED : BST_UNCHECKED); if (IsExeAssociatedWithPdfExtension()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF is your default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); } else if (IsRunningInPortableMode()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("Default PDF reader can't be changed in portable mode")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); } else { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("Make SumatraPDF my default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), HasPermission(Perm_RegistryAccess)); } win::SetText(hDlg, _TR("SumatraPDF Options")); SetDlgItemText(hDlg, IDC_SECTION_VIEW, _TR("View")); SetDlgItemText(hDlg, IDC_DEFAULT_LAYOUT_LABEL, _TR("Default &Layout:")); SetDlgItemText(hDlg, IDC_DEFAULT_ZOOM_LABEL, _TR("Default &Zoom:")); SetDlgItemText(hDlg, IDC_DEFAULT_SHOW_TOC, _TR("Show the &bookmarks sidebar when available")); SetDlgItemText(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT, _TR("&Remember these settings for each document")); SetDlgItemText(hDlg, IDC_USE_SYS_COLORS, _TR("Replace document &colors with Windows color scheme")); SetDlgItemText(hDlg, IDC_SECTION_ADVANCED, _TR("Advanced")); SetDlgItemText(hDlg, IDC_CHECK_FOR_UPDATES, _TR("Automatically check for &updates")); SetDlgItemText(hDlg, IDC_REMEMBER_OPENED_FILES, _TR("Remember &opened files")); SetDlgItemText(hDlg, IDC_SECTION_INVERSESEARCH, _TR("Set inverse search command-line")); SetDlgItemText(hDlg, IDC_CMDLINE_LABEL, _TR("Enter the command-line to invoke when you double-click on the PDF document:")); SetDlgItemText(hDlg, IDOK, _TR("OK")); SetDlgItemText(hDlg, IDCANCEL, _TR("Cancel")); if (GetSysColor(COLOR_WINDOWTEXT) == RGB(0, 0, 0) && GetSysColor(COLOR_WINDOW) == RGB(0xFF, 0xFF, 0xFF)) { // remove the "use system colors" item if it wouldn't change anything RemoveDialogItem(hDlg, IDC_USE_SYS_COLORS); } if (prefs->enableTeXEnhancements && HasPermission(Perm_DiskAccess)) { // Fill the combo with the list of possible inverse search commands // Try to select a correct default when first showing this dialog const WCHAR *cmdLine = prefs->inverseSearchCmdLine; ScopedMem<WCHAR> inverseSearch; if (!cmdLine) { inverseSearch.Set(AutoDetectInverseSearchCommands(GetDlgItem(hDlg, IDC_CMDLINE))); cmdLine = inverseSearch; } // Find the index of the active command line LRESULT ind = SendMessage(GetDlgItem(hDlg, IDC_CMDLINE), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM) cmdLine); if (CB_ERR == ind) { // if no existing command was selected then set the user custom command in the combo ComboBox_AddItemData(GetDlgItem(hDlg, IDC_CMDLINE), cmdLine); SetDlgItemText(hDlg, IDC_CMDLINE, cmdLine); } else { // select the active command SendMessage(GetDlgItem(hDlg, IDC_CMDLINE), CB_SETCURSEL, (WPARAM) ind , 0); } } else { RemoveDialogItem(hDlg, IDC_SECTION_INVERSESEARCH, IDC_SECTION_ADVANCED); } CenterDialog(hDlg); SetFocus(GetDlgItem(hDlg, IDC_DEFAULT_LAYOUT)); return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: prefs = (GlobalPrefs *)GetWindowLongPtr(hDlg, GWLP_USERDATA); assert(prefs); prefs->defaultDisplayModeEnum = (DisplayMode)(SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_GETCURSEL, 0, 0) + DM_FIRST); prefs->defaultZoomFloat = GetZoomComboBoxValue(hDlg, IDC_DEFAULT_ZOOM, false, prefs->defaultZoomFloat); prefs->showToc = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DEFAULT_SHOW_TOC)); prefs->rememberStatePerDocument = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT)); prefs->useSysColors = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_USE_SYS_COLORS)); prefs->checkForUpdates = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CHECK_FOR_UPDATES)); prefs->rememberOpenedFiles = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_OPENED_FILES)); if (prefs->enableTeXEnhancements && HasPermission(Perm_DiskAccess)) { free(prefs->inverseSearchCmdLine); prefs->inverseSearchCmdLine = win::GetText(GetDlgItem(hDlg, IDC_CMDLINE)); } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_REMEMBER_OPENED_FILES: { bool rememberOpenedFiles = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_OPENED_FILES)); EnableWindow(GetDlgItem(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT), rememberOpenedFiles); } return TRUE; case IDC_DEFAULT_SHOW_TOC: case IDC_REMEMBER_STATE_PER_DOCUMENT: case IDC_CHECK_FOR_UPDATES: return TRUE; case IDC_SET_DEFAULT_READER: if (!HasPermission(Perm_RegistryAccess)) return TRUE; AssociateExeWithPdfExtension(); if (IsExeAssociatedWithPdfExtension()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF is your default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE); } else { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF should now be your default PDF reader")); } return TRUE; } break; } return FALSE; }