From: Gabriel Ivăncescu Subject: [PATCH 14/17] shell32/autocomplete: Reset the contents of the AutoComplete listbox when hiding it Message-Id: <4633784049a8f6086a7b7fe0a91d38e363f0ab60.1536163731.git.gabrielopcode@gmail.com> Date: Wed, 5 Sep 2018 19:13:16 +0300 In-Reply-To: <695190c8471230e6a87e237a7c4a86e3281525b8.1536163731.git.gabrielopcode@gmail.com> References: <695190c8471230e6a87e237a7c4a86e3281525b8.1536163731.git.gabrielopcode@gmail.com> Signed-off-by: Gabriel Ivăncescu --- dlls/shell32/autocomplete.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/dlls/shell32/autocomplete.c b/dlls/shell32/autocomplete.c index 9bc617b..c5bc582 100644 --- a/dlls/shell32/autocomplete.c +++ b/dlls/shell32/autocomplete.c @@ -109,6 +109,14 @@ static void set_text_and_selection(IAutoCompleteImpl *This, HWND hwnd, WCHAR *te CallWindowProcW(proc, hwnd, EM_SETSEL, start, end); } +static void hide_listbox(IAutoCompleteImpl *ac, HWND hwnd) +{ + /* hide the AutoComplete listbox but also reset its contents to avoid + memory use buildup for tons of edit controls with AutoComplete */ + ShowWindow(hwnd, SW_HIDE); + send_to_LB(ac, hwnd, LB_RESETCONTENT, 0, 0); +} + static void destroy_autocomplete_object(IAutoCompleteImpl *ac) { ac->hwndEdit = NULL; @@ -137,12 +145,12 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, { case CB_SHOWDROPDOWN: if (This->options & ACO_AUTOSUGGEST) - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); break; case WM_KILLFOCUS: if ((This->options & ACO_AUTOSUGGEST) && ((HWND)wParam != This->hwndListBox)) { - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); } return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam); case WM_KEYDOWN: @@ -181,7 +189,7 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, This->no_fwd_char = '\n'; /* CTRL+RETURN char */ if (This->options & ACO_AUTOSUGGEST) - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); heap_free(hwndText); return 0; } @@ -196,13 +204,13 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, len = send_to_LB(This, hwndListBox, LB_GETTEXT, sel, (LPARAM)hwndText); set_text_and_selection(This, hwnd, hwndText, 0, len); This->no_fwd_char = '\r'; /* RETURN char */ - ShowWindow(hwndListBox, SW_HIDE); + hide_listbox(This, hwndListBox); heap_free(hwndText); return 0; } } } - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); } break; case VK_UP: @@ -267,7 +275,7 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, edit_proc = edit_proc == ACEditSubclassProc ? This->wpOrigEditProc : edit_proc; len = CallWindowProcW(edit_proc, hwnd, WM_GETTEXTLENGTH, 0, 0); if ((This->options & ACO_AUTOSUGGEST) && len == 0) { - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); return ret; } if (wParam != 0x16 /* ^V (paste) */) @@ -360,7 +368,7 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, SWP_SHOWWINDOW ); send_to_LB(This, This->hwndListBox, WM_SETREDRAW, TRUE, 0); } else { - ShowWindow(This->hwndListBox, SW_HIDE); + hide_listbox(This, This->hwndListBox); } } return ret; @@ -400,7 +408,7 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, if ((msg = heap_alloc((len + 1)*sizeof(WCHAR)))) { len = send_to_LB(This, hwnd, LB_GETTEXT, sel, (LPARAM)msg); set_text_and_selection(This, This->hwndEdit, msg, 0, len); - ShowWindow(hwnd, SW_HIDE); + hide_listbox(This, hwnd); heap_free(msg); } break; -- 1.9.1