From 9d4ce95de50e019c3522ec95f6525d85230ea699 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 21 Nov 2018 16:27:01 +0100 Subject: [PATCH] user32: Attempt to set scroll info in SetScrollPos even if SCROLL_GetInternalInfo fails. SetScrollPos may be called on non-scroll window and we should send SBM_SETSCROLLINFO. This fixes scrollbars in Visio. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/user32/scroll.c | 5 ++--- dlls/user32/tests/scroll.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dlls/user32/scroll.c b/dlls/user32/scroll.c index 37095df889e..95d9761d768 100644 --- a/dlls/user32/scroll.c +++ b/dlls/user32/scroll.c @@ -1854,10 +1854,9 @@ INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL b { SCROLLINFO info; SCROLLBAR_INFO *infoPtr; - INT oldPos; + INT oldPos = 0; - if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0; - oldPos = infoPtr->curVal; + if ((infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) oldPos = infoPtr->curVal; info.cbSize = sizeof(info); info.nPos = nPos; info.fMask = SIF_POS; diff --git a/dlls/user32/tests/scroll.c b/dlls/user32/tests/scroll.c index 43d4720b820..fbc94a6d680 100644 --- a/dlls/user32/tests/scroll.c +++ b/dlls/user32/tests/scroll.c @@ -604,11 +604,16 @@ static void test_SetScrollInfo(void) static WNDPROC scrollbar_wndproc; +static SCROLLINFO set_scrollinfo; + static LRESULT CALLBACK subclass_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == WM_CREATE && ((CREATESTRUCTA*)lparam)->lpCreateParams) return DefWindowProcA(hwnd, msg, wparam, lparam); + if (msg == SBM_SETSCROLLINFO) + set_scrollinfo = *(SCROLLINFO*)lparam; + return CallWindowProcA(scrollbar_wndproc, hwnd, msg, wparam, lparam); } @@ -637,6 +642,20 @@ static void test_subclass(void) CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 ); ok(hwnd != NULL, "Failed to create window: %u\n", GetLastError()); + r = SetScrollRange(hwnd, SB_CTL, 0, 100, TRUE); + ok(r, "SetScrollRange failed: %u\n", GetLastError()); + + res = SetScrollPos(hwnd, SB_CTL, 2, FALSE); + ok(!res, "SetScrollPos returned %lu\n", res); + + memset(&set_scrollinfo, 0xcc, sizeof(set_scrollinfo)); + res = SetScrollPos(hwnd, SB_CTL, 1, FALSE); + ok(res == 2, "SetScrollPos returned %lu\n", res); + ok(set_scrollinfo.cbSize == sizeof(SCROLLINFO), "cbSize = %u\n", set_scrollinfo.cbSize); + todo_wine + ok(set_scrollinfo.fMask == (0x1000 | SIF_POS), "fMask = %x\n", set_scrollinfo.fMask); + ok(set_scrollinfo.nPos == 1, "nPos = %x\n", set_scrollinfo.nPos); + memset(&scroll_info, 0xcc, sizeof(scroll_info)); scroll_info.cbSize = sizeof(scroll_info); res = SendMessageA(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)&scroll_info); @@ -671,6 +690,14 @@ static void test_subclass(void) res = SendMessageA(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)&scroll_info); ok(!res, "SBM_GETSCROLLBARINFO returned %lu\n", res); + memset(&set_scrollinfo, 0xcc, sizeof(set_scrollinfo)); + res = SetScrollPos(hwnd, SB_CTL, 1, FALSE); + ok(res == 0, "SetScrollPos returned %lu\n", res); + ok(set_scrollinfo.cbSize == sizeof(SCROLLINFO), "cbSize = %u\n", set_scrollinfo.cbSize); + todo_wine + ok(set_scrollinfo.fMask == (0x1000 | SIF_POS), "fMask = %x\n", set_scrollinfo.fMask); + ok(set_scrollinfo.nPos == 1, "nPos = %x\n", set_scrollinfo.nPos); + DestroyWindow(hwnd); }