From da9c52371edd7e2d03907df939e7e8c7109fb4a7 Mon Sep 17 00:00:00 2001 From: Ilya Shpigor Date: Sun, 15 Nov 2009 13:33:38 +0300 Subject: [PATCH] user32: Destroy EDITSTATE structure in the WM_NCDESTROY message processing. --- dlls/user32/edit.c | 10 +++++----- dlls/user32/tests/edit.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index 190e9c6690e..f4143b102de 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -4691,10 +4691,10 @@ static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name) /********************************************************************* * - * WM_DESTROY + * WM_NCDESTROY * */ -static LRESULT EDIT_WM_Destroy(EDITSTATE *es) +static LRESULT EDIT_WM_NCDestroy(EDITSTATE *es) { LINEDEF *pc, *pp; @@ -4762,7 +4762,7 @@ static LRESULT EditWndProc_common( HWND hwnd, UINT msg, if (!es && msg != WM_NCCREATE) return DefWindowProcT(hwnd, msg, wParam, lParam, unicode); - if (es && (msg != WM_DESTROY)) EDIT_LockBuffer(es); + if (es && (msg != WM_NCDESTROY)) EDIT_LockBuffer(es); switch (msg) { case EM_GETSEL16: @@ -5102,8 +5102,8 @@ static LRESULT EditWndProc_common( HWND hwnd, UINT msg, result = EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTW)lParam, unicode); break; - case WM_DESTROY: - result = EDIT_WM_Destroy(es); + case WM_NCDESTROY: + result = EDIT_WM_NCDestroy(es); es = NULL; break; diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 5ca012e53f7..e42127f88ad 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -1239,6 +1239,45 @@ static void test_edit_control_5(void) DestroyWindow(hWnd); } +/* Test WM_GETTEXT processing + * after destroy messages + */ +static void test_edit_control_6(void) +{ + static const char *str = "test\r\ntest"; + char buf[MAXLEN]; + LONG ret; + HWND hWnd; + + hWnd = CreateWindowEx(0, + "EDIT", + "Test", + 0, + 10, 10, 1, 1, + NULL, NULL, hinst, NULL); + assert(hWnd); + + ret = SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str); + ok(ret == TRUE, "Expected %d, got %d\n", TRUE, ret); + ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf); + ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret); + ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf); + buf[0] = 0; + ret = SendMessageA(hWnd, WM_DESTROY, 0, 0); + ok(ret == 0, "Expected 0, got %d\n", ret); + ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf); + ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret); + ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf); + buf[0] = 0; + ret = SendMessageA(hWnd, WM_NCDESTROY, 0, 0); + ok(ret == 0, "Expected 0, got %d\n", ret); + ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf); + ok(ret == 0, "Expected 0, got len %d\n", ret); + ok(!lstrcmp(buf, ""), "Expected empty string, got %s\n", buf); + + DestroyWindow(hWnd); +} + static void test_edit_control_limittext(void) { HWND hwEdit; @@ -2270,6 +2309,7 @@ START_TEST(edit) test_edit_control_3(); test_edit_control_4(); test_edit_control_5(); + test_edit_control_6(); test_edit_control_limittext(); test_margins(); test_margins_font_change();