1 /*
2  * PROJECT:     ReactOS API tests
3  * LICENSE:     LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE:     Test for ScrollBar cbWndExtra
5  * COPYRIGHT:   Copyright 2019 Mark Jansen <mark.jansen@reactos.org>
6  *
7  * Why do we need this test?
8  * Ask the authors of Civilization II...
9  */
10 
11 #include "precomp.h"
12 
13 #define BUILTIN_SCROLLBAR   "Scrollbar"
14 #define CUSTOM_SCROLLBAR    "MSScrollBarClass"
15 
16 
17 
18 START_TEST(ScrollBarWndExtra)
19 {
20     HWND hScrollBar;
21     HWND hScrollBarImpersonator;
22     WNDCLASSA WndClass;
23     ATOM ClassAtom;
24 
25     LONG_PTR dummyData = (LONG_PTR)0xbeefbeefbeefbeefULL, result;
26     WNDPROC lpfnWndProc;
27     DWORD dwExtra;
28 
29     hScrollBar = CreateWindowExA(0, BUILTIN_SCROLLBAR, "", WS_POPUP,
30                                  20, 20, 120, 120, NULL, 0, GetModuleHandle(NULL), 0);
31 
32     ok(hScrollBar != NULL, "Scrollbar creation failed (%lu)\n", GetLastError());
33 
34     lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hScrollBar, GWL_WNDPROC);
35     dwExtra = GetClassLongPtrA(hScrollBar, GCL_CBWNDEXTRA);
36 
37     ZeroMemory(&WndClass, sizeof(WndClass));
38     WndClass.style = CS_DBLCLKS | CS_PARENTDC | CS_HREDRAW | CS_VREDRAW;
39     WndClass.lpfnWndProc = lpfnWndProc;
40     WndClass.cbWndExtra = dwExtra + sizeof(LONG_PTR);
41     WndClass.hInstance = GetModuleHandle(NULL);
42     WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
43     WndClass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
44     WndClass.lpszClassName = CUSTOM_SCROLLBAR;
45     ClassAtom = RegisterClassA(&WndClass);
46 
47     ok(ClassAtom != 0, "RegisterClassA failed (%lu)\n", GetLastError());
48     DestroyWindow(hScrollBar);
49 
50 
51     hScrollBarImpersonator = CreateWindowExA(0, CUSTOM_SCROLLBAR, "", WS_POPUP,
52                                              20, 20, 120, 120, NULL, 0, GetModuleHandle(NULL), 0);
53     ok(hScrollBarImpersonator != NULL, "Scrollbar creation failed (%lu)\n", GetLastError());
54 
55     SetWindowLongPtrA(hScrollBarImpersonator, dwExtra, dummyData);
56     result = GetWindowLongPtrA(hScrollBarImpersonator, dwExtra);
57     ok(result == dummyData, "Invalid dummyData\n");
58 
59     DestroyWindow(hScrollBarImpersonator);
60     UnregisterClassA(CUSTOM_SCROLLBAR, GetModuleHandle(NULL));
61 }
62