@@ -5383,7 +5383,7 @@ void SaveConfig() {
53835383
53845384 // Window Lock Behaviors
53855385 WritePrivateProfileStringW(L"View", L"KeepWindowSizeOnNav", g_config.KeepWindowSizeOnNav ? L"1" : L"0", iniPath.c_str());
5386- WritePrivateProfileStringW(L"View", L"RememberLastWindowSize ", g_config.RememberLastWindowSize ? L"1" : L"0", iniPath.c_str());
5386+ WritePrivateProfileStringW(L"View", L"RememberLastWindowSizeAndPosition ", g_config.RememberLastWindowSizeAndPosition ? L"1" : L"0", iniPath.c_str());
53875387 WritePrivateProfileStringW(L"View", L"UpscaleSmallImagesWhenLocked", g_config.UpscaleSmallImagesWhenLocked ? L"1" : L"0", iniPath.c_str());
53885388
53895389 WritePrivateProfileStringW(L"View", L"ExifPanelMode", std::to_wstring(g_config.ExifPanelMode).c_str(), iniPath.c_str());
@@ -5607,7 +5607,7 @@ void LoadConfig() {
56075607
56085608 // Window Lock Behaviors
56095609 g_config.KeepWindowSizeOnNav = GetPrivateProfileIntW(L"View", L"KeepWindowSizeOnNav", 0, iniPath.c_str()) != 0;
5610- g_config.RememberLastWindowSize = GetPrivateProfileIntW(L"View", L"RememberLastWindowSize ", 0, iniPath.c_str()) != 0;
5610+ g_config.RememberLastWindowSizeAndPosition = GetPrivateProfileIntW(L"View", L"RememberLastWindowSizeAndPosition ", 0, iniPath.c_str()) != 0;
56115611 g_config.UpscaleSmallImagesWhenLocked = GetPrivateProfileIntW(L"View", L"UpscaleSmallImagesWhenLocked", 0, iniPath.c_str()) != 0;
56125612
56135613 g_config.ExifPanelMode = GetPrivateProfileIntW(L"View", L"ExifPanelMode", 0, iniPath.c_str());
@@ -7046,9 +7046,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, [[maybe_unused]] LPWSTR lpCm
70467046 int screenH = GetSystemMetrics(SM_CYSCREEN);
70477047 int winW = 800;
70487048 int winH = 600;
7049+ int xPos = (screenW - winW) / 2;
7050+ int yPos = (screenH - winH) / 2;
7051+
7052+ bool startFullscreen = false;
7053+ bool startMaximized = false;
70497054
7050- // Load last window size if RememberLastWindowSize is true
7051- if (g_config.RememberLastWindowSize && g_config.LockWindowSize ) {
7055+ // Load last window size and position if RememberLastWindowSizeAndPosition is true
7056+ if (g_config.RememberLastWindowSizeAndPosition ) {
70527057 std::wstring iniPath = GetConfigPath();
70537058 if (g_config.PortableMode) {
70547059 wchar_t exePath[MAX_PATH];
@@ -7058,19 +7063,45 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, [[maybe_unused]] LPWSTR lpCm
70587063 if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
70597064 iniPath = exeDir + L"\\QuickView.ini";
70607065 }
7066+
7067+ startFullscreen = GetPrivateProfileIntW(L"View", L"LastWindowWasFullscreen", 0, iniPath.c_str()) != 0;
7068+ startMaximized = GetPrivateProfileIntW(L"View", L"LastWindowWasMaximized", 0, iniPath.c_str()) != 0;
7069+
70617070 int savedW = GetPrivateProfileIntW(L"View", L"LastWindowW", 0, iniPath.c_str());
70627071 int savedH = GetPrivateProfileIntW(L"View", L"LastWindowH", 0, iniPath.c_str());
7072+ int savedX = GetPrivateProfileIntW(L"View", L"LastWindowX", -10000, iniPath.c_str());
7073+ int savedY = GetPrivateProfileIntW(L"View", L"LastWindowY", -10000, iniPath.c_str());
7074+
70637075 if (savedW > 0 && savedH > 0) {
70647076 winW = savedW;
70657077 winH = savedH;
70667078 }
7067- }
70687079
7069- int xPos = (screenW - winW) / 2;
7070- int yPos = (screenH - winH) / 2;
7080+ if (savedX != -10000 && savedY != -10000) {
7081+ // Basic sanity check to ensure window is on screen
7082+ RECT testRect = { savedX, savedY, savedX + savedW, savedY + savedH };
7083+ HMONITOR hMon = MonitorFromRect(&testRect, MONITOR_DEFAULTTONULL);
7084+ if (hMon != NULL) {
7085+ xPos = savedX;
7086+ yPos = savedY;
7087+ }
7088+ }
7089+ }
70717090
70727091 HWND hwnd = CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP, g_szClassName, g_szWindowTitle, WS_OVERLAPPEDWINDOW, xPos, yPos, winW, winH, nullptr, nullptr, hInstance, nullptr);
70737092 if (!hwnd) return 0;
7093+
7094+ if (g_config.RememberLastWindowSizeAndPosition) {
7095+ if (startMaximized) {
7096+ nCmdShow = SW_MAXIMIZE;
7097+ }
7098+ if (startFullscreen && g_config.OpenFullScreenMode == 0) {
7099+ // We set g_isFullScreen to true. But wait, WM_COMMAND IDM_FULLSCREEN toggles.
7100+ // Let's just post a message to trigger it.
7101+ PostMessage(hwnd, WM_COMMAND, IDM_FULLSCREEN, 0);
7102+ }
7103+ }
7104+
70747105 RefreshWindowDpi(hwnd);
70757106
70767107 // [Phase 0] Start Named Pipe server on Master process.
@@ -7968,20 +7999,30 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
79687999 if (!CheckUnsavedChanges(hwnd)) return 0;
79698000
79708001 // Save Last Window Size
7971- if (g_config.RememberLastWindowSize && g_config.LockWindowSize && !IsZoomed(hwnd) && !IsIconic(hwnd) && !g_isFullScreen) {
7972- RECT rc;
7973- if (GetWindowRect(hwnd, &rc)) {
7974- std::wstring iniPath = GetConfigPath();
7975- if (g_config.PortableMode) {
7976- wchar_t exePath[MAX_PATH];
7977- GetModuleFileNameW(nullptr, exePath, MAX_PATH);
7978- std::wstring exeDir = exePath;
7979- size_t lastSlash = exeDir.find_last_of(L"\\/");
7980- if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
7981- iniPath = exeDir + L"\\QuickView.ini";
8002+ if (g_config.RememberLastWindowSizeAndPosition && !IsIconic(hwnd)) {
8003+ std::wstring iniPath = GetConfigPath();
8004+ if (g_config.PortableMode) {
8005+ wchar_t exePath[MAX_PATH];
8006+ GetModuleFileNameW(nullptr, exePath, MAX_PATH);
8007+ std::wstring exeDir = exePath;
8008+ size_t lastSlash = exeDir.find_last_of(L"\\/");
8009+ if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
8010+ iniPath = exeDir + L"\\QuickView.ini";
8011+ }
8012+
8013+ WritePrivateProfileStringW(L"View", L"LastWindowWasFullscreen", g_isFullScreen ? L"1" : L"0", iniPath.c_str());
8014+ WritePrivateProfileStringW(L"View", L"LastWindowWasMaximized", IsZoomed(hwnd) ? L"1" : L"0", iniPath.c_str());
8015+
8016+ if (!g_isFullScreen) {
8017+ WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
8018+ if (GetWindowPlacement(hwnd, &wp)) {
8019+ int w = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
8020+ int h = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
8021+ WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(w).c_str(), iniPath.c_str());
8022+ WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(h).c_str(), iniPath.c_str());
8023+ WritePrivateProfileStringW(L"View", L"LastWindowX", std::to_wstring(wp.rcNormalPosition.left).c_str(), iniPath.c_str());
8024+ WritePrivateProfileStringW(L"View", L"LastWindowY", std::to_wstring(wp.rcNormalPosition.top).c_str(), iniPath.c_str());
79828025 }
7983- WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(rc.right - rc.left).c_str(), iniPath.c_str());
7984- WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(rc.bottom - rc.top).c_str(), iniPath.c_str());
79858026 }
79868027 }
79878028
0 commit comments