Merge branch 'ntfs_rebase'
[reactos.git] / modules / rostests / winetests / user32 / scroll.c
1 /*
2 * Unit tests for scrollbar
3 *
4 * Copyright 2008 Lyutin Anatoly (Etersoft)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22
23 static HWND hScroll;
24 static BOOL bThemeActive = FALSE;
25
26 static LRESULT CALLBACK MyWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
27 {
28 switch(msg)
29 {
30
31 case WM_CREATE:
32 {
33 hScroll = CreateWindowA( "SCROLLBAR", "", WS_CHILD | WS_VISIBLE, 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0 );
34
35 return 0;
36 }
37 case WM_DESTROY:
38 PostQuitMessage(0);
39 break;
40 case WM_HSCROLL:
41 case WM_VSCROLL:
42 /* stop tracking */
43 ReleaseCapture();
44 return 0;
45 default:
46 return DefWindowProcA(hWnd, msg, wParam, lParam);
47 }
48 return 0;
49 }
50
51 static HWND create_main_test_wnd(void)
52 {
53 HWND hMainWnd;
54
55 hScroll = NULL;
56 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
57 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
58 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
59 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
60 ok(hScroll != NULL, "got NULL scroll bar handle\n");
61
62 return hMainWnd;
63 }
64
65 static void scrollbar_test_track(void)
66 {
67 HWND mainwnd;
68
69 mainwnd = create_main_test_wnd();
70
71 /* test that scrollbar tracking is terminated when
72 * the control loses mouse capture */
73 SendMessageA( hScroll, WM_LBUTTONDOWN, 0, MAKELPARAM( 1, 1));
74 /* a normal return from SendMessage */
75 /* not normal for instances such as closing the window */
76 ok( IsWindow( hScroll), "Scrollbar has gone!\n");
77
78 DestroyWindow(hScroll);
79 DestroyWindow(mainwnd);
80 }
81
82 static void test_EnableScrollBar(void)
83 {
84 HWND mainwnd;
85 BOOL ret;
86
87 mainwnd = create_main_test_wnd();
88
89 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_BOTH );
90 ok( ret, "The scrollbar should be disabled.\n" );
91 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
92
93 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
94 ok( ret, "The scrollbar should be enabled.\n" );
95 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
96
97 /* test buttons separately */
98 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_LTUP );
99 ok( ret, "The scrollbar LTUP button should be disabled.\n" );
100 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
101 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
102 ok( ret, "The scrollbar should be enabled.\n" );
103 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
104
105 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_RTDN );
106 ok( ret, "The scrollbar RTDN button should be disabled.\n" );
107 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
108 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
109 ok( ret, "The scrollbar should be enabled.\n" );
110 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
111
112 /* disable window, try to re-enable */
113 ret = EnableWindow( hScroll, FALSE );
114 ok( !ret, "got %d\n", ret );
115 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
116
117 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
118 ok( ret, "got %d\n", ret );
119 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
120
121 DestroyWindow(hScroll);
122 DestroyWindow(mainwnd);
123 }
124
125 static void test_SetScrollPos(void)
126 {
127 HWND mainwnd;
128 int ret;
129
130 mainwnd = create_main_test_wnd();
131
132 EnableWindow( hScroll, FALSE );
133 ok( !IsWindowEnabled( hScroll ), "The scroll should be disabled.\n" );
134
135 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
136 ok( !ret, "The position should not be set.\n" );
137
138 ret = GetScrollPos( hScroll, SB_CTL);
139 ok( !ret, "The position should be equal to zero\n");
140
141 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
142 ok( ret, "The range should be set.\n" );
143
144 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
145 ok( !ret , "The position should not be set.\n" );
146
147 ret = GetScrollPos( hScroll, SB_CTL);
148 ok( ret == 30, "The position should be set!!!\n");
149
150 EnableWindow( hScroll, TRUE );
151 ok( IsWindowEnabled( hScroll ), "The scroll should be enabled.\n" );
152
153 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
154 ok( ret == 30, "The position should be set.\n" );
155
156 ret = GetScrollPos( hScroll, SB_CTL);
157 ok( ret == 30, "The position should not be equal to zero\n");
158
159 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
160 ok( ret, "The range should be set.\n" );
161
162 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
163 ok( ret == 30, "The position should be set.\n" );
164
165 ret = GetScrollPos( hScroll, SB_CTL);
166 ok( ret == 30, "The position should not be equal to zero\n");
167
168 DestroyWindow(hScroll);
169 DestroyWindow(mainwnd);
170 }
171
172 static void test_ShowScrollBar(void)
173 {
174 HWND mainwnd;
175 BOOL ret;
176
177 mainwnd = create_main_test_wnd();
178
179 ret = ShowScrollBar( hScroll, SB_CTL, FALSE );
180 ok( ret, "The ShowScrollBar() should not failed.\n" );
181 ok( !IsWindowVisible( hScroll ), "The scrollbar window should not be visible\n" );
182
183 ret = ShowScrollBar( hScroll, SB_CTL, TRUE );
184 ok( ret, "The ShowScrollBar() should not failed.\n" );
185 ok( !IsWindowVisible( hScroll ), "The scrollbar window should be visible\n" );
186
187 ret = ShowScrollBar( NULL, SB_CTL, TRUE );
188 ok( !ret, "The ShowScrollBar() should failed.\n" );
189
190 DestroyWindow(hScroll);
191 DestroyWindow(mainwnd);
192 }
193
194 static void test_GetScrollBarInfo(void)
195 {
196 HWND hMainWnd;
197 BOOL ret;
198 SCROLLBARINFO sbi;
199 RECT rect;
200 BOOL (WINAPI *pGetScrollBarInfo)(HWND, LONG, LPSCROLLBARINFO);
201
202 pGetScrollBarInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetScrollBarInfo");
203 if (!pGetScrollBarInfo)
204 {
205 win_skip("GetScrollBarInfo is not available\n");
206 return;
207 }
208
209 hMainWnd = create_main_test_wnd();
210
211 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
212 * coordinates. */
213 sbi.cbSize = sizeof(sbi);
214 ret = pGetScrollBarInfo( hScroll, OBJID_CLIENT, &sbi);
215 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
216 GetWindowRect( hScroll, &rect );
217 ok( ret, "The GetWindowRect() call should not fail.\n" );
218 ok( !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)),
219 "unexpected rgstate(0x%x)\n", sbi.rgstate[0]);
220 ok(EqualRect(&rect, &sbi.rcScrollBar), "WindowRect %s != rcScrollBar %s\n",
221 wine_dbgstr_rect(&rect), wine_dbgstr_rect(&sbi.rcScrollBar));
222
223 /* Test windows horizontal and vertical scrollbar to make sure rcScrollBar
224 * is still returned in screen coordinates by moving the window, and
225 * making sure that it shifts the rcScrollBar value. */
226 ShowWindow( hMainWnd, SW_SHOW );
227 sbi.cbSize = sizeof(sbi);
228 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
229 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
230 GetWindowRect( hMainWnd, &rect );
231 ok( ret, "The GetWindowRect() call should not fail.\n" );
232 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
233 rect.right-rect.left, rect.bottom-rect.top, TRUE );
234 rect = sbi.rcScrollBar;
235 OffsetRect(&rect, 5, 5);
236 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
237 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
238 ok(EqualRect(&rect, &sbi.rcScrollBar), "PreviousRect %s != CurrentRect %s\n",
239 wine_dbgstr_rect(&rect), wine_dbgstr_rect(&sbi.rcScrollBar));
240
241 sbi.cbSize = sizeof(sbi);
242 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
243 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
244 GetWindowRect( hMainWnd, &rect );
245 ok( ret, "The GetWindowRect() call should not fail.\n" );
246 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
247 rect.right-rect.left, rect.bottom-rect.top, TRUE );
248 rect = sbi.rcScrollBar;
249 OffsetRect(&rect, 5, 5);
250 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
251 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
252 ok(EqualRect(&rect, &sbi.rcScrollBar), "PreviousRect %s != CurrentRect %s\n",
253 wine_dbgstr_rect(&rect), wine_dbgstr_rect(&sbi.rcScrollBar));
254
255 DestroyWindow(hScroll);
256 DestroyWindow(hMainWnd);
257 }
258
259 /* some tests designed to show that Horizontal and Vertical
260 * window scroll bar info are not created independently */
261 static void scrollbar_test_default( DWORD style)
262 {
263 INT min, max, ret;
264 DWORD winstyle;
265 HWND hwnd;
266 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
267
268 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
269 0, 0, 10, 10, 0, 0, 0, NULL);
270 assert( hwnd != 0);
271
272 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
273 ok( ret ||
274 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
275 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
276 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
277 ok( min == 0 && max == 0,
278 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
279 else
280 ok(( min == 0 && max == 100) ||
281 broken( min == 0 && max == 0), /* Win 9x/ME */
282 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
283 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
284 ok( ret ||
285 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
286 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
287 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
288 ok( min == 0 && max == 0,
289 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
290 else
291 ok(( min == 0 && max == 100) ||
292 broken( min == 0 && max == 0), /* Win 9x/ME */
293 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
294 /* test GetScrollInfo, vist for vertical SB */
295 ret = GetScrollInfo( hwnd, SB_VERT, &si);
296 /* should fail if no H or V scroll bar styles are present. Succeed otherwise */
297 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
298 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
299 else
300 ok( ret ||
301 broken( !ret), /* Win 9x/ME */
302 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
303 /* Same for Horizontal SB */
304 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
305 /* should fail if no H or V scroll bar styles are present. Succeed otherwise */
306 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
307 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
308 else
309 ok( ret ||
310 broken( !ret), /* Win 9x/ME */
311 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
312 /* now set the Vertical Scroll range to something that could be the default value it
313 * already has */;
314 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
315 ok( ret, "SetScrollRange failed.\n");
316 /* and request the Horizontal range */
317 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
318 ok( ret, "GetScrollRange failed.\n");
319 /* now the range should be 0,100 in ALL cases */
320 ok( min == 0 && max == 100,
321 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
322 /* See what is different now for GetScrollRange */
323 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
324 /* should succeed in ALL cases */
325 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
326 ret = GetScrollInfo( hwnd, SB_VERT, &si);
327 /* should succeed in ALL cases */
328 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
329 /* report the windows style */
330 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
331 /* WS_VSCROLL added to the window style */
332 if( !(style & WS_VSCROLL))
333 {
334 if (bThemeActive || style != WS_HSCROLL)
335 todo_wine
336 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL),
337 "unexpected style change %08x/%08x\n", winstyle, style);
338 else
339 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style,
340 "unexpected style change %08x/%08x\n", winstyle, style);
341 }
342 /* do the test again with H and V reversed.
343 * Start with a clean window */
344 DestroyWindow( hwnd);
345 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
346 0, 0, 10, 10, 0, 0, 0, NULL);
347 assert( hwnd != 0);
348 /* Set Horizontal Scroll range to something that could be the default value it
349 * already has */;
350 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
351 ok( ret, "SetScrollRange failed.\n");
352 /* and request the Vertical range */
353 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
354 ok( ret, "GetScrollRange failed.\n");
355 /* now the range should be 0,100 in ALL cases */
356 ok( min == 0 && max == 100,
357 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
358 /* See what is different now for GetScrollRange */
359 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
360 /* should succeed in ALL cases */
361 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
362 ret = GetScrollInfo( hwnd, SB_VERT, &si);
363 /* should succeed in ALL cases */
364 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
365 /* report the windows style */
366 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
367 /* WS_HSCROLL added to the window style */
368 if( !(style & WS_HSCROLL))
369 {
370 if (bThemeActive || style != WS_VSCROLL)
371 todo_wine
372 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL),
373 "unexpected style change %08x/%08x\n", winstyle, style);
374 else
375 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style,
376 "unexpected style change %08x/%08x\n", winstyle, style);
377 }
378 /* Slightly change the test to use SetScrollInfo
379 * Start with a clean window */
380 DestroyWindow( hwnd);
381 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
382 0, 0, 10, 10, 0, 0, 0, NULL);
383 assert( hwnd != 0);
384 /* set Horizontal position with SetScrollInfo */
385 si.nPos = 0;
386 si.nMin = 11;
387 si.nMax = 22;
388 si.fMask |= SIF_RANGE;
389 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
390 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
391 /* and request the Vertical range */
392 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
393 ok( ret, "GetScrollRange failed.\n");
394 /* now the range should be 0,100 in ALL cases */
395 ok( min == 0 && max == 100,
396 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
397 /* See what is different now for GetScrollRange */
398 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
399 /* should succeed in ALL cases */
400 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
401 ret = GetScrollInfo( hwnd, SB_VERT, &si);
402 /* should succeed in ALL cases */
403 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
404 /* also test if the window scroll bars are enabled */
405 ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
406 ok( !ret, "Vertical window scroll bar was not enabled\n");
407 ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
408 ok( !ret, "Horizontal window scroll bar was not enabled\n");
409 DestroyWindow( hwnd);
410 /* finally, check if adding a WS_[HV]SCROLL style of a window makes the scroll info
411 * available */
412 if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */
413 /* Start with a clean window */
414 DestroyWindow( hwnd);
415 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP ,
416 0, 0, 10, 10, 0, 0, 0, NULL);
417 assert( hwnd != 0);
418 ret = GetScrollInfo( hwnd, SB_VERT, &si);
419 /* should fail */
420 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
421 /* add scroll styles */
422 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
423 SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL);
424 ret = GetScrollInfo( hwnd, SB_VERT, &si);
425 /* should still fail */
426 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
427 /* clean up */
428 DestroyWindow( hwnd);
429 }
430
431 static LRESULT CALLBACK scroll_init_proc(HWND hwnd, UINT msg,
432 WPARAM wparam, LPARAM lparam)
433 {
434 SCROLLINFO horz, vert;
435 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
436 BOOL h_ret, v_ret;
437
438 switch(msg)
439 {
440 case WM_NCCREATE:
441 return cs->lpCreateParams ? DefWindowProcA(hwnd, msg, wparam, lparam) :
442 TRUE;
443
444 case WM_CREATE:
445 horz.cbSize = sizeof horz;
446 horz.fMask = SIF_ALL;
447 horz.nMin = 0xdeadbeaf;
448 horz.nMax = 0xbaadc0de;
449 vert = horz;
450 h_ret = GetScrollInfo(hwnd, SB_HORZ, &horz);
451 v_ret = GetScrollInfo(hwnd, SB_VERT, &vert);
452
453 if(cs->lpCreateParams)
454 {
455 /* WM_NCCREATE was passed to DefWindowProc */
456 if(cs->style & (WS_VSCROLL | WS_HSCROLL))
457 {
458 ok(h_ret && v_ret, "GetScrollInfo() should return NON-zero "
459 "but got h_ret=%d v_ret=%d\n", h_ret, v_ret);
460 ok(vert.nMin == 0 && vert.nMax == 100,
461 "unexpected init values(SB_VERT): min=%d max=%d\n",
462 vert.nMin, vert.nMax);
463 ok(horz.nMin == 0 && horz.nMax == 100,
464 "unexpected init values(SB_HORZ): min=%d max=%d\n",
465 horz.nMin, horz.nMax);
466 }
467 else
468 {
469 ok(!h_ret && !v_ret, "GetScrollInfo() should return zeru, "
470 "but got h_ret=%d v_ret=%d\n", h_ret, v_ret);
471 ok(vert.nMin == 0xdeadbeaf && vert.nMax == 0xbaadc0de,
472 "unexpected initialization(SB_VERT): min=%d max=%d\n",
473 vert.nMin, vert.nMax);
474 ok(horz.nMin == 0xdeadbeaf && horz.nMax == 0xbaadc0de,
475 "unexpected initialization(SB_HORZ): min=%d max=%d\n",
476 horz.nMin, horz.nMax);
477 }
478 }
479 else
480 {
481 ok(!h_ret && !v_ret, "GetScrollInfo() should return zeru, "
482 "but got h_ret=%d v_ret=%d\n", h_ret, v_ret);
483 ok(horz.nMin == 0xdeadbeaf && horz.nMax == 0xbaadc0de &&
484 vert.nMin == 0xdeadbeaf && vert.nMax == 0xbaadc0de,
485 "unexpected initialization\n");
486 }
487 return FALSE; /* abort creation */
488
489 default:
490 /* need for WM_GETMINMAXINFO, which precedes WM_NCCREATE */
491 return 0;
492 }
493 }
494
495 static void scrollbar_test_init(void)
496 {
497 WNDCLASSEXA wc;
498 CHAR cls_name[] = "scroll_test_class";
499 LONG style[] = {WS_VSCROLL, WS_HSCROLL, WS_VSCROLL | WS_HSCROLL, 0};
500 int i;
501
502 memset( &wc, 0, sizeof wc );
503 wc.cbSize = sizeof wc;
504 wc.style = CS_VREDRAW | CS_HREDRAW;
505 wc.hInstance = GetModuleHandleA(0);
506 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
507 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
508 wc.lpszClassName = cls_name;
509 wc.lpfnWndProc = scroll_init_proc;
510 RegisterClassExA(&wc);
511
512 for(i = 0; i < sizeof style / sizeof style[0]; i++)
513 {
514 /* need not to destroy these windows due creation abort */
515 CreateWindowExA(0, cls_name, NULL, style[i],
516 100, 100, 100, 100, NULL, NULL, wc.hInstance, (LPVOID)TRUE);
517 CreateWindowExA(0, cls_name, NULL, style[i],
518 100, 100, 100, 100, NULL, NULL, wc.hInstance, (LPVOID)FALSE);
519 }
520 UnregisterClassA(cls_name, wc.hInstance);
521 }
522
523 static void test_SetScrollInfo(void)
524 {
525 SCROLLINFO si;
526 HWND mainwnd;
527 BOOL ret;
528
529 mainwnd = create_main_test_wnd();
530
531 ret = IsWindowEnabled(hScroll);
532 ok(ret, "scroll bar disabled\n");
533
534 EnableScrollBar(hScroll, SB_CTL, ESB_DISABLE_BOTH);
535
536 ret = IsWindowEnabled(hScroll);
537 ok(!ret, "scroll bar enabled\n");
538
539 memset(&si, 0, sizeof(si));
540 si.cbSize = sizeof(si);
541 si.fMask = 0xf;
542 ret = GetScrollInfo(hScroll, SB_CTL, &si);
543 ok(ret, "got %d\n", ret);
544
545 /* SetScrollInfo */
546 memset(&si, 0, sizeof(si));
547 si.cbSize = sizeof(si);
548 ret = IsWindowEnabled(hScroll);
549 ok(!ret, "scroll bar enabled\n");
550 si.fMask = SIF_POS|SIF_RANGE|SIF_PAGE|SIF_DISABLENOSCROLL;
551 si.nMax = 100;
552 si.nMin = 10;
553 si.nPos = 0;
554 si.nPage = 100;
555 SetScrollInfo(hScroll, SB_CTL, &si, TRUE);
556 ret = IsWindowEnabled(hScroll);
557 ok(!ret, "scroll bar enabled\n");
558
559 si.fMask = 0xf;
560 ret = GetScrollInfo(hScroll, SB_CTL, &si);
561 ok(ret, "got %d\n", ret);
562
563 EnableScrollBar(hScroll, SB_CTL, ESB_ENABLE_BOTH);
564 ok(IsWindowEnabled(hScroll), "expected enabled scrollbar\n");
565
566 si.fMask = SIF_POS|SIF_RANGE|SIF_PAGE|SIF_DISABLENOSCROLL;
567 si.nMax = 10;
568 si.nMin = 100;
569 si.nPos = 0;
570 si.nPage = 100;
571 SetScrollInfo(hScroll, SB_CTL, &si, TRUE);
572 ret = IsWindowEnabled(hScroll);
573 ok(ret, "scroll bar disabled\n");
574
575 DestroyWindow(hScroll);
576 DestroyWindow(mainwnd);
577 }
578
579 START_TEST ( scroll )
580 {
581 WNDCLASSA wc;
582 HMODULE hUxtheme;
583 BOOL (WINAPI * pIsThemeActive)(VOID);
584
585 wc.style = CS_HREDRAW | CS_VREDRAW;
586 wc.cbClsExtra = 0;
587 wc.cbWndExtra = 0;
588 wc.hInstance = GetModuleHandleA(NULL);
589 wc.hIcon = NULL;
590 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_IBEAM);
591 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
592 wc.lpszMenuName = NULL;
593 wc.lpszClassName = "MyTestWnd";
594 wc.lpfnWndProc = MyWndProc;
595 RegisterClassA(&wc);
596
597 test_EnableScrollBar();
598 test_SetScrollPos();
599 test_ShowScrollBar();
600 test_GetScrollBarInfo();
601 scrollbar_test_track();
602 test_SetScrollInfo();
603
604 /* Some test results vary depending of theming being active or not */
605 hUxtheme = LoadLibraryA("uxtheme.dll");
606 if (hUxtheme)
607 {
608 pIsThemeActive = (void*)GetProcAddress(hUxtheme, "IsThemeActive");
609 if (pIsThemeActive)
610 bThemeActive = pIsThemeActive();
611 FreeLibrary(hUxtheme);
612 }
613
614 scrollbar_test_default( 0);
615 scrollbar_test_default( WS_HSCROLL);
616 scrollbar_test_default( WS_VSCROLL);
617 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
618
619 scrollbar_test_init();
620 }