1 /* Unit test suite for the dialog functions.
3 * Copyright 2004 Bill Medland
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * This test suite currently works by building a quite complex hierarchy of
22 * objects in a variety of styles and then performs a limited number of tests
23 * for the previous and next dialog group or tab items.
25 * The test specifically does not test all possibilities at this time since
26 * there are several cases where the Windows behaviour is rather strange and
27 * significant work would be required to get the Wine code to duplicate the
28 * strangeness, especially since most are in situations that would not
36 #include "wine/test.h"
42 static HWND hwnd
[MAXHWNDS
];
43 static unsigned int numwnds
=1; /* 0 is reserved for null */
46 static HINSTANCE g_hinst
; /* This application's HINSTANCE */
47 static HWND g_hwndMain
, g_hwndButton1
, g_hwndButton2
, g_hwndButtonCancel
;
48 static HWND g_hwndTestDlg
, g_hwndTestDlgBut1
, g_hwndTestDlgBut2
, g_hwndTestDlgEdit
;
49 static HWND g_hwndInitialFocusT1
, g_hwndInitialFocusT2
, g_hwndInitialFocusGroupBox
;
51 static LONG g_styleInitialFocusT1
, g_styleInitialFocusT2
;
52 static BOOL g_bInitialFocusInitDlgResult
;
54 static int g_terminated
;
63 static const h_entry hierarchy
[] = {
64 /* 0 is reserved for the null window */
65 { 1, 0, WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
},
66 { 20, 1, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
67 { 2, 1, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
68 { 60, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
69 /* What happens with groups when the parent is disabled */
70 { 8, 2, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, WS_EX_CONTROLPARENT
},
71 { 85, 8, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_GROUP
, 0},
72 { 9, 8, WS_CHILD
, WS_EX_CONTROLPARENT
},
73 { 86, 9, WS_CHILD
| WS_VISIBLE
, 0},
74 { 87, 9, WS_CHILD
| WS_VISIBLE
, 0},
75 { 31, 8, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
76 { 10, 2, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
77 { 88, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
78 { 11, 10, WS_CHILD
, WS_EX_CONTROLPARENT
},
79 { 89, 11, WS_CHILD
| WS_VISIBLE
, 0},
80 { 32, 11, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
81 { 90, 11, WS_CHILD
| WS_VISIBLE
, 0},
82 { 33, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
83 { 21, 2, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
84 { 61, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
85 { 3, 1, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
86 { 22, 3, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
87 { 62, 3, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
88 { 7, 3, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
89 { 4, 7, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
90 { 83, 4, WS_CHILD
| WS_VISIBLE
, 0},
91 { 5, 4, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
92 /* A couple of controls around the main dialog */
93 { 29, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
94 { 81, 5, WS_CHILD
| WS_VISIBLE
, 0},
95 /* The main dialog with lots of controls */
96 { 6, 5, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
97 /* At the start of a dialog */
98 /* Disabled controls are skipped */
99 { 63, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
100 /* Invisible controls are skipped */
101 { 64, 6, WS_CHILD
| WS_TABSTOP
, 0},
102 /* Invisible disabled controls are skipped */
103 { 65, 6, WS_CHILD
| WS_DISABLED
| WS_TABSTOP
, 0},
104 /* Non-tabstop controls are skipped for tabs but not for groups */
105 { 66, 6, WS_CHILD
| WS_VISIBLE
, 0},
106 /* End of first group, with no tabstops in it */
107 { 23, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
108 /* At last a tabstop */
109 { 67, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
110 /* A group that is totally disabled or invisible */
111 { 24, 6, WS_CHILD
| WS_DISABLED
| WS_GROUP
, 0},
112 { 68, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
113 { 69, 6, WS_CHILD
| WS_TABSTOP
, 0},
114 /* A valid group in the middle of the dialog (not the first nor last group*/
115 { 25, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
116 /* A non-tabstop item will be skipped for tabs */
117 { 70, 6, WS_CHILD
| WS_VISIBLE
, 0},
118 /* A disabled item will be skipped for tabs and groups */
119 { 71, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
120 /* A valid item will be found for tabs and groups */
121 { 72, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
122 /* A disabled item to skip when looking for the next group item */
123 { 73, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
124 /* The next group begins with an enabled visible label */
125 { 26, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
126 { 74, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
127 { 75, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
128 /* That group is terminated by a disabled label */
129 { 27, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_GROUP
, 0},
130 { 76, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
131 { 77, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
132 /* That group is terminated by an invisible label */
133 { 28, 6, WS_CHILD
| WS_GROUP
, 0},
134 /* The end of the dialog with item for loop and recursion testing */
135 { 78, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
136 /* No tabstop so skipped for prev tab, but found for prev group */
137 { 79, 6, WS_CHILD
| WS_VISIBLE
, 0},
138 { 80, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
139 /* A couple of controls after the main dialog */
140 { 82, 5, WS_CHILD
| WS_VISIBLE
, 0},
141 { 30, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
142 /* And around them */
143 { 84, 4, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
147 static BOOL
CreateWindows (HINSTANCE hinst
)
149 const h_entry
*p
= hierarchy
;
153 DWORD style
, exstyle
;
156 /* Basically assert that the hierarchy is valid and track the
157 * maximum control number
159 if (p
->id
>= numwnds
)
161 if (p
->id
>= sizeof(hwnd
)/sizeof(hwnd
[0]))
163 trace ("Control %d is out of range\n", p
->id
);
171 trace ("Control %d is out of range\n", p
->id
);
174 if (hwnd
[p
->id
] != 0)
176 trace ("Control %d is used more than once\n", p
->id
);
180 /* Create the control */
181 sprintf (ctrlname
, "ctrl%4.4d", p
->id
);
182 hwnd
[p
->id
] = CreateWindowEx (p
->exstyle
, TEXT(p
->parent
? "static" : "GetNextDlgItemWindowClass"), TEXT(ctrlname
), p
->style
, 10, 10, 10, 10, hwnd
[p
->parent
], p
->parent
? (HMENU
) (2000 + p
->id
) : 0, hinst
, 0);
185 trace ("Failed to create control %d\n", p
->id
);
189 /* Check that the styles are as we specified (except the main one
190 * which is quite frequently messed up). If this keeps breaking then
191 * we could mask out the bits that don't concern us.
195 style
= GetWindowLong (hwnd
[p
->id
], GWL_STYLE
);
196 exstyle
= GetWindowLong (hwnd
[p
->id
], GWL_EXSTYLE
);
197 if (style
!= p
->style
|| exstyle
!= p
->exstyle
)
199 trace ("Style mismatch at %d: %8.8x %8.8x cf %8.8x %8.8x\n", p
->id
, style
, exstyle
, p
->style
, p
->exstyle
);
208 /* Form the lParam of a WM_KEYDOWN message */
209 static DWORD
KeyDownData (int repeat
, int scancode
, int extended
, int wasdown
)
211 return ((repeat
& 0x0000FFFF) | ((scancode
& 0x00FF) >> 16) |
212 (extended
? 0x01000000 : 0) | (wasdown
? 0x40000000 : 0));
215 /* Form a WM_KEYDOWN VK_TAB message to the specified window */
216 static void FormTabMsg (MSG
*pMsg
, HWND hwnd
)
219 pMsg
->message
= WM_KEYDOWN
;
220 pMsg
->wParam
= VK_TAB
;
221 pMsg
->lParam
= KeyDownData (1, 0x0F, 0, 0);
222 /* pMsg->time is not set. It shouldn't be needed */
223 /* pMsg->pt is ignored */
226 /* Form a WM_KEYDOWN VK_RETURN message to the specified window */
227 static void FormEnterMsg (MSG
*pMsg
, HWND hwnd
)
230 pMsg
->message
= WM_KEYDOWN
;
231 pMsg
->wParam
= VK_RETURN
;
232 pMsg
->lParam
= KeyDownData (1, 0x1C, 0, 0);
233 /* pMsg->time is not set. It shouldn't be needed */
234 /* pMsg->pt is ignored */
237 /***********************************************************************
244 int isok
; /* or is it todo */
253 static int id (HWND h
)
256 for (i
= 0; i
< numwnds
; i
++)
264 * Tests 1-8 test the hCtl argument of null or the dialog itself.
266 * 1. Prev Group of null is null
267 * 2. Prev Tab of null is null
268 * 3. Prev Group of hDlg in hDlg is null
269 * 4. Prev Tab of hDlg in hDlg is null
270 * 5. Next Group of null is first visible enabled child
271 * Check it skips invisible, disabled and both.
272 * 6. Next Tab of null is first visible enabled tabstop
273 * Check it skips invisible, disabled, nontabstop, and in combination.
274 * 7. Next Group of hDlg in hDlg is as of null
275 * 8. Next Tab of hDlg in hDlg is as of null
277 * Tests 9-14 test descent
279 * 9. DS_CONTROL does not result in descending the hierarchy for Tab Next
280 * 10. DS_CONTROL does not result in descending the hierarchy for Group Next
281 * 11. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Next
282 * 12. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Next
283 * 13. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Prev
284 * 14. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Prev
286 * Tests 15-24 are the basic Prev/Next Group tests
288 * 15. Next Group of a visible enabled non-group control is the next visible
289 * enabled non-group control, if there is one before the next group
290 * 16. Next Group of a visible enabled non-group control wraps around to the
291 * beginning of the group on finding a control that starts another group.
292 * Note that the group is in the middle of the dialog.
293 * 17. As 16 except note that the next group is started with a disabled
295 * 18. As 16 except note that the next group is started with an invisible
297 * 19. Next Group wraps around the controls of the dialog
298 * 20. Next Group is the same even if the initial control is disabled.
299 * 21. Next Group is the same even if the initial control is invisible.
300 * 22. Next Group is the same even if the initial control has the group style
301 * 23. Next Group returns the initial control if there is no visible enabled
302 * control in the group. (Initial control disabled and not group style).
303 * 24. Prev version of test 16.
304 * Prev Group of a visible enabled non-group control wraps around to the
305 * beginning of the group on finding a control that starts the group.
306 * Note that the group is in the middle of the dialog.
308 * In tests 25 to 28 the control is sitting under dialogs which do not have
309 * the WS_EX_CONTROLPARENT style and so cannot be reached from the top of
312 * 25. Next Group of an inaccessible control is as if it were accessible
313 * 26. Prev Group of an inaccessible control begins searching at the highest
314 * level ancestor that did not permit recursion down the hierarchy
315 * 27. Next Tab of an inaccessible control is as if it were accessible
316 * 28. Prev Tab of an inaccessible control begins searching at the highest
317 * level ancestor that did not permit recursion down the hierarchy.
319 * Tests 29- are the basic Tab tests
321 * 29. Next Tab of a control is the next visible enabled control with the
322 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
323 * 30. Prev Tab of a control is the previous visible enabled control with the
324 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
325 * 31. Next Tab test with at least two layers of descent and finding the
326 * result not at the first control.
327 * 32. Next Tab test with at least two layers of descent with the descent and
328 * control at the start of each level.
329 * 33. Prev Tab test with at least two layers of descent and finding the
330 * result not at the last control.
331 * 34. Prev Tab test with at least two layers of descent with the descent and
332 * control at the end of each level.
334 * 35. Passing NULL may result in the first child being the one returned.
336 * 36. Passing NULL may result in the first child being the one returned.
340 static void GetNextDlgItemTest (void)
342 static test_record test
[] =
344 /* isok test dlg ctl tab prev res */
346 { 1, 1, 6, 0, 0, 1, 0},
347 { 1, 2, 6, 0, 1, 1, 0},
348 { 1, 3, 6, 6, 0, 1, 0},
349 { 1, 4, 6, 6, 1, 1, 0},
350 { 1, 5, 6, 0, 0, 0, 66},
351 { 1, 6, 6, 0, 1, 0, 67},
352 { 1, 7, 6, 6, 0, 0, 66},
353 { 1, 8, 6, 6, 1, 0, 67},
355 { 1, 9, 4, 83, 1, 0, 84},
356 { 1, 10, 4, 83, 0, 0, 5},
357 { 1, 11, 5, 81, 1, 0, 67},
358 { 1, 12, 5, 81, 0, 0, 66},
359 { 1, 13, 5, 82, 1, 1, 78},
361 { 1, 14, 5, 82, 0, 1, 79},
362 { 1, 15, 6, 70, 0, 0, 72},
363 { 1, 16, 6, 72, 0, 0, 25},
364 { 1, 17, 6, 75, 0, 0, 26},
365 { 1, 18, 6, 77, 0, 0, 76},
366 { 1, 19, 6, 79, 0, 0, 66},
367 { 1, 20, 6, 71, 0, 0, 72},
368 { 1, 21, 6, 64, 0, 0, 66},
370 { 1, 22, 6, 25, 0, 0, 70},
371 { 1, 23, 6, 68, 0, 0, 68},
372 { 1, 24, 6, 25, 0, 1, 72},
373 { 1, 25, 1, 70, 0, 0, 72},
374 /*{ 0, 26, 1, 70, 0, 1, 3}, Crashes Win95*/
375 { 1, 27, 1, 70, 1, 0, 72},
376 /*{ 0, 28, 1, 70, 1, 1, 61}, Crashes Win95*/
378 { 1, 29, 6, 67, 1, 0, 72},
379 { 1, 30, 6, 72, 1, 1, 67},
381 { 1, 35, 2, 0, 0, 0, 60},
382 { 1, 36, 2, 0, 1, 0, 60},
384 { 0, 0, 0, 0, 0, 0, 0} /* End of test */
386 const test_record
*p
= test
;
388 ok (CreateWindows (g_hinst
), "Could not create test windows\n");
393 a
= (p
->tab
? GetNextDlgTabItem
: GetNextDlgGroupItem
) (hwnd
[p
->dlg
], hwnd
[p
->ctl
], p
->prev
);
396 ok (a
== hwnd
[p
->res
], "Test %d: %s %s item of %d in %d was %d instead of %d\n", p
->test
, p
->prev
? "Prev" : "Next", p
->tab
? "Tab" : "Group", p
->ctl
, p
->dlg
, id(a
), p
->res
);
402 ok (a
== hwnd
[p
->res
], "Test %d: %s %s item of %d in %d was actually %d matching expected %d\n", p
->test
, p
->prev
? "Prev" : "Next", p
->tab
? "Tab" : "Group", p
->ctl
, p
->dlg
, id(a
), p
->res
);
412 static BOOL
OnMainWindowCreate (HWND hwnd
, LPCREATESTRUCT lpcs
)
414 g_hwndButton1
= CreateWindow (TEXT("button"), TEXT("Button &1"),
415 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_DEFPUSHBUTTON
| BS_TEXT
,
416 10, 10, 80, 80, hwnd
, (HMENU
)100, g_hinst
, 0);
417 if (!g_hwndButton1
) return FALSE
;
419 g_hwndButton2
= CreateWindow (TEXT("button"), TEXT("Button &2"),
420 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_TEXT
,
421 110, 10, 80, 80, hwnd
, (HMENU
)200, g_hinst
, 0);
422 if (!g_hwndButton2
) return FALSE
;
424 g_hwndButtonCancel
= CreateWindow (TEXT("button"), TEXT("Cancel"),
425 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
426 210, 10, 80, 80, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
427 if (!g_hwndButtonCancel
) return FALSE
;
437 static BOOL
OnTestDlgCreate (HWND hwnd
, LPCREATESTRUCT lpcs
)
439 g_hwndTestDlgEdit
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
|
440 WS_EX_RIGHTSCROLLBAR
| WS_EX_NOPARENTNOTIFY
| WS_EX_CLIENTEDGE
,
441 TEXT("Edit"), TEXT("Edit"),
442 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| ES_LEFT
| ES_AUTOHSCROLL
,
443 16,33,184,24, hwnd
, (HMENU
)101, g_hinst
, 0);
444 if (!g_hwndTestDlgEdit
) return FALSE
;
446 g_hwndTestDlgBut1
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
447 | WS_EX_NOPARENTNOTIFY
,
448 TEXT("button"), TEXT("Button &1"),
449 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
450 204,33,30,24, hwnd
, (HMENU
)201, g_hinst
, 0);
451 if (!g_hwndTestDlgBut1
) return FALSE
;
453 g_hwndTestDlgBut2
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
454 | WS_EX_NOPARENTNOTIFY
, TEXT("button"),
456 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
457 90,102,80,24, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
458 if (!g_hwndTestDlgBut2
) return FALSE
;
463 static LRESULT CALLBACK
main_window_procA (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
469 /* Add blank case statements for these to ensure we don't use them
472 case DM_GETDEFID
: break;
473 case DM_SETDEFID
: break;
476 return (OnMainWindowCreate (hwnd
,
477 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
479 if (wParam
== IDCANCEL
)
487 result
=DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
491 static LRESULT CALLBACK
disabled_test_proc (HWND hwnd
, UINT uiMsg
,
492 WPARAM wParam
, LPARAM lParam
)
501 dw
= SendMessage(hwnd
, DM_GETDEFID
, 0, 0);
502 assert(DC_HASDEFID
== HIWORD(dw
));
503 hwndOk
= GetDlgItem(hwnd
, LOWORD(dw
));
505 EnableWindow(hwndOk
, FALSE
);
507 PostMessage(hwnd
, WM_KEYDOWN
, VK_RETURN
, 0);
508 PostMessage(hwnd
, WM_COMMAND
, IDCANCEL
, 0);
517 else if (wParam
== IDCANCEL
)
525 result
=DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
529 static LRESULT CALLBACK
testDlgWinProc (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
535 /* Add blank case statements for these to ensure we don't use them
538 case DM_GETDEFID
: break;
539 case DM_SETDEFID
: break;
542 return (OnTestDlgCreate (hwnd
,
543 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
546 result
=DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
550 static BOOL
RegisterWindowClasses (void)
555 cls
.lpfnWndProc
= DefWindowProcA
;
558 cls
.hInstance
= g_hinst
;
560 cls
.hCursor
= LoadCursorA (NULL
, IDC_ARROW
);
561 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
562 cls
.lpszMenuName
= NULL
;
563 cls
.lpszClassName
= "GetNextDlgItemWindowClass";
565 if (!RegisterClassA (&cls
)) return FALSE
;
567 cls
.lpfnWndProc
= main_window_procA
;
568 cls
.lpszClassName
= "IsDialogMessageWindowClass";
570 if (!RegisterClassA (&cls
)) return FALSE
;
572 GetClassInfoA(0, "#32770", &cls
);
573 cls
.lpfnWndProc
= testDlgWinProc
;
574 cls
.lpszClassName
= "WM_NEXTDLGCTLWndClass";
575 if (!RegisterClassA (&cls
)) return FALSE
;
580 static void WM_NEXTDLGCTLTest(void)
584 g_hwndTestDlg
= CreateWindowEx( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
585 | WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
| WS_EX_APPWINDOW
,
586 "WM_NEXTDLGCTLWndClass",
587 "WM_NEXTDLGCTL Message test window",
588 WS_POPUPWINDOW
| WS_CLIPSIBLINGS
| WS_DLGFRAME
| WS_OVERLAPPED
|
589 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| DS_3DLOOK
| DS_SETFONT
| DS_MODALFRAME
,
591 NULL
, NULL
, g_hinst
, 0);
593 assert (g_hwndTestDlg
);
594 assert (g_hwndTestDlgBut1
);
595 assert (g_hwndTestDlgBut2
);
596 assert (g_hwndTestDlgEdit
);
599 * Test message DM_SETDEFID
602 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, IDCANCEL
, 0 );
603 DefDlgProcA( g_hwndTestDlgBut1
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, FALSE
);
604 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
606 ok ( IDCANCEL
== (LOWORD(dwVal
)), "Did not set default ID\n" );
609 * Check whether message WM_NEXTDLGCTL is changing the focus to next control and if
610 * the destination control is a button, style of the button should be changed to
611 * BS_DEFPUSHBUTTON with out making it default.
615 * Keep the focus on Edit control.
618 if ( SetFocus( g_hwndTestDlgEdit
) )
620 ok ((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't set on Edit control\n");
623 * Test message WM_NEXTDLGCTL
625 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
626 ok ((GetFocus() == g_hwndTestDlgBut1
), "Focus didn't move to first button\n");
629 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
631 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
632 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
635 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
636 * the style of default button changed to BS_PUSHBUTTON.
638 if ( IDCANCEL
== (LOWORD(dwVal
)) )
640 ok ( ((GetWindowLong( g_hwndTestDlgBut1
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
641 "Button1 style not set to BS_DEFPUSHBUTTON\n" );
643 ok ( !((GetWindowLong( g_hwndTestDlgBut2
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
644 "Button2's style not chaged to BS_PUSHBUTTON\n" );
648 * Move focus to Button2 using "WM_NEXTDLGCTL"
650 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
651 ok ((GetFocus() == g_hwndTestDlgBut2
), "Focus didn't move to second button\n");
654 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
656 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
657 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
660 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
661 * the style of button which lost the focus changed to BS_PUSHBUTTON.
663 if ( IDCANCEL
== (LOWORD(dwVal
)) )
665 ok ( ((GetWindowLong( g_hwndTestDlgBut2
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
666 "Button2 style not set to BS_DEFPUSHBUTTON\n" );
668 ok ( !((GetWindowLong( g_hwndTestDlgBut1
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
669 "Button1's style not chaged to BS_PUSHBUTTON\n" );
673 * Move focus to Edit control using "WM_NEXTDLGCTL"
675 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
676 ok ((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't move to Edit control\n");
679 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
681 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
682 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
684 DestroyWindow(g_hwndTestDlg
);
687 static void IsDialogMessageWTest (void)
691 g_hwndMain
= CreateWindow ("IsDialogMessageWindowClass", "IsDialogMessageWindowClass",
693 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
694 NULL
, NULL
, g_hinst
, 0);
697 assert (g_hwndButton1
);
698 assert (g_hwndButtonCancel
);
700 /* The focus should initially be nowhere. The first TAB should take it
701 * to the first button. The second TAB should take it to the Cancel
704 FormTabMsg (&msg
, g_hwndMain
);
705 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle first TAB\n");
706 ok ((GetFocus() == g_hwndButton1
), "Focus did not move to first button\n");
707 FormTabMsg (&msg
, g_hwndButton1
);
708 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle second TAB\n");
709 ok ((GetFocus() == g_hwndButtonCancel
),
710 "Focus did not move to cancel button\n");
711 FormEnterMsg (&msg
, g_hwndButtonCancel
);
712 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle the ENTER\n");
713 ok (g_terminated
, "ENTER did not terminate\n");
717 static INT_PTR CALLBACK
delayFocusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
724 g_hwndInitialFocusGroupBox
= GetDlgItem(hDlg
,100);
725 g_hwndButton1
= GetDlgItem(hDlg
,200);
726 g_hwndButton2
= GetDlgItem(hDlg
,201);
727 g_hwndButtonCancel
= GetDlgItem(hDlg
,IDCANCEL
);
728 g_styleInitialFocusT1
= GetWindowLong(g_hwndInitialFocusGroupBox
, GWL_STYLE
);
730 /* Initially check the second radio button */
731 SendMessage(g_hwndButton1
, BM_SETCHECK
, BST_UNCHECKED
, 0);
732 SendMessage(g_hwndButton2
, BM_SETCHECK
, BST_CHECKED
, 0);
733 /* Continue testing after dialog initialization */
734 PostMessage(hDlg
, WM_USER
, 0, 0);
735 return g_bInitialFocusInitDlgResult
;
738 if (LOWORD(wParam
) == IDCANCEL
)
740 EndDialog(hDlg
, LOWORD(wParam
));
746 g_styleInitialFocusT2
= GetWindowLong(hDlg
, GWL_STYLE
);
747 g_hwndInitialFocusT1
= GetFocus();
749 g_hwndInitialFocusT2
= GetFocus();
750 PostMessage(hDlg
, WM_COMMAND
, IDCANCEL
, 0);
757 static INT_PTR CALLBACK
focusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
766 if (LOWORD(wParam
) == IDCANCEL
)
768 EndDialog(hDlg
, LOWORD(wParam
));
771 else if (LOWORD(wParam
) == 200)
773 if (HIWORD(wParam
) == EN_SETFOCUS
)
774 g_hwndInitialFocusT1
= (HWND
)lParam
;
782 /* Helper for InitialFocusTest */
783 static const char * GetHwndString(HWND hw
)
786 return "a null handle";
787 if (hw
== g_hwndMain
)
788 return "the dialog handle";
789 if (hw
== g_hwndInitialFocusGroupBox
)
790 return "the group box control";
791 if (hw
== g_hwndButton1
)
792 return "the first button";
793 if (hw
== g_hwndButton2
)
794 return "the second button";
795 if (hw
== g_hwndButtonCancel
)
796 return "the cancel button";
798 return "unknown handle";
801 static void InitialFocusTest (void)
804 * This test intentionally returns FALSE in response to WM_INITDIALOG
805 * without setting focus to a control. This is not allowed according to
806 * MSDN, but it is exactly what MFC's CFormView does.
808 * Since the WM_INITDIALOG handler returns FALSE without setting the focus,
809 * the focus should initially be NULL. Later, when we manually set focus to
810 * the dialog, the default handler should set focus to the first control that
811 * is "visible, not disabled, and has the WS_TABSTOP style" (MSDN). Because the
812 * second radio button has been checked, it should be the first control
813 * that meets these criteria and should receive the focus.
816 g_bInitialFocusInitDlgResult
= FALSE
;
817 g_hwndInitialFocusT1
= (HWND
) -1;
818 g_hwndInitialFocusT2
= (HWND
) -1;
819 g_styleInitialFocusT1
= -1;
820 g_styleInitialFocusT2
= -1;
822 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
824 ok (((g_styleInitialFocusT1
& WS_TABSTOP
) == 0),
825 "Error in wrc - Detected WS_TABSTOP as default style for GROUPBOX\n");
827 ok (((g_styleInitialFocusT2
& WS_VISIBLE
) == 0),
828 "Modal dialogs should not be shown until the message queue first goes empty\n");
830 ok ((g_hwndInitialFocusT1
== NULL
),
831 "Error in initial focus when WM_INITDIALOG returned FALSE: "
832 "Expected NULL focus, got %s (%p).\n",
833 GetHwndString(g_hwndInitialFocusT1
), g_hwndInitialFocusT1
);
835 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
836 "Error after first SetFocus() when WM_INITDIALOG returned FALSE: "
837 "Expected the second button (%p), got %s (%p).\n",
838 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
839 g_hwndInitialFocusT2
);
842 * This is the same as above, except WM_INITDIALOG is made to return TRUE.
843 * This should cause the focus to go to the second radio button right away
844 * and stay there (until the user indicates otherwise).
847 g_bInitialFocusInitDlgResult
= TRUE
;
848 g_hwndInitialFocusT1
= (HWND
) -1;
849 g_hwndInitialFocusT2
= (HWND
) -1;
850 g_styleInitialFocusT1
= -1;
851 g_styleInitialFocusT2
= -1;
853 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
855 ok ((g_hwndInitialFocusT1
== g_hwndButton2
),
856 "Error in initial focus when WM_INITDIALOG returned TRUE: "
857 "Expected the second button (%p), got %s (%p).\n",
858 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
859 g_hwndInitialFocusT2
);
861 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
862 "Error after first SetFocus() when WM_INITDIALOG returned TRUE: "
863 "Expected the second button (%p), got %s (%p).\n",
864 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
865 g_hwndInitialFocusT2
);
868 * If the dialog has DS_CONTROL and it's not visible then we shouldn't change focus */
873 DLGTEMPLATE
* pTemplate
;
875 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG", (LPSTR
)RT_DIALOG
);
876 hTemplate
= LoadResource(g_hinst
, hResource
);
877 pTemplate
= (LPDLGTEMPLATEA
)LockResource(hTemplate
);
879 g_hwndInitialFocusT1
= 0;
880 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
881 ok (hDlg
!= 0, "Failed to create test dialog.\n");
883 ok ((g_hwndInitialFocusT1
== 0),
884 "Focus should not be set for an invisible DS_CONTROL dialog %p.\n", g_hwndInitialFocusT1
);
890 static void test_GetDlgItemText(void)
895 strcpy(string
, "Overwrite Me");
896 ret
= GetDlgItemTextA(NULL
, 0, string
, sizeof(string
)/sizeof(string
[0]));
897 ok(!ret
, "GetDlgItemText(NULL) shouldn't have succeeded\n");
899 ok(string
[0] == '\0' || broken(!strcmp(string
, "Overwrite Me")),
900 "string retrieved using GetDlgItemText should have been NULL terminated\n");
903 static void test_DialogBoxParamA(void)
906 HWND hwnd_invalid
= (HWND
)0x4444;
908 SetLastError(0xdeadbeef);
909 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "IDD_DIALOG" , hwnd_invalid
, 0 , 0);
910 ok(0 == ret
|| broken(ret
== -1), "DialogBoxParamA returned %d, expected 0\n", ret
);
911 ok(ERROR_INVALID_WINDOW_HANDLE
== GetLastError() ||
912 broken(GetLastError() == 0xdeadbeef),
913 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n",GetLastError());
914 SetLastError(0xdeadbeef);
915 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "RESOURCE_INVALID" , 0, 0, 0);
916 ok(-1 == ret
, "DialogBoxParamA returned %d, expected -1\n", ret
);
917 ok(ERROR_RESOURCE_NAME_NOT_FOUND
== GetLastError() ||
918 broken(GetLastError() == 0xdeadbeef),
919 "got %d, expected ERROR_RESOURCE_NAME_NOT_FOUND\n",GetLastError());
922 static void test_DisabledDialogTest(void)
924 g_terminated
= FALSE
;
925 DialogBoxParam(g_hinst
, "IDD_DIALOG", NULL
, (DLGPROC
)disabled_test_proc
, 0);
926 ok(FALSE
== g_terminated
, "dialog with disabled ok button has been terminated\n");
931 g_hinst
= GetModuleHandleA (0);
933 if (!RegisterWindowClasses()) assert(0);
935 GetNextDlgItemTest();
936 IsDialogMessageWTest();
939 test_GetDlgItemText();
940 test_DialogBoxParamA();
941 test_DisabledDialogTest();