From a343038e97bcd6fd405e5b2e234296612b28155b Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 24 May 2020 18:24:41 +0300 Subject: [PATCH] Fix stale window handle when switching GUI panels. --- od-win32/win32gui.cpp | 2 +- od-win32/win32gui.h | 1 + od-win32/win32gui_extra.cpp | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 28b1e54a..cf4f89e4 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -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) { diff --git a/od-win32/win32gui.h b/od-win32/win32gui.h index 7e277f33..21c11969 100644 --- a/od-win32/win32gui.h +++ b/od-win32/win32gui.h @@ -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); diff --git a/od-win32/win32gui_extra.cpp b/od-win32/win32gui_extra.cpp index 4ceb9a47..935f9f8c 100644 --- a/od-win32/win32gui_extra.cpp +++ b/od-win32/win32gui_extra.cpp @@ -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); } -- 2.47.3