@@ -5380,7 +5380,7 @@ void SaveConfig() {
53805380
53815381 // Window Lock Behaviors
53825382 WritePrivateProfileStringW(L"View", L"KeepWindowSizeOnNav", g_config.KeepWindowSizeOnNav ? L"1" : L"0", iniPath.c_str());
5383- WritePrivateProfileStringW(L"View", L"RememberLastWindowSize ", g_config.RememberLastWindowSize ? L"1" : L"0", iniPath.c_str());
5383+ WritePrivateProfileStringW(L"View", L"RememberLastWindowSizeAndPosition ", g_config.RememberLastWindowSizeAndPosition ? L"1" : L"0", iniPath.c_str());
53845384 WritePrivateProfileStringW(L"View", L"UpscaleSmallImagesWhenLocked", g_config.UpscaleSmallImagesWhenLocked ? L"1" : L"0", iniPath.c_str());
53855385
53865386 WritePrivateProfileStringW(L"View", L"ExifPanelMode", std::to_wstring(g_config.ExifPanelMode).c_str(), iniPath.c_str());
@@ -5604,7 +5604,7 @@ void LoadConfig() {
56045604
56055605 // Window Lock Behaviors
56065606 g_config.KeepWindowSizeOnNav = GetPrivateProfileIntW(L"View", L"KeepWindowSizeOnNav", 0, iniPath.c_str()) != 0;
5607- g_config.RememberLastWindowSize = GetPrivateProfileIntW(L"View", L"RememberLastWindowSize ", 0, iniPath.c_str()) != 0;
5607+ g_config.RememberLastWindowSizeAndPosition = GetPrivateProfileIntW(L"View", L"RememberLastWindowSizeAndPosition ", 0, iniPath.c_str()) != 0;
56085608 g_config.UpscaleSmallImagesWhenLocked = GetPrivateProfileIntW(L"View", L"UpscaleSmallImagesWhenLocked", 0, iniPath.c_str()) != 0;
56095609
56105610 g_config.ExifPanelMode = GetPrivateProfileIntW(L"View", L"ExifPanelMode", 0, iniPath.c_str());
@@ -7043,9 +7043,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdSh
70437043 int screenH = GetSystemMetrics(SM_CYSCREEN);
70447044 int winW = 800;
70457045 int winH = 600;
7046+ int xPos = (screenW - winW) / 2;
7047+ int yPos = (screenH - winH) / 2;
7048+
7049+ bool startFullscreen = false;
7050+ bool startMaximized = false;
70467051
7047- // Load last window size if RememberLastWindowSize is true
7048- if (g_config.RememberLastWindowSize && g_config.LockWindowSize ) {
7052+ // Load last window size and position if RememberLastWindowSizeAndPosition is true
7053+ if (g_config.RememberLastWindowSizeAndPosition ) {
70497054 std::wstring iniPath = GetConfigPath();
70507055 if (g_config.PortableMode) {
70517056 wchar_t exePath[MAX_PATH];
@@ -7055,19 +7060,45 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdSh
70557060 if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
70567061 iniPath = exeDir + L"\\QuickView.ini";
70577062 }
7063+
7064+ startFullscreen = GetPrivateProfileIntW(L"View", L"LastWindowWasFullscreen", 0, iniPath.c_str()) != 0;
7065+ startMaximized = GetPrivateProfileIntW(L"View", L"LastWindowWasMaximized", 0, iniPath.c_str()) != 0;
7066+
70587067 int savedW = GetPrivateProfileIntW(L"View", L"LastWindowW", 0, iniPath.c_str());
70597068 int savedH = GetPrivateProfileIntW(L"View", L"LastWindowH", 0, iniPath.c_str());
7069+ int savedX = GetPrivateProfileIntW(L"View", L"LastWindowX", -10000, iniPath.c_str());
7070+ int savedY = GetPrivateProfileIntW(L"View", L"LastWindowY", -10000, iniPath.c_str());
7071+
70607072 if (savedW > 0 && savedH > 0) {
70617073 winW = savedW;
70627074 winH = savedH;
70637075 }
7064- }
70657076
7066- int xPos = (screenW - winW) / 2;
7067- int yPos = (screenH - winH) / 2;
7077+ if (savedX != -10000 && savedY != -10000) {
7078+ // Basic sanity check to ensure window is on screen
7079+ RECT testRect = { savedX, savedY, savedX + savedW, savedY + savedH };
7080+ HMONITOR hMon = MonitorFromRect(&testRect, MONITOR_DEFAULTTONULL);
7081+ if (hMon != NULL) {
7082+ xPos = savedX;
7083+ yPos = savedY;
7084+ }
7085+ }
7086+ }
70687087
70697088 HWND hwnd = CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP, g_szClassName, g_szWindowTitle, WS_OVERLAPPEDWINDOW, xPos, yPos, winW, winH, nullptr, nullptr, hInstance, nullptr);
70707089 if (!hwnd) return 0;
7090+
7091+ if (g_config.RememberLastWindowSizeAndPosition) {
7092+ if (startMaximized) {
7093+ nCmdShow = SW_MAXIMIZE;
7094+ }
7095+ if (startFullscreen && g_config.OpenFullScreenMode == 0) {
7096+ // We set g_isFullScreen to true. But wait, WM_COMMAND IDM_FULLSCREEN toggles.
7097+ // Let's just post a message to trigger it.
7098+ PostMessage(hwnd, WM_COMMAND, IDM_FULLSCREEN, 0);
7099+ }
7100+ }
7101+
70717102 RefreshWindowDpi(hwnd);
70727103
70737104 // [Phase 0] Start Named Pipe server on Master process.
@@ -7965,20 +7996,30 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
79657996 if (!CheckUnsavedChanges(hwnd)) return 0;
79667997
79677998 // Save Last Window Size
7968- if (g_config.RememberLastWindowSize && g_config.LockWindowSize && !IsZoomed(hwnd) && !IsIconic(hwnd) && !g_isFullScreen) {
7969- RECT rc;
7970- if (GetWindowRect(hwnd, &rc)) {
7971- std::wstring iniPath = GetConfigPath();
7972- if (g_config.PortableMode) {
7973- wchar_t exePath[MAX_PATH];
7974- GetModuleFileNameW(nullptr, exePath, MAX_PATH);
7975- std::wstring exeDir = exePath;
7976- size_t lastSlash = exeDir.find_last_of(L"\\/");
7977- if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
7978- iniPath = exeDir + L"\\QuickView.ini";
7999+ if (g_config.RememberLastWindowSizeAndPosition && !IsIconic(hwnd)) {
8000+ std::wstring iniPath = GetConfigPath();
8001+ if (g_config.PortableMode) {
8002+ wchar_t exePath[MAX_PATH];
8003+ GetModuleFileNameW(nullptr, exePath, MAX_PATH);
8004+ std::wstring exeDir = exePath;
8005+ size_t lastSlash = exeDir.find_last_of(L"\\/");
8006+ if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
8007+ iniPath = exeDir + L"\\QuickView.ini";
8008+ }
8009+
8010+ WritePrivateProfileStringW(L"View", L"LastWindowWasFullscreen", g_isFullScreen ? L"1" : L"0", iniPath.c_str());
8011+ WritePrivateProfileStringW(L"View", L"LastWindowWasMaximized", IsZoomed(hwnd) ? L"1" : L"0", iniPath.c_str());
8012+
8013+ if (!g_isFullScreen) {
8014+ WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
8015+ if (GetWindowPlacement(hwnd, &wp)) {
8016+ int w = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
8017+ int h = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
8018+ WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(w).c_str(), iniPath.c_str());
8019+ WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(h).c_str(), iniPath.c_str());
8020+ WritePrivateProfileStringW(L"View", L"LastWindowX", std::to_wstring(wp.rcNormalPosition.left).c_str(), iniPath.c_str());
8021+ WritePrivateProfileStringW(L"View", L"LastWindowY", std::to_wstring(wp.rcNormalPosition.top).c_str(), iniPath.c_str());
79798022 }
7980- WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(rc.right - rc.left).c_str(), iniPath.c_str());
7981- WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(rc.bottom - rc.top).c_str(), iniPath.c_str());
79828023 }
79838024 }
79848025
0 commit comments