WM_NEXTDLGCTL should not change the default button ID (based on a
[wine/multimedia.git] / dlls / user / tests / dialog.c
blob52dcd8e4b06135e45b3f3fca9f83c11555b71be6
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
29 * normally be met.
32 #include <assert.h>
33 #include <stdio.h>
34 #include <stdarg.h>
36 #include "wine/test.h"
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winuser.h"
41 #define MAXHWNDS 1024
42 static HWND hwnd [MAXHWNDS];
43 static unsigned int numwnds=1; /* 0 is reserved for null */
45 /* Global handles */
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;
50 static int g_terminated;
52 typedef struct {
53 unsigned int id;
54 int parent;
55 DWORD style;
56 DWORD exstyle;
57 } h_entry;
59 static const h_entry hierarchy [] = {
60 /* 0 is reserved for the null window */
61 { 1, 0, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE},
62 { 20, 1, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
63 { 2, 1, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT},
64 { 60, 2, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
65 /* What happens with groups when the parent is disabled */
66 { 8, 2, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, WS_EX_CONTROLPARENT},
67 { 85, 8, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP, 0},
68 { 9, 8, WS_CHILD, WS_EX_CONTROLPARENT},
69 { 86, 9, WS_CHILD | WS_VISIBLE, 0},
70 { 87, 9, WS_CHILD | WS_VISIBLE, 0},
71 { 31, 8, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
72 { 10, 2, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT},
73 { 88, 10, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
74 { 11, 10, WS_CHILD, WS_EX_CONTROLPARENT},
75 { 89, 11, WS_CHILD | WS_VISIBLE, 0},
76 { 32, 11, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
77 { 90, 11, WS_CHILD | WS_VISIBLE, 0},
78 { 33, 10, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
79 { 21, 2, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
80 { 61, 2, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
81 { 3, 1, WS_CHILD | WS_VISIBLE | DS_CONTROL, 0},
82 { 22, 3, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
83 { 62, 3, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
84 { 7, 3, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT},
85 { 4, 7, WS_CHILD | WS_VISIBLE | DS_CONTROL, 0},
86 { 83, 4, WS_CHILD | WS_VISIBLE, 0},
87 { 5, 4, WS_CHILD | WS_VISIBLE | DS_CONTROL, 0},
88 /* A couple of controls around the main dialog */
89 { 29, 5, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
90 { 81, 5, WS_CHILD | WS_VISIBLE, 0},
91 /* The main dialog with lots of controls */
92 { 6, 5, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT},
93 /* At the start of a dialog */
94 /* Disabled controls are skipped */
95 { 63, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 0},
96 /* Invisible controls are skipped */
97 { 64, 6, WS_CHILD | WS_TABSTOP, 0},
98 /* Invisible disabled controls are skipped */
99 { 65, 6, WS_CHILD | WS_DISABLED | WS_TABSTOP, 0},
100 /* Non-tabstop controls are skipped for tabs but not for groups */
101 { 66, 6, WS_CHILD | WS_VISIBLE, 0},
102 /* End of first group, with no tabstops in it */
103 { 23, 6, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
104 /* At last a tabstop */
105 { 67, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
106 /* A group that is totally disabled or invisible */
107 { 24, 6, WS_CHILD | WS_DISABLED | WS_GROUP, 0},
108 { 68, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 0},
109 { 69, 6, WS_CHILD | WS_TABSTOP, 0},
110 /* A valid group in the middle of the dialog (not the first nor last group*/
111 { 25, 6, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
112 /* A non-tabstop item will be skipped for tabs */
113 { 70, 6, WS_CHILD | WS_VISIBLE, 0},
114 /* A disabled item will be skipped for tabs and groups */
115 { 71, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 0},
116 /* A valid item will be found for tabs and groups */
117 { 72, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
118 /* A disabled item to skip when looking for the next group item */
119 { 73, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 0},
120 /* The next group begins with an enabled visible label */
121 { 26, 6, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
122 { 74, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
123 { 75, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
124 /* That group is terminated by a disabled label */
125 { 27, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_GROUP, 0},
126 { 76, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
127 { 77, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
128 /* That group is terminated by an invisible label */
129 { 28, 6, WS_CHILD | WS_GROUP, 0},
130 /* The end of the dialog with item for loop and recursion testing */
131 { 78, 6, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
132 /* No tabstop so skipped for prev tab, but found for prev group */
133 { 79, 6, WS_CHILD | WS_VISIBLE, 0},
134 { 80, 6, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 0},
135 /* A couple of controls after the main dialog */
136 { 82, 5, WS_CHILD | WS_VISIBLE, 0},
137 { 30, 5, WS_CHILD | WS_VISIBLE | WS_GROUP, 0},
138 /* And around them */
139 { 84, 4, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0},
140 {0, 0, 0, 0}
143 static BOOL CreateWindows (HINSTANCE hinst)
145 const h_entry *p = hierarchy;
147 while (p->id != 0)
149 DWORD style, exstyle;
150 char ctrlname[9];
152 /* Basically assert that the hierarchy is valid and track the
153 * maximum control number
155 if (p->id >= numwnds)
157 if (p->id >= sizeof(hwnd)/sizeof(hwnd[0]))
159 trace ("Control %d is out of range\n", p->id);
160 return FALSE;
162 else
163 numwnds = p->id+1;
165 if (p->id <= 0)
167 trace ("Control %d is out of range\n", p->id);
168 return FALSE;
170 if (hwnd[p->id] != 0)
172 trace ("Control %d is used more than once\n", p->id);
173 return FALSE;
176 /* Create the control */
177 sprintf (ctrlname, "ctrl%4.4d", p->id);
178 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);
179 if (!hwnd[p->id])
181 trace ("Failed to create control %d\n", p->id);
182 return FALSE;
185 /* Check that the styles are as we specified (except the main one
186 * which is quite frequently messed up). If this keeps breaking then
187 * we could mask out the bits that don't concern us.
189 if (p->parent)
191 style = GetWindowLong (hwnd[p->id], GWL_STYLE);
192 exstyle = GetWindowLong (hwnd[p->id], GWL_EXSTYLE);
193 if (style == p->style && exstyle == p->exstyle)
195 trace ("Style mismatch at %d: %8.8lx %8.8lx cf %8.8lx %8.8lx\n", p->id, style, exstyle, p->style, p->exstyle);
198 p++;
201 return TRUE;
204 /* Form the lParam of a WM_KEYDOWN message */
205 static DWORD KeyDownData (int repeat, int scancode, int extended, int wasdown)
207 return ((repeat & 0x0000FFFF) | ((scancode & 0x00FF) >> 16) |
208 (extended ? 0x01000000 : 0) | (wasdown ? 0x40000000 : 0));
211 /* Form a WM_KEYDOWN VK_TAB message to the specified window */
212 static void FormTabMsg (MSG *pMsg, HWND hwnd)
214 pMsg->hwnd = hwnd;
215 pMsg->message = WM_KEYDOWN;
216 pMsg->wParam = VK_TAB;
217 pMsg->lParam = KeyDownData (1, 0x0F, 0, 0);
218 /* pMsg->time is not set. It shouldn't be needed */
219 /* pMsg->pt is ignored */
222 /* Form a WM_KEYDOWN VK_RETURN message to the specified window */
223 static void FormEnterMsg (MSG *pMsg, HWND hwnd)
225 pMsg->hwnd = hwnd;
226 pMsg->message = WM_KEYDOWN;
227 pMsg->wParam = VK_RETURN;
228 pMsg->lParam = KeyDownData (1, 0x1C, 0, 0);
229 /* pMsg->time is not set. It shouldn't be needed */
230 /* pMsg->pt is ignored */
233 /***********************************************************************
235 * The actual tests
238 typedef struct
240 int isok; /* or is it todo */
241 int test;
242 int dlg;
243 int ctl;
244 int tab;
245 int prev;
246 int res;
247 } test_record;
249 static int id (HWND h)
251 unsigned int i;
252 for (i = 0; i < numwnds; i++)
253 if (hwnd[i] == h)
254 return i;
255 return -1;
258 /* Tests
260 * Tests 1-8 test the hCtl argument of null or the dialog itself.
262 * 1. Prev Group of null is null
263 * 2. Prev Tab of null is null
264 * 3. Prev Group of hDlg in hDlg is null
265 * 4. Prev Tab of hDlg in hDlg is null
266 * 5. Next Group of null is first visible enabled child
267 * Check it skips invisible, diabled and both.
268 * 6. Next Tab of null is first visible enabled tabstop
269 * Check it skips invisible, disabled, nontabstop, and in combination.
270 * 7. Next Group of hDlg in hDlg is as of null
271 * 8. Next Tab of hDlg in hDlg is as of null
273 * Tests 9-14 test descent
275 * 9. DS_CONTROL does not result in descending the hierarchy for Tab Next
276 * 10. DS_CONTROL does not result in descending the hierarchy for Group Next
277 * 11. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Next
278 * 12. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Next
279 * 13. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Prev
280 * 14. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Prev
282 * Tests 15-24 are the basic Prev/Next Group tests
284 * 15. Next Group of a visible enabled non-group control is the next visible
285 * enabled non-group control, if there is one before the next group
286 * 16. Next Group of a visible enabled non-group control wraps around to the
287 * beginning of the group on finding a control that starts another group.
288 * Note that the group is in the middle of the dialog.
289 * 17. As 16 except note that the next group is started with a disabled
290 * visible control.
291 * 18. As 16 except note that the next group is started with an invisible
292 * enabled control.
293 * 19. Next Group wraps around the controls of the dialog
294 * 20. Next Group is the same even if the initial control is disabled.
295 * 21. Next Group is the same even if the initial control is invisible.
296 * 22. Next Group is the same even if the initial control has the group style
297 * 23. Next Group returns the initial control if there is no visible enabled
298 * control in the group. (Initial control disabled and not group style).
299 * 24. Prev version of test 16.
300 * Prev Group of a visible enabled non-group control wraps around to the
301 * beginning of the group on finding a control that starts the group.
302 * Note that the group is in the middle of the dialog.
304 * In tests 25 to 28 the control is sitting under dialogs which do not have
305 * the WS_EX_CONTROLPARENT style and so cannot be reached from the top of
306 * the dialog.
308 * 25. Next Group of an inaccessible control is as if it were accessible
309 * 26. Prev Group of an inaccessible control begins searching at the highest
310 * level ancestor that did not permit recursion down the hierarchy
311 * 27. Next Tab of an inaccessible control is as if it were accessible
312 * 28. Prev Tab of an inaccessible control begins searching at the highest
313 * level ancestor that did not permit recursion down the hierarchy.
315 * Tests 29- are the basic Tab tests
317 * 29. Next Tab of a control is the next visible enabled control with the
318 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
319 * 30. Prev Tab of a control is the previous visible enabled control with the
320 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
321 * 31. Next Tab test with at least two layers of descent and finding the
322 * result not at the first control.
323 * 32. Next Tab test with at least two layers of descent with the descent and
324 * control at the start of each level.
325 * 33. Prev Tab test with at least two layers of descent and finding the
326 * result not at the last control.
327 * 34. Prev Tab test with at least two layers of descent with the descent and
328 * control at the end of each level.
330 * 35. Passing NULL may result in the first child being the one returned.
331 * (group test)
332 * 36. Passing NULL may result in the first child being the one returned.
333 * (tab test)
336 static void GetNextDlgItemTest (void)
338 static test_record test [] =
340 /* isok test dlg ctl tab prev res */
342 { 1, 1, 6, 0, 0, 1, 0},
343 { 1, 2, 6, 0, 1, 1, 0},
344 { 1, 3, 6, 6, 0, 1, 0},
345 { 1, 4, 6, 6, 1, 1, 0},
346 { 1, 5, 6, 0, 0, 0, 66},
347 { 1, 6, 6, 0, 1, 0, 67},
348 { 1, 7, 6, 6, 0, 0, 66},
349 { 1, 8, 6, 6, 1, 0, 67},
351 { 1, 9, 4, 83, 1, 0, 84},
352 { 1, 10, 4, 83, 0, 0, 5},
353 { 1, 11, 5, 81, 1, 0, 67},
354 { 1, 12, 5, 81, 0, 0, 66},
355 { 1, 13, 5, 82, 1, 1, 78},
357 { 1, 14, 5, 82, 0, 1, 79},
358 { 1, 15, 6, 70, 0, 0, 72},
359 { 1, 16, 6, 72, 0, 0, 25},
360 { 1, 17, 6, 75, 0, 0, 26},
361 { 1, 18, 6, 77, 0, 0, 76},
362 { 1, 19, 6, 79, 0, 0, 66},
363 { 1, 20, 6, 71, 0, 0, 72},
364 { 1, 21, 6, 64, 0, 0, 66},
366 { 1, 22, 6, 25, 0, 0, 70},
367 { 1, 23, 6, 68, 0, 0, 68},
368 { 1, 24, 6, 25, 0, 1, 72},
369 { 1, 25, 1, 70, 0, 0, 72},
370 /*{ 0, 26, 1, 70, 0, 1, 3}, Crashes Win95*/
371 { 1, 27, 1, 70, 1, 0, 72},
372 /*{ 0, 28, 1, 70, 1, 1, 61}, Crashes Win95*/
374 { 1, 29, 6, 67, 1, 0, 72},
375 { 1, 30, 6, 72, 1, 1, 67},
377 { 1, 35, 2, 0, 0, 0, 60},
378 { 1, 36, 2, 0, 1, 0, 60},
380 { 0, 0, 0, 0, 0, 0, 0} /* End of test */
382 const test_record *p = test;
384 ok (CreateWindows (g_hinst), "Could not create test windows\n");
386 while (p->dlg)
388 HWND a;
389 a = (p->tab ? GetNextDlgTabItem : GetNextDlgGroupItem) (hwnd[p->dlg], hwnd[p->ctl], p->prev);
390 if (p->isok)
392 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);
394 else
396 todo_wine
398 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);
401 p++;
406 * OnMainWindowCreate
408 static BOOL OnMainWindowCreate (HWND hwnd, LPCREATESTRUCT lpcs)
410 g_hwndButton1 = CreateWindow (TEXT("button"), TEXT("Button &1"),
411 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON | BS_TEXT,
412 10, 10, 80, 80, hwnd, (HMENU)100, g_hinst, 0);
413 if (!g_hwndButton1) return FALSE;
415 g_hwndButton2 = CreateWindow (TEXT("button"), TEXT("Button &2"),
416 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
417 110, 10, 80, 80, hwnd, (HMENU)200, g_hinst, 0);
418 if (!g_hwndButton2) return FALSE;
420 g_hwndButtonCancel = CreateWindow (TEXT("button"), TEXT("Cancel"),
421 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT,
422 210, 10, 80, 80, hwnd, (HMENU)IDCANCEL, g_hinst, 0);
423 if (!g_hwndButtonCancel) return FALSE;
425 return TRUE;
430 * OnTestDlgCreate
433 static BOOL OnTestDlgCreate (HWND hwnd, LPCREATESTRUCT lpcs)
435 g_hwndTestDlgEdit = CreateWindowEx ( WS_EX_LEFT | WS_EX_LTRREADING |
436 WS_EX_RIGHTSCROLLBAR | WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE,
437 TEXT("Edit"), TEXT("Edit"),
438 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_AUTOHSCROLL,
439 16,33,184,24, hwnd, (HMENU)101, g_hinst, 0);
440 if (!g_hwndTestDlgEdit) return FALSE;
442 g_hwndTestDlgBut1 = CreateWindowEx ( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR
443 | WS_EX_NOPARENTNOTIFY,
444 TEXT("button"), TEXT("Button &1"),
445 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT,
446 204,33,30,24, hwnd, (HMENU)201, g_hinst, 0);
447 if (!g_hwndTestDlgBut1) return FALSE;
449 g_hwndTestDlgBut2 = CreateWindowEx ( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR
450 | WS_EX_NOPARENTNOTIFY, TEXT("button"),
451 TEXT("Button &2"),
452 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT,
453 90,102,80,24, hwnd, (HMENU)IDCANCEL, g_hinst, 0);
454 if (!g_hwndTestDlgBut2) return FALSE;
456 return TRUE;
460 static LRESULT CALLBACK main_window_procA (HWND hwnd, UINT uiMsg, WPARAM wParam,
461 LPARAM lParam)
463 LRESULT result;
464 switch (uiMsg)
466 /* Add blank case statements for these to ensure we don't use them
467 * by mistake.
469 case DM_GETDEFID: break;
470 case DM_SETDEFID: break;
472 case WM_CREATE:
473 return (OnMainWindowCreate (hwnd,
474 (LPCREATESTRUCTA) lParam) ? 0 : (LRESULT) -1);
475 case WM_COMMAND:
476 if (wParam == IDCANCEL)
478 g_terminated = TRUE;
479 return 0;
481 break;
484 result=DefWindowProcA (hwnd, uiMsg, wParam, lParam);
485 return result;
488 static LRESULT CALLBACK testDlgWinProc (HWND hwnd, UINT uiMsg, WPARAM wParam,
489 LPARAM lParam)
491 LRESULT result;
492 switch (uiMsg)
494 /* Add blank case statements for these to ensure we don't use them
495 * by mistake.
497 case DM_GETDEFID: break;
498 case DM_SETDEFID: break;
500 case WM_CREATE:
501 return (OnTestDlgCreate (hwnd,
502 (LPCREATESTRUCTA) lParam) ? 0 : (LRESULT) -1);
505 result=DefWindowProcA (hwnd, uiMsg, wParam, lParam);
506 return result;
509 static BOOL RegisterWindowClasses (void)
511 WNDCLASSA cls;
513 cls.style = 0;
514 cls.lpfnWndProc = DefWindowProcA;
515 cls.cbClsExtra = 0;
516 cls.cbWndExtra = 0;
517 cls.hInstance = g_hinst;
518 cls.hIcon = NULL;
519 cls.hCursor = LoadCursorA (NULL, IDC_ARROW);
520 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
521 cls.lpszMenuName = NULL;
522 cls.lpszClassName = "GetNextDlgItemWindowClass";
524 if (!RegisterClassA (&cls)) return FALSE;
526 cls.lpfnWndProc = main_window_procA;
527 cls.lpszClassName = "IsDialogMessageWindowClass";
529 if (!RegisterClassA (&cls)) return FALSE;
531 GetClassInfoA(0, "#32770", &cls);
532 cls.lpfnWndProc = testDlgWinProc;
533 cls.lpszClassName = "WM_NEXTDLGCTLWndClass";
534 if (!RegisterClassA (&cls)) return FALSE;
536 return TRUE;
539 static void WM_NEXTDLGCTLTest(void)
541 DWORD dwVal;
543 g_hwndTestDlg = CreateWindowEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR
544 | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW,
545 "WM_NEXTDLGCTLWndClass",
546 "WM_NEXTDLGCTL Message test window",
547 WS_POPUPWINDOW | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_OVERLAPPED |
548 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | DS_3DLOOK | DS_SETFONT | DS_MODALFRAME,
549 0, 0, 235, 135,
550 NULL, NULL, g_hinst, 0);
552 assert (g_hwndTestDlg);
553 assert (g_hwndTestDlgBut1);
554 assert (g_hwndTestDlgBut2);
555 assert (g_hwndTestDlgEdit);
558 * Test message DM_SETDEFID
561 DefDlgProcA( g_hwndTestDlg, DM_SETDEFID, IDCANCEL, 0 );
562 DefDlgProcA( g_hwndTestDlgBut1, BM_SETSTYLE, BS_DEFPUSHBUTTON, FALSE );
563 dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0);
565 ok ( IDCANCEL == (LOWORD(dwVal)), "Did not set default ID" );
568 * Check whether message WM_NEXTDLGCTL is changing the focus to next control and if
569 * the destination control is a button, style of the button should be changed to
570 * BS_DEFPUSHBUTTON with out making it default.
574 * Keep the focus on Edit control.
577 if ( SetFocus( g_hwndTestDlgEdit ) )
579 ok ((GetFocus() == g_hwndTestDlgEdit), "Focus didn't set on Edit control\n");
582 * Test message WM_NEXTDLGCTL
584 DefDlgProcA( g_hwndTestDlg, WM_NEXTDLGCTL, 0, 0 );
585 ok ((GetFocus() == g_hwndTestDlgBut1), "Focus didn't move to first button\n");
588 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
590 dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0);
591 ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n");
594 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
595 * the style of default button changed to BS_PUSHBUTTON.
597 if ( IDCANCEL == (LOWORD(dwVal)) )
599 ok ( ((GetWindowLong( g_hwndTestDlgBut1, GWL_STYLE)) & BS_DEFPUSHBUTTON),
600 "Button1 style not set to BS_DEFPUSHBUTTON\n" );
602 ok ( !((GetWindowLong( g_hwndTestDlgBut2, GWL_STYLE)) & BS_DEFPUSHBUTTON),
603 "Button2's style not chaged to BS_PUSHBUTTON\n" );
607 * Move focus to Button2 using "WM_NEXTDLGCTL"
609 DefDlgProcA( g_hwndTestDlg, WM_NEXTDLGCTL, 0, 0 );
610 ok ((GetFocus() == g_hwndTestDlgBut2), "Focus didn't move to second button\n");
613 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
615 dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0);
616 ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n");
619 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
620 * the style of button which lost the focus changed to BS_PUSHBUTTON.
622 if ( IDCANCEL == (LOWORD(dwVal)) )
624 ok ( ((GetWindowLong( g_hwndTestDlgBut2, GWL_STYLE)) & BS_DEFPUSHBUTTON),
625 "Button2 style not set to BS_DEFPUSHBUTTON\n" );
627 ok ( !((GetWindowLong( g_hwndTestDlgBut1, GWL_STYLE)) & BS_DEFPUSHBUTTON),
628 "Button1's style not chaged to BS_PUSHBUTTON\n" );
632 * Move focus to Edit control using "WM_NEXTDLGCTL"
634 DefDlgProcA( g_hwndTestDlg, WM_NEXTDLGCTL, 0, 0 );
635 ok ((GetFocus() == g_hwndTestDlgEdit), "Focus didn't move to Edit control\n");
638 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
640 dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0);
641 ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n");
645 static void IsDialogMessageWTest (void)
647 MSG msg;
649 g_hwndMain = CreateWindow ("IsDialogMessageWindowClass", "IsDialogMessageWindowClass",
650 WS_OVERLAPPEDWINDOW,
651 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
652 NULL, NULL, g_hinst, 0);
654 assert (g_hwndMain);
655 assert (g_hwndButton1);
656 assert (g_hwndButtonCancel);
658 /* The focus should initially be nowhere. The first TAB should take it
659 * to the first button. The second TAB should take it to the Cancel
660 * button.
662 FormTabMsg (&msg, g_hwndMain);
663 ok (IsDialogMessage (g_hwndMain, &msg), "Did not handle first TAB\n");
664 ok ((GetFocus() == g_hwndButton1), "Focus did not move to first button\n");
665 FormTabMsg (&msg, g_hwndButton1);
666 ok (IsDialogMessage (g_hwndMain, &msg), "Did not handle second TAB\n");
667 ok ((GetFocus() == g_hwndButtonCancel),
668 "Focus did not move to cancel button\n");
669 FormEnterMsg (&msg, g_hwndButtonCancel);
670 ok (IsDialogMessage (g_hwndMain, &msg), "Did not handle the ENTER\n");
671 ok (g_terminated, "ENTER did not terminate\n");
674 START_TEST(dialog)
676 g_hinst = GetModuleHandleA (0);
678 if (!RegisterWindowClasses()) assert(0);
680 GetNextDlgItemTest();
681 IsDialogMessageWTest();
682 WM_NEXTDLGCTLTest();