[PATCH 2/2] user/listbox: Don't update scrollbar during window creation

Fabian Maurer dark.shadow4 at web.de
Thu Sep 13 10:42:22 CDT 2018


Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/user32/listbox.c       |  7 +++++++
 dlls/user32/tests/listbox.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index c8bd148d63..7bbdcd2d39 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -86,6 +86,7 @@ typedef struct
     HFONT       font;           /* Current font */
     LCID          locale;       /* Current locale for string comparisons */
     LPHEADCOMBO   lphc;		/* ComboLBox */
+    BOOL        got_wm_size;     /* Did we get already a WM_SIZE? */
 } LB_DESCR;
 
 
@@ -225,6 +226,10 @@ static void LISTBOX_UpdateScroll( LB_DESCR *descr )
        the programmer use it for his/her own purposes. */
 
     if (descr->style & LBS_NOREDRAW) return;
+
+    /* When height is 0 don't update scrollbar during CreateWindowEx, that is until we receive our first WM_SIZE */
+    if (!descr->got_wm_size && descr->height == 0) return;
+
     info.cbSize = sizeof(info);
 
     if (descr->style & LBS_MULTICOLUMN)
@@ -2507,6 +2512,7 @@ static BOOL LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc )
     descr->font          = 0;
     descr->locale        = GetUserDefaultLCID();
     descr->lphc		 = lphc;
+    descr->got_wm_size   = FALSE;
 
     if( lphc )
     {
@@ -2993,6 +2999,7 @@ LRESULT ListBoxWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
         return ret;
     case WM_SIZE:
         LISTBOX_UpdateSize( descr );
+        descr->got_wm_size = TRUE;
         return 0;
     case WM_GETFONT:
         return (LRESULT)descr->font;
diff --git a/dlls/user32/tests/listbox.c b/dlls/user32/tests/listbox.c
index dfa8de7b88..785b6d7df9 100644
--- a/dlls/user32/tests/listbox.c
+++ b/dlls/user32/tests/listbox.c
@@ -1980,6 +1980,40 @@ static void test_WM_MEASUREITEM(void)
     DestroyWindow(parent);
 }
 
+static void test_WS_VSCROLL(void)
+{
+    HWND parent, listbox;
+    UINT style;
+
+    parent = create_parent();
+
+    /* Listbox must always have WS_VSCROLL after creating when height 0 was specified */
+    listbox = CreateWindowA("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT) | WS_CHILD | WS_VSCROLL, 0, 0, 100, 0, parent, NULL, NULL, 0);
+    style = GetWindowLongW(listbox, GWL_STYLE);
+    ok((style & WS_VSCROLL) != 0, "Listbox must have WS_VSCROLL\n");
+    SendMessageA(listbox, WM_SIZE, SIZE_RESTORED, 0);
+    style = GetWindowLongW(listbox, GWL_STYLE);
+    ok((style & WS_VSCROLL) == 0, "Listbox must not have WS_VSCROLL\n");
+    DestroyWindow(listbox);
+
+    /* Listbox must not have WS_VSCROLL after creating when height > 0 was specified */
+    listbox = CreateWindowA("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT) | WS_CHILD | WS_VSCROLL, 0, 0, 100, 100, parent, NULL, NULL, 0);
+    style = GetWindowLongW(listbox, GWL_STYLE);
+    ok((style & WS_VSCROLL) == 0, "Listbox must not have WS_VSCROLL\n");
+    DestroyWindow(listbox);
+
+    /* Adding elements must change WS_VSCROLL flag */
+    listbox = CreateWindowA("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT) | WS_CHILD | WS_VSCROLL, 0, 0, 100, 0, parent, NULL, NULL, 0);
+    SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"test1");
+    style = GetWindowLongW(listbox, GWL_STYLE);
+    ok((style & WS_VSCROLL) == 0, "Listbox must not have WS_VSCROLL\n");
+    SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"test1");
+    style = GetWindowLongW(listbox, GWL_STYLE);
+    ok((style & WS_VSCROLL) != 0, "Listbox must have WS_VSCROLL\n");
+
+    DestroyWindow(parent);
+}
+
 START_TEST(listbox)
 {
   const struct listbox_test SS =
@@ -2065,4 +2099,5 @@ START_TEST(listbox)
   test_extents();
   test_WM_MEASUREITEM();
   test_LB_SETSEL();
+  test_WS_VSCROLL();
 }
-- 
2.19.0




More information about the wine-devel mailing list