]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Fix stale window handle when switching GUI panels.
authorToni Wilen <twilen@winuae.net>
Sun, 24 May 2020 15:24:41 +0000 (18:24 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 24 May 2020 15:24:41 +0000 (18:24 +0300)
od-win32/win32gui.cpp
od-win32/win32gui.h
od-win32/win32gui_extra.cpp

index 28b1e54a2fefc375ba8047eae583d2f5fe303631..cf4f89e44e90fd0390d90619bf51d70ebf2265f6 100644 (file)
@@ -20643,7 +20643,7 @@ static HWND updatePanel (int id, UINT action)
        ew (guiDlg, IDOK, TRUE);
        if (panelDlg != NULL) {
                ShowWindow (panelDlg, FALSE);
-               DestroyWindow (panelDlg);
+               x_DestroyWindow(panelDlg, panelresource);
                panelDlg = NULL;
        }
        if (ToolTipHWND != NULL) {
index 7e277f33ca6df740002592a8d6e7a987c02b3607..21c11969359238e0b86588ed142cf0af0e4866b7 100644 (file)
@@ -110,6 +110,7 @@ extern struct uae_prefs workprefs;
 extern int dialog_inhibit;
 
 HWND x_CreateDialogIndirectParam(HINSTANCE hInstance, LPCDLGTEMPLATE lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM lParamInit, struct newresource*);
+void x_DestroyWindow(HWND, struct newresource*);
 void getguipos(int *xp, int *yp);
 extern int scaleresource(struct newresource*, struct dlgcontext *dctx, HWND, int, int, DWORD, int);
 extern void rescaleresource(struct newresource*, bool);
index 4ceb9a475b1e012c672978e5f7f1f2bdaaecbd35..935f9f8c74d17af0e68b129c1fa8647e12d7eb46 100644 (file)
@@ -746,6 +746,21 @@ HWND x_CreateDialogIndirectParam(
        return DIALOG_CreateIndirect(hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, NULL, res);
 }
 
+void x_DestroyWindow(HWND hwnd, struct newresource *res)
+{
+       for (int i = 0; res->hwndcnt; i++) {
+               struct newreswnd *pr = &res->hwnds[i];
+               if (res->hwnds[i].hwnd == hwnd) {
+                       res->hwndcnt--;
+                       int tomove = res->hwndcnt - i;
+                       if (tomove > 0) {
+                               memmove(&res->hwnds[i], &res->hwnds[i + 1], tomove * sizeof(newreswnd));
+                       }
+                       break;
+               }
+       }
+       DestroyWindow(hwnd);
+}
 
 static int align (double f)
 {
@@ -841,7 +856,9 @@ static void scalechildwindows(struct newresource *nr)
                        disable = true;
                }
                SetFocus(nw->hwnd);
-               SetWindowPos(nw->hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | SWP_DEFERERASE);
+               if (!SetWindowPos(nw->hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | SWP_DEFERERASE)) {
+                       write_log("scalechildwindows %d/%d: ERROR %d", i, nr->hwndcnt, GetLastError());
+               }
                if (disable) {
                        EnableWindow(nw->hwnd, FALSE);
                }