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
37 #define WINVER 0x0600 /* For NONCLIENTMETRICS with padding */
39 #include "wine/test.h"
46 static HWND hwnd
[MAXHWNDS
];
47 static unsigned int numwnds
=1; /* 0 is reserved for null */
50 static HINSTANCE g_hinst
; /* This application's HINSTANCE */
51 static HWND g_hwndMain
, g_hwndButton1
, g_hwndButton2
, g_hwndButtonCancel
;
52 static HWND g_hwndTestDlg
, g_hwndTestDlgBut1
, g_hwndTestDlgBut2
, g_hwndTestDlgEdit
;
53 static HWND g_hwndInitialFocusT1
, g_hwndInitialFocusT2
, g_hwndInitialFocusGroupBox
;
55 static LONG g_styleInitialFocusT1
, g_styleInitialFocusT2
;
56 static BOOL g_bInitialFocusInitDlgResult
, g_bReceivedCommand
;
58 static int g_terminated
;
67 static const h_entry hierarchy
[] = {
68 /* 0 is reserved for the null window */
69 { 1, 0, WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
},
70 { 20, 1, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
71 { 2, 1, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
72 { 60, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
73 /* What happens with groups when the parent is disabled */
74 { 8, 2, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, WS_EX_CONTROLPARENT
},
75 { 85, 8, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_GROUP
, 0},
76 { 9, 8, WS_CHILD
, WS_EX_CONTROLPARENT
},
77 { 86, 9, WS_CHILD
| WS_VISIBLE
, 0},
78 { 87, 9, WS_CHILD
| WS_VISIBLE
, 0},
79 { 31, 8, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
80 { 10, 2, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
81 { 88, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
82 { 11, 10, WS_CHILD
, WS_EX_CONTROLPARENT
},
83 { 89, 11, WS_CHILD
| WS_VISIBLE
, 0},
84 { 32, 11, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
85 { 90, 11, WS_CHILD
| WS_VISIBLE
, 0},
86 { 33, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
87 { 21, 2, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
88 { 61, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
89 { 3, 1, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
90 { 22, 3, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
91 { 62, 3, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
92 { 7, 3, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
93 { 4, 7, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
94 { 83, 4, WS_CHILD
| WS_VISIBLE
, 0},
95 { 5, 4, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
96 /* A couple of controls around the main dialog */
97 { 29, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
98 { 81, 5, WS_CHILD
| WS_VISIBLE
, 0},
99 /* The main dialog with lots of controls */
100 { 6, 5, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
101 /* At the start of a dialog */
102 /* Disabled controls are skipped */
103 { 63, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
104 /* Invisible controls are skipped */
105 { 64, 6, WS_CHILD
| WS_TABSTOP
, 0},
106 /* Invisible disabled controls are skipped */
107 { 65, 6, WS_CHILD
| WS_DISABLED
| WS_TABSTOP
, 0},
108 /* Non-tabstop controls are skipped for tabs but not for groups */
109 { 66, 6, WS_CHILD
| WS_VISIBLE
, 0},
110 /* End of first group, with no tabstops in it */
111 { 23, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
112 /* At last a tabstop */
113 { 67, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
114 /* A group that is totally disabled or invisible */
115 { 24, 6, WS_CHILD
| WS_DISABLED
| WS_GROUP
, 0},
116 { 68, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
117 { 69, 6, WS_CHILD
| WS_TABSTOP
, 0},
118 /* A valid group in the middle of the dialog (not the first nor last group*/
119 { 25, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
120 /* A non-tabstop item will be skipped for tabs */
121 { 70, 6, WS_CHILD
| WS_VISIBLE
, 0},
122 /* A disabled item will be skipped for tabs and groups */
123 { 71, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
124 /* A valid item will be found for tabs and groups */
125 { 72, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
126 /* A disabled item to skip when looking for the next group item */
127 { 73, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
128 /* The next group begins with an enabled visible label */
129 { 26, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
130 { 74, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
131 { 75, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
132 /* That group is terminated by a disabled label */
133 { 27, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_GROUP
, 0},
134 { 76, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
135 { 77, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
136 /* That group is terminated by an invisible label */
137 { 28, 6, WS_CHILD
| WS_GROUP
, 0},
138 /* The end of the dialog with item for loop and recursion testing */
139 { 78, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
140 /* No tabstop so skipped for prev tab, but found for prev group */
141 { 79, 6, WS_CHILD
| WS_VISIBLE
, 0},
142 { 80, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
143 /* A couple of controls after the main dialog */
144 { 82, 5, WS_CHILD
| WS_VISIBLE
, 0},
145 { 30, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
146 /* And around them */
147 { 84, 4, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
151 static BOOL
CreateWindows (HINSTANCE hinst
)
153 const h_entry
*p
= hierarchy
;
157 DWORD style
, exstyle
;
160 /* Basically assert that the hierarchy is valid and track the
161 * maximum control number
163 if (p
->id
>= numwnds
)
165 if (p
->id
>= sizeof(hwnd
)/sizeof(hwnd
[0]))
167 trace ("Control %ld is out of range\n", p
->id
);
175 trace ("Control %ld is out of range\n", p
->id
);
178 if (hwnd
[p
->id
] != 0)
180 trace ("Control %ld is used more than once\n", p
->id
);
184 /* Create the control */
185 sprintf (ctrlname
, "ctrl%4.4ld", p
->id
);
186 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);
189 trace ("Failed to create control %ld\n", p
->id
);
193 /* Check that the styles are as we specified (except the main one
194 * which is quite frequently messed up). If this keeps breaking then
195 * we could mask out the bits that don't concern us.
199 style
= GetWindowLong (hwnd
[p
->id
], GWL_STYLE
);
200 exstyle
= GetWindowLong (hwnd
[p
->id
], GWL_EXSTYLE
);
201 if (style
!= p
->style
|| exstyle
!= p
->exstyle
)
203 trace ("Style mismatch at %ld: %8.8x %8.8x cf %8.8x %8.8x\n", p
->id
, style
, exstyle
, p
->style
, p
->exstyle
);
212 /* Form the lParam of a WM_KEYDOWN message */
213 static DWORD
KeyDownData (int repeat
, int scancode
, int extended
, int wasdown
)
215 return ((repeat
& 0x0000FFFF) | ((scancode
& 0x00FF) << 16) |
216 (extended
? 0x01000000 : 0) | (wasdown
? 0x40000000 : 0));
219 /* Form a WM_KEYDOWN VK_TAB message to the specified window */
220 static void FormTabMsg (MSG
*pMsg
, HWND hwnd
)
223 pMsg
->message
= WM_KEYDOWN
;
224 pMsg
->wParam
= VK_TAB
;
225 pMsg
->lParam
= KeyDownData (1, 0x0F, 0, 0);
226 /* pMsg->time is not set. It shouldn't be needed */
227 /* pMsg->pt is ignored */
230 /* Form a WM_KEYDOWN VK_RETURN message to the specified window */
231 static void FormEnterMsg (MSG
*pMsg
, HWND hwnd
)
234 pMsg
->message
= WM_KEYDOWN
;
235 pMsg
->wParam
= VK_RETURN
;
236 pMsg
->lParam
= KeyDownData (1, 0x1C, 0, 0);
237 /* pMsg->time is not set. It shouldn't be needed */
238 /* pMsg->pt is ignored */
241 /***********************************************************************
248 int isok
; /* or is it todo */
257 static int id (HWND h
)
260 for (i
= 0; i
< numwnds
; i
++)
268 * Tests 1-8 test the hCtl argument of null or the dialog itself.
270 * 1. Prev Group of null is null
271 * 2. Prev Tab of null is null
272 * 3. Prev Group of hDlg in hDlg is null
273 * 4. Prev Tab of hDlg in hDlg is null
274 * 5. Next Group of null is first visible enabled child
275 * Check it skips invisible, disabled and both.
276 * 6. Next Tab of null is first visible enabled tabstop
277 * Check it skips invisible, disabled, nontabstop, and in combination.
278 * 7. Next Group of hDlg in hDlg is as of null
279 * 8. Next Tab of hDlg in hDlg is as of null
281 * Tests 9-14 test descent
283 * 9. DS_CONTROL does not result in descending the hierarchy for Tab Next
284 * 10. DS_CONTROL does not result in descending the hierarchy for Group Next
285 * 11. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Next
286 * 12. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Next
287 * 13. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Prev
288 * 14. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Prev
290 * Tests 15-24 are the basic Prev/Next Group tests
292 * 15. Next Group of a visible enabled non-group control is the next visible
293 * enabled non-group control, if there is one before the next group
294 * 16. Next Group of a visible enabled non-group control wraps around to the
295 * beginning of the group on finding a control that starts another group.
296 * Note that the group is in the middle of the dialog.
297 * 17. As 16 except note that the next group is started with a disabled
299 * 18. As 16 except note that the next group is started with an invisible
301 * 19. Next Group wraps around the controls of the dialog
302 * 20. Next Group is the same even if the initial control is disabled.
303 * 21. Next Group is the same even if the initial control is invisible.
304 * 22. Next Group is the same even if the initial control has the group style
305 * 23. Next Group returns the initial control if there is no visible enabled
306 * control in the group. (Initial control disabled and not group style).
307 * 24. Prev version of test 16.
308 * Prev Group of a visible enabled non-group control wraps around to the
309 * beginning of the group on finding a control that starts the group.
310 * Note that the group is in the middle of the dialog.
312 * In tests 25 to 28 the control is sitting under dialogs which do not have
313 * the WS_EX_CONTROLPARENT style and so cannot be reached from the top of
316 * 25. Next Group of an inaccessible control is as if it were accessible
317 * 26. Prev Group of an inaccessible control begins searching at the highest
318 * level ancestor that did not permit recursion down the hierarchy
319 * 27. Next Tab of an inaccessible control is as if it were accessible
320 * 28. Prev Tab of an inaccessible control begins searching at the highest
321 * level ancestor that did not permit recursion down the hierarchy.
323 * Tests 29- are the basic Tab tests
325 * 29. Next Tab of a control is the next visible enabled control with the
326 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
327 * 30. Prev Tab of a control is the previous visible enabled control with the
328 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
329 * 31. Next Tab test with at least two layers of descent and finding the
330 * result not at the first control.
331 * 32. Next Tab test with at least two layers of descent with the descent and
332 * control at the start of each level.
333 * 33. Prev Tab test with at least two layers of descent and finding the
334 * result not at the last control.
335 * 34. Prev Tab test with at least two layers of descent with the descent and
336 * control at the end of each level.
338 * 35. Passing NULL may result in the first child being the one returned.
340 * 36. Passing NULL may result in the first child being the one returned.
344 static void test_GetNextDlgItem(void)
346 static test_record test
[] =
348 /* isok test dlg ctl tab prev res */
350 { 1, 1, 6, 0, 0, 1, 0},
351 { 1, 2, 6, 0, 1, 1, 0},
352 { 1, 3, 6, 6, 0, 1, 0},
353 { 1, 4, 6, 6, 1, 1, 0},
354 { 1, 5, 6, 0, 0, 0, 66},
355 { 1, 6, 6, 0, 1, 0, 67},
356 { 1, 7, 6, 6, 0, 0, 66},
357 { 1, 8, 6, 6, 1, 0, 67},
359 { 1, 9, 4, 83, 1, 0, 84},
360 { 1, 10, 4, 83, 0, 0, 5},
361 { 1, 11, 5, 81, 1, 0, 67},
362 { 1, 12, 5, 81, 0, 0, 66},
363 { 1, 13, 5, 82, 1, 1, 78},
365 { 1, 14, 5, 82, 0, 1, 79},
366 { 1, 15, 6, 70, 0, 0, 72},
367 { 1, 16, 6, 72, 0, 0, 25},
368 { 1, 17, 6, 75, 0, 0, 26},
369 { 1, 18, 6, 77, 0, 0, 76},
370 { 1, 19, 6, 79, 0, 0, 66},
371 { 1, 20, 6, 71, 0, 0, 72},
372 { 1, 21, 6, 64, 0, 0, 66},
374 { 1, 22, 6, 25, 0, 0, 70},
375 { 1, 23, 6, 68, 0, 0, 68},
376 { 1, 24, 6, 25, 0, 1, 72},
377 { 1, 25, 1, 70, 0, 0, 72},
378 /*{ 0, 26, 1, 70, 0, 1, 3}, Crashes Win95*/
379 { 1, 27, 1, 70, 1, 0, 72},
380 /*{ 0, 28, 1, 70, 1, 1, 61}, Crashes Win95*/
382 { 1, 29, 6, 67, 1, 0, 72},
383 { 1, 30, 6, 72, 1, 1, 67},
385 { 1, 35, 2, 0, 0, 0, 60},
386 { 1, 36, 2, 0, 1, 0, 60},
388 { 0, 0, 0, 0, 0, 0, 0} /* End of test */
390 const test_record
*p
= test
;
392 ok (CreateWindows (g_hinst
), "Could not create test windows\n");
397 a
= (p
->tab
? GetNextDlgTabItem
: GetNextDlgGroupItem
) (hwnd
[p
->dlg
], hwnd
[p
->ctl
], p
->prev
);
400 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
);
406 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
);
416 static BOOL
OnMainWindowCreate (HWND hwnd
, LPCREATESTRUCT lpcs
)
418 g_hwndButton1
= CreateWindow (TEXT("button"), TEXT("Button &1"),
419 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_DEFPUSHBUTTON
| BS_TEXT
,
420 10, 10, 80, 80, hwnd
, (HMENU
)100, g_hinst
, 0);
421 if (!g_hwndButton1
) return FALSE
;
423 g_hwndButton2
= CreateWindow (TEXT("button"), TEXT("Button &2"),
424 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_TEXT
,
425 110, 10, 80, 80, hwnd
, (HMENU
)200, g_hinst
, 0);
426 if (!g_hwndButton2
) return FALSE
;
428 g_hwndButtonCancel
= CreateWindow (TEXT("button"), TEXT("Cancel"),
429 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
430 210, 10, 80, 80, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
431 if (!g_hwndButtonCancel
) return FALSE
;
441 static BOOL
OnTestDlgCreate (HWND hwnd
, LPCREATESTRUCT lpcs
)
443 g_hwndTestDlgEdit
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
|
444 WS_EX_RIGHTSCROLLBAR
| WS_EX_NOPARENTNOTIFY
| WS_EX_CLIENTEDGE
,
445 TEXT("Edit"), TEXT("Edit"),
446 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| ES_LEFT
| ES_AUTOHSCROLL
,
447 16,33,184,24, hwnd
, (HMENU
)101, g_hinst
, 0);
448 if (!g_hwndTestDlgEdit
) return FALSE
;
450 g_hwndTestDlgBut1
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
451 | WS_EX_NOPARENTNOTIFY
,
452 TEXT("button"), TEXT("Button &1"),
453 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
454 204,33,30,24, hwnd
, (HMENU
)201, g_hinst
, 0);
455 if (!g_hwndTestDlgBut1
) return FALSE
;
457 g_hwndTestDlgBut2
= CreateWindowEx ( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
458 | WS_EX_NOPARENTNOTIFY
, TEXT("button"),
460 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
461 90,102,80,24, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
462 if (!g_hwndTestDlgBut2
) return FALSE
;
467 static LRESULT CALLBACK
main_window_procA (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
472 /* Add blank case statements for these to ensure we don't use them
475 case DM_GETDEFID
: break;
476 case DM_SETDEFID
: break;
479 return (OnMainWindowCreate (hwnd
,
480 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
482 if (wParam
== IDCANCEL
)
490 return DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
493 static LRESULT CALLBACK
disabled_test_proc (HWND hwnd
, UINT uiMsg
,
494 WPARAM wParam
, LPARAM lParam
)
503 dw
= SendMessage(hwnd
, DM_GETDEFID
, 0, 0);
504 assert(DC_HASDEFID
== HIWORD(dw
));
505 hwndOk
= GetDlgItem(hwnd
, LOWORD(dw
));
507 EnableWindow(hwndOk
, FALSE
);
509 PostMessage(hwnd
, WM_KEYDOWN
, VK_RETURN
, 0);
510 PostMessage(hwnd
, WM_COMMAND
, IDCANCEL
, 0);
520 else if (wParam
== IDCANCEL
)
528 return DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
531 static LRESULT CALLBACK
testDlgWinProc (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
536 /* Add blank case statements for these to ensure we don't use them
539 case DM_GETDEFID
: break;
540 case DM_SETDEFID
: break;
543 return (OnTestDlgCreate (hwnd
,
544 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
546 if(LOWORD(wParam
) == 300) g_bReceivedCommand
= TRUE
;
549 return DefDlgProcA (hwnd
, uiMsg
, wParam
, lParam
);
552 static BOOL
RegisterWindowClasses (void)
557 cls
.lpfnWndProc
= DefWindowProcA
;
560 cls
.hInstance
= g_hinst
;
562 cls
.hCursor
= LoadCursorA (NULL
, IDC_ARROW
);
563 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
564 cls
.lpszMenuName
= NULL
;
565 cls
.lpszClassName
= "GetNextDlgItemWindowClass";
567 if (!RegisterClassA (&cls
)) return FALSE
;
569 cls
.lpfnWndProc
= main_window_procA
;
570 cls
.lpszClassName
= "IsDialogMessageWindowClass";
572 if (!RegisterClassA (&cls
)) return FALSE
;
574 GetClassInfoA(0, "#32770", &cls
);
575 cls
.lpfnWndProc
= testDlgWinProc
;
576 cls
.lpszClassName
= "WM_NEXTDLGCTLWndClass";
577 if (!RegisterClassA (&cls
)) return FALSE
;
582 static void test_WM_NEXTDLGCTL(void)
584 HWND child1
, child2
, child3
;
588 g_hwndTestDlg
= CreateWindowEx( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
589 | WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
| WS_EX_APPWINDOW
,
590 "WM_NEXTDLGCTLWndClass",
591 "WM_NEXTDLGCTL Message test window",
592 WS_POPUPWINDOW
| WS_CLIPSIBLINGS
| WS_DLGFRAME
| WS_OVERLAPPED
|
593 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| DS_3DLOOK
| DS_SETFONT
| DS_MODALFRAME
,
595 NULL
, NULL
, g_hinst
, 0);
597 assert (g_hwndTestDlg
);
598 assert (g_hwndTestDlgBut1
);
599 assert (g_hwndTestDlgBut2
);
600 assert (g_hwndTestDlgEdit
);
603 * Test message DM_SETDEFID
606 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, IDCANCEL
, 0 );
607 DefDlgProcA( g_hwndTestDlgBut1
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, FALSE
);
608 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
610 ok ( IDCANCEL
== (LOWORD(dwVal
)), "Did not set default ID\n" );
613 * Check whether message WM_NEXTDLGCTL is changing the focus to next control and if
614 * the destination control is a button, style of the button should be changed to
615 * BS_DEFPUSHBUTTON with out making it default.
619 * Keep the focus on Edit control.
622 if ( SetFocus( g_hwndTestDlgEdit
) )
624 ok ((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't set on Edit control\n");
627 * Test message WM_NEXTDLGCTL
629 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
630 ok ((GetFocus() == g_hwndTestDlgBut1
), "Focus didn't move to first button\n");
633 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
635 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
636 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
639 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
640 * the style of default button changed to BS_PUSHBUTTON.
642 if ( IDCANCEL
== (LOWORD(dwVal
)) )
644 ok ( ((GetWindowLong( g_hwndTestDlgBut1
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
645 "Button1 style not set to BS_DEFPUSHBUTTON\n" );
647 ok ( !((GetWindowLong( g_hwndTestDlgBut2
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
648 "Button2's style not changed to BS_PUSHBUTTON\n" );
652 * Move focus to Button2 using "WM_NEXTDLGCTL"
654 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
655 ok ((GetFocus() == g_hwndTestDlgBut2
), "Focus didn't move to second button\n");
658 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
660 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
661 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
664 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
665 * the style of button which lost the focus changed to BS_PUSHBUTTON.
667 if ( IDCANCEL
== (LOWORD(dwVal
)) )
669 ok ( ((GetWindowLong( g_hwndTestDlgBut2
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
670 "Button2 style not set to BS_DEFPUSHBUTTON\n" );
672 ok ( !((GetWindowLong( g_hwndTestDlgBut1
, GWL_STYLE
)) & BS_DEFPUSHBUTTON
),
673 "Button1's style not changed to BS_PUSHBUTTON\n" );
677 * Move focus to Edit control using "WM_NEXTDLGCTL"
679 DefDlgProcA( g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0 );
680 ok ((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't move to Edit control\n");
683 * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL"
685 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
686 ok ( IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
689 /* test nested default buttons */
691 child1
= CreateWindowA("button", "child1", WS_VISIBLE
|WS_CHILD
, 0, 0, 50, 50,
692 g_hwndTestDlg
, (HMENU
)100, g_hinst
, NULL
);
693 ok(child1
!= NULL
, "failed to create first child\n");
694 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 60, 60, 30, 30,
695 g_hwndTestDlg
, (HMENU
)200, g_hinst
, NULL
);
696 ok(child2
!= NULL
, "failed to create second child\n");
697 /* create nested child */
698 child3
= CreateWindowA("button", "child3", WS_VISIBLE
|WS_CHILD
, 10, 10, 10, 10,
699 child1
, (HMENU
)300, g_hinst
, NULL
);
700 ok(child3
!= NULL
, "failed to create subchild\n");
702 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, 200, 0);
703 dwVal
= DefDlgProcA( g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
704 ok(LOWORD(dwVal
) == 200, "expected 200, got %x\n", dwVal
);
706 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, 300, 0);
707 dwVal
= DefDlgProcA( g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
708 ok(LOWORD(dwVal
) == 300, "expected 300, got %x\n", dwVal
);
709 ok(SendMessageW( child3
, WM_GETDLGCODE
, 0, 0) != DLGC_DEFPUSHBUTTON
,
710 "expected child3 not to be marked as DLGC_DEFPUSHBUTTON\n");
712 g_bReceivedCommand
= FALSE
;
713 FormEnterMsg (&msg
, child3
);
714 ok(IsDialogMessage (g_hwndTestDlg
, &msg
), "Did not handle the ENTER\n");
715 ok(g_bReceivedCommand
, "Did not trigger the default Button action\n");
717 DestroyWindow(child3
);
718 DestroyWindow(child2
);
719 DestroyWindow(child1
);
720 DestroyWindow(g_hwndTestDlg
);
723 static void test_IsDialogMessage(void)
727 g_hwndMain
= CreateWindow ("IsDialogMessageWindowClass", "IsDialogMessageWindowClass",
729 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
730 NULL
, NULL
, g_hinst
, 0);
733 assert (g_hwndButton1
);
734 assert (g_hwndButtonCancel
);
736 /* The focus should initially be nowhere. The first TAB should take it
737 * to the first button. The second TAB should take it to the Cancel
740 FormTabMsg (&msg
, g_hwndMain
);
741 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle first TAB\n");
742 ok ((GetFocus() == g_hwndButton1
), "Focus did not move to first button\n");
743 FormTabMsg (&msg
, g_hwndButton1
);
744 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle second TAB\n");
745 ok ((GetFocus() == g_hwndButtonCancel
),
746 "Focus did not move to cancel button\n");
747 FormEnterMsg (&msg
, g_hwndButtonCancel
);
748 ok (IsDialogMessage (g_hwndMain
, &msg
), "Did not handle the ENTER\n");
749 ok (g_terminated
, "ENTER did not terminate\n");
753 static INT_PTR CALLBACK
delayFocusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
760 g_hwndInitialFocusGroupBox
= GetDlgItem(hDlg
,100);
761 g_hwndButton1
= GetDlgItem(hDlg
,200);
762 g_hwndButton2
= GetDlgItem(hDlg
,201);
763 g_hwndButtonCancel
= GetDlgItem(hDlg
,IDCANCEL
);
764 g_styleInitialFocusT1
= GetWindowLong(g_hwndInitialFocusGroupBox
, GWL_STYLE
);
766 /* Initially check the second radio button */
767 SendMessage(g_hwndButton1
, BM_SETCHECK
, BST_UNCHECKED
, 0);
768 SendMessage(g_hwndButton2
, BM_SETCHECK
, BST_CHECKED
, 0);
769 /* Continue testing after dialog initialization */
770 PostMessage(hDlg
, WM_USER
, 0, 0);
771 return g_bInitialFocusInitDlgResult
;
774 if (LOWORD(wParam
) == IDCANCEL
)
776 EndDialog(hDlg
, LOWORD(wParam
));
782 g_styleInitialFocusT2
= GetWindowLong(hDlg
, GWL_STYLE
);
783 g_hwndInitialFocusT1
= GetFocus();
785 g_hwndInitialFocusT2
= GetFocus();
786 PostMessage(hDlg
, WM_COMMAND
, IDCANCEL
, 0);
793 static INT_PTR CALLBACK
focusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
802 if (LOWORD(wParam
) == 200)
804 if (HIWORD(wParam
) == EN_SETFOCUS
)
805 g_hwndInitialFocusT1
= (HWND
)lParam
;
813 /* Helper for InitialFocusTest */
814 static const char * GetHwndString(HWND hw
)
817 return "a null handle";
818 if (hw
== g_hwndMain
)
819 return "the dialog handle";
820 if (hw
== g_hwndInitialFocusGroupBox
)
821 return "the group box control";
822 if (hw
== g_hwndButton1
)
823 return "the first button";
824 if (hw
== g_hwndButton2
)
825 return "the second button";
826 if (hw
== g_hwndButtonCancel
)
827 return "the cancel button";
829 return "unknown handle";
832 static void test_initial_focus(void)
835 * This test intentionally returns FALSE in response to WM_INITDIALOG
836 * without setting focus to a control. This is what MFC's CFormView does.
838 * Since the WM_INITDIALOG handler returns FALSE without setting the focus,
839 * the focus should initially be NULL. Later, when we manually set focus to
840 * the dialog, the default handler should set focus to the first control that
841 * is "visible, not disabled, and has the WS_TABSTOP style" (MSDN). Because the
842 * second radio button has been checked, it should be the first control
843 * that meets these criteria and should receive the focus.
846 g_bInitialFocusInitDlgResult
= FALSE
;
847 g_hwndInitialFocusT1
= (HWND
) -1;
848 g_hwndInitialFocusT2
= (HWND
) -1;
849 g_styleInitialFocusT1
= -1;
850 g_styleInitialFocusT2
= -1;
852 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
854 ok (((g_styleInitialFocusT1
& WS_TABSTOP
) == 0),
855 "Error in wrc - Detected WS_TABSTOP as default style for GROUPBOX\n");
857 ok (((g_styleInitialFocusT2
& WS_VISIBLE
) == 0),
858 "Modal dialogs should not be shown until the message queue first goes empty\n");
860 ok ((g_hwndInitialFocusT1
== NULL
),
861 "Error in initial focus when WM_INITDIALOG returned FALSE: "
862 "Expected NULL focus, got %s (%p).\n",
863 GetHwndString(g_hwndInitialFocusT1
), g_hwndInitialFocusT1
);
865 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
866 "Error after first SetFocus() when WM_INITDIALOG returned FALSE: "
867 "Expected the second button (%p), got %s (%p).\n",
868 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
869 g_hwndInitialFocusT2
);
872 * This is the same as above, except WM_INITDIALOG is made to return TRUE.
873 * This should cause the focus to go to the second radio button right away
874 * and stay there (until the user indicates otherwise).
877 g_bInitialFocusInitDlgResult
= TRUE
;
878 g_hwndInitialFocusT1
= (HWND
) -1;
879 g_hwndInitialFocusT2
= (HWND
) -1;
880 g_styleInitialFocusT1
= -1;
881 g_styleInitialFocusT2
= -1;
883 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
885 ok ((g_hwndInitialFocusT1
== g_hwndButton2
),
886 "Error in initial focus when WM_INITDIALOG returned TRUE: "
887 "Expected the second button (%p), got %s (%p).\n",
888 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT1
),
889 g_hwndInitialFocusT1
);
891 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
892 "Error after first SetFocus() when WM_INITDIALOG returned TRUE: "
893 "Expected the second button (%p), got %s (%p).\n",
894 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
895 g_hwndInitialFocusT2
);
898 * If the dialog has DS_CONTROL and it's not visible then we shouldn't change focus */
903 DLGTEMPLATE
* pTemplate
;
905 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG", RT_DIALOG
);
906 hTemplate
= LoadResource(g_hinst
, hResource
);
907 pTemplate
= LockResource(hTemplate
);
909 g_hwndInitialFocusT1
= 0;
910 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
911 ok (hDlg
!= 0, "Failed to create test dialog.\n");
913 ok ((g_hwndInitialFocusT1
== 0),
914 "Focus should not be set for an invisible DS_CONTROL dialog %p.\n", g_hwndInitialFocusT1
);
920 * If the dialog has no tab-accessible controls, set focus to first control */
925 DLGTEMPLATE
* pTemplate
;
928 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG_2", RT_DIALOG
);
929 hTemplate
= LoadResource(g_hinst
, hResource
);
930 pTemplate
= LockResource(hTemplate
);
932 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
933 g_hwndInitialFocusT1
= GetFocus();
934 hLabel
= GetDlgItem(hDlg
, 200);
935 ok (hDlg
!= 0, "Failed to create test dialog.\n");
937 ok ((g_hwndInitialFocusT1
== hLabel
),
938 "Focus should have been set to the first control, expected (%p) got (%p).\n",
939 hLabel
, g_hwndInitialFocusT1
);
945 static void test_GetDlgItemText(void)
950 strcpy(string
, "Overwrite Me");
951 ret
= GetDlgItemTextA(NULL
, 0, string
, sizeof(string
)/sizeof(string
[0]));
952 ok(!ret
, "GetDlgItemText(NULL) shouldn't have succeeded\n");
954 ok(string
[0] == '\0' || broken(!strcmp(string
, "Overwrite Me")),
955 "string retrieved using GetDlgItemText should have been NULL terminated\n");
958 static void test_GetDlgItem(void)
960 HWND hwnd
, child1
, child2
, hwnd2
;
963 hwnd
= CreateWindowA("button", "parent", WS_VISIBLE
, 0, 0, 100, 100, NULL
, 0, g_hinst
, NULL
);
964 ok(hwnd
!= NULL
, "failed to created window\n");
966 /* created with the same ID */
967 child1
= CreateWindowA("button", "child1", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, hwnd
, 0, g_hinst
, NULL
);
968 ok(child1
!= NULL
, "failed to create first child\n");
969 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, hwnd
, 0, g_hinst
, NULL
);
970 ok(child2
!= NULL
, "failed to create second child\n");
972 hwnd2
= GetDlgItem(hwnd
, 0);
973 ok(hwnd2
== child1
, "expected first child, got %p\n", hwnd2
);
975 hwnd2
= GetTopWindow(hwnd
);
976 ok(hwnd2
== child1
, "expected first child to be top, got %p\n", hwnd2
);
978 ret
= SetWindowPos(child1
, child2
, 0, 0, 0, 0, SWP_NOMOVE
);
979 ok(ret
, "got %d\n", ret
);
980 hwnd2
= GetTopWindow(hwnd
);
981 ok(hwnd2
== child2
, "expected second child to be top, got %p\n", hwnd2
);
983 /* top window from child list is picked */
984 hwnd2
= GetDlgItem(hwnd
, 0);
985 ok(hwnd2
== child2
, "expected second child, got %p\n", hwnd2
);
987 /* Now test how GetDlgItem searches */
988 DestroyWindow(child2
);
989 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, child1
, 0, g_hinst
, NULL
);
990 ok(child2
!= NULL
, "failed to create second child\n");
992 /* give child2 an ID */
993 SetWindowLong(child2
, GWLP_ID
, 100);
995 hwnd2
= GetDlgItem(hwnd
, 100);
996 ok(!hwnd2
, "expected child to not be found, got %p\n", hwnd2
);
998 /* make the ID of child2 public with a WS_EX_CONTROLPARENT parent */
999 SetWindowLong(child1
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1001 hwnd2
= GetDlgItem(hwnd
, 100);
1002 ok(!hwnd2
, "expected child to not be found, got %p\n", hwnd2
);
1004 DestroyWindow(child1
);
1005 DestroyWindow(child2
);
1006 DestroyWindow(hwnd
);
1009 static INT_PTR CALLBACK
DestroyDlgWinProc (HWND hDlg
, UINT uiMsg
,
1010 WPARAM wParam
, LPARAM lParam
)
1012 if (uiMsg
== WM_INITDIALOG
)
1014 DestroyWindow(hDlg
);
1020 static INT_PTR CALLBACK
DestroyOnCloseDlgWinProc (HWND hDlg
, UINT uiMsg
,
1021 WPARAM wParam
, LPARAM lParam
)
1026 PostMessage(hDlg
, WM_CLOSE
, 0, 0);
1029 DestroyWindow(hDlg
);
1038 static INT_PTR CALLBACK
TestInitDialogHandleProc (HWND hDlg
, UINT uiMsg
,
1039 WPARAM wParam
, LPARAM lParam
)
1041 if (uiMsg
== WM_INITDIALOG
)
1043 HWND expected
= GetNextDlgTabItem(hDlg
, NULL
, FALSE
);
1044 ok(expected
== (HWND
)wParam
,
1045 "Expected wParam to be the handle to the first tabstop control (%p), got %p\n",
1046 expected
, (HWND
)wParam
);
1048 EndDialog(hDlg
, LOWORD(SendMessage(hDlg
, DM_GETDEFID
, 0, 0)));
1054 static INT_PTR CALLBACK
TestDefButtonDlgProc (HWND hDlg
, UINT uiMsg
,
1055 WPARAM wParam
, LPARAM lParam
)
1060 EndDialog(hDlg
, LOWORD(SendMessage(hDlg
, DM_GETDEFID
, 0, 0)));
1066 static INT_PTR CALLBACK
TestReturnKeyDlgProc (HWND hDlg
, UINT uiMsg
,
1067 WPARAM wParam
, LPARAM lParam
)
1069 static int received_idok
;
1075 MSG msg
= {hDlg
, WM_KEYDOWN
, VK_RETURN
, 0x011c0001};
1078 IsDialogMessage(hDlg
, &msg
);
1079 ok(received_idok
== 0xdead, "WM_COMMAND/0xdead not received\n");
1082 IsDialogMessage(hDlg
, &msg
);
1083 ok(received_idok
== IDOK
, "WM_COMMAND/IDOK not received\n");
1090 if (received_idok
== -1)
1092 HWND hwnd
= GetDlgItem(hDlg
, 0xdead);
1093 ok(!hwnd
, "dialog item with ID 0xdead should not exist\n");
1094 SetWindowLong(hDlg
, DWLP_MSGRESULT
, MAKELRESULT(0xdead, DC_HASDEFID
));
1100 received_idok
= wParam
;
1106 static INT_PTR CALLBACK
TestControlStyleDlgProc(HWND hdlg
, UINT msg
,
1107 WPARAM wparam
, LPARAM lparam
)
1110 DWORD style
, exstyle
;
1116 control
= GetDlgItem(hdlg
, 7);
1117 ok(control
!= 0, "dialog control with id 7 not found\n");
1118 style
= GetWindowLong(control
, GWL_STYLE
);
1119 ok(style
== (WS_CHILD
|WS_VISIBLE
), "expected WS_CHILD|WS_VISIBLE, got %#x\n", style
);
1120 exstyle
= GetWindowLong(control
, GWL_EXSTYLE
);
1121 ok(exstyle
== (WS_EX_NOPARENTNOTIFY
|WS_EX_TRANSPARENT
|WS_EX_CLIENTEDGE
), "expected WS_EX_NOPARENTNOTIFY|WS_EX_TRANSPARENT|WS_EX_CLIENTEDGE, got %#x\n", exstyle
);
1123 GetWindowText(control
, buf
, sizeof(buf
));
1124 ok(lstrcmp(buf
, "bump7") == 0, "expected bump7, got %s\n", buf
);
1126 control
= GetDlgItem(hdlg
, 8);
1127 ok(control
!= 0, "dialog control with id 8 not found\n");
1128 style
= GetWindowLong(control
, GWL_STYLE
);
1129 ok(style
== (WS_CHILD
|WS_VISIBLE
), "expected WS_CHILD|WS_VISIBLE, got %#x\n", style
);
1130 exstyle
= GetWindowLong(control
, GWL_EXSTYLE
);
1131 ok(exstyle
== (WS_EX_NOPARENTNOTIFY
|WS_EX_TRANSPARENT
), "expected WS_EX_NOPARENTNOTIFY|WS_EX_TRANSPARENT, got %#x\n", exstyle
);
1133 GetWindowText(control
, buf
, sizeof(buf
));
1134 ok(lstrcmp(buf
, "bump8") == 0, "expected bump8, got %s\n", buf
);
1136 EndDialog(hdlg
, -7);
1142 static void test_DialogBoxParamA(void)
1145 HWND hwnd_invalid
= (HWND
)0x4444;
1147 ret
= DialogBoxParamA(GetModuleHandle(0), "TEST_DLG_CHILD_POPUP", 0, TestControlStyleDlgProc
, 0);
1148 ok(ret
== -7, "expected -7, got %ld\n", ret
);
1150 SetLastError(0xdeadbeef);
1151 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "IDD_DIALOG" , hwnd_invalid
, 0 , 0);
1152 ok(0 == ret
|| broken(ret
== -1), "DialogBoxParamA returned %ld, expected 0\n", ret
);
1153 ok(ERROR_INVALID_WINDOW_HANDLE
== GetLastError() ||
1154 broken(GetLastError() == 0xdeadbeef),
1155 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n",GetLastError());
1157 /* Test a dialog which destroys itself on WM_INITDIALOG. */
1158 SetLastError(0xdeadbeef);
1159 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "IDD_DIALOG", 0, DestroyDlgWinProc
, 0);
1160 ok(-1 == ret
, "DialogBoxParamA returned %ld, expected -1\n", ret
);
1161 ok(ERROR_INVALID_WINDOW_HANDLE
== GetLastError() ||
1162 GetLastError() == ERROR_SUCCESS
||
1163 broken(GetLastError() == 0xdeadbeef),
1164 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n",GetLastError());
1166 /* Test a dialog which destroys itself on WM_CLOSE. */
1167 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "IDD_DIALOG", 0, DestroyOnCloseDlgWinProc
, 0);
1168 ok(0 == ret
, "DialogBoxParamA returned %ld, expected 0\n", ret
);
1170 SetLastError(0xdeadbeef);
1171 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "RESOURCE_INVALID" , 0, 0, 0);
1172 ok(-1 == ret
, "DialogBoxParamA returned %ld, expected -1\n", ret
);
1173 ok(ERROR_RESOURCE_NAME_NOT_FOUND
== GetLastError() ||
1174 broken(GetLastError() == 0xdeadbeef),
1175 "got %d, expected ERROR_RESOURCE_NAME_NOT_FOUND\n",GetLastError());
1177 SetLastError(0xdeadbeef);
1178 ret
= DefDlgProcA(0, WM_ERASEBKGND
, 0, 0);
1179 ok(ret
== 0, "DefDlgProcA returned %ld, expected 0\n", ret
);
1180 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
1181 broken(GetLastError() == 0xdeadbeef),
1182 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
1184 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "TEST_EMPTY_DIALOG", 0, TestInitDialogHandleProc
, 0);
1185 ok(ret
== IDOK
, "Expected IDOK\n");
1187 ret
= DialogBoxParamA(GetModuleHandle(NULL
), "TEST_EMPTY_DIALOG", 0, TestDefButtonDlgProc
, 0);
1188 ok(ret
== IDOK
, "Expected IDOK\n");
1190 DialogBoxParamA(GetModuleHandle(NULL
), "TEST_EMPTY_DIALOG", 0, TestReturnKeyDlgProc
, 0);
1193 static void test_DisabledDialogTest(void)
1195 g_terminated
= FALSE
;
1196 DialogBoxParam(g_hinst
, "IDD_DIALOG", NULL
, disabled_test_proc
, 0);
1197 ok(FALSE
== g_terminated
, "dialog with disabled ok button has been terminated\n");
1200 static INT_PTR CALLBACK
messageBoxFontDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
1203 return (uiMsg
== WM_INITDIALOG
);
1206 static void test_MessageBoxFontTest(void)
1208 /* This dialog template defines a dialog template which got 0x7fff as its
1209 * font size and omits the other font members. On WinNT, passing such a
1210 * dialog template to CreateDialogIndirectParamW will result in a dialog
1211 * being created which uses the message box font. We test that here.
1214 static unsigned char dlgTemplate
[] =
1217 0x01,0x00, /* Version */
1218 0xff,0xff, /* Extended template marker */
1219 0x00,0x00,0x00,0x00, /* Context Help ID */
1220 0x00,0x00,0x00,0x00, /* Extended style */
1221 0xc0,0x00,0xc8,0x80, /* Style (WS_SYSMENU|WS_CAPTION|WS_POPUP|DS_SETFONT|DS_MODALFRAME) */
1222 0x01,0x00, /* Control count */
1225 0x80,0x00, /* Width */
1226 0x80,0x00, /* Height */
1227 0x00,0x00, /* Menu name */
1228 0x00,0x00, /* Class name */
1229 'T',0x00,'e',0x00, /* Caption (unicode) */
1232 0xff,0x7f, /* Font height (0x7fff = message box font) */
1235 0x00,0x00, /* Align to DWORD (header is 42 bytes) */
1236 0x00,0x00,0x00,0x00, /* Context Help ID */
1237 0x00,0x00,0x00,0x00, /* Extended style */
1238 0x00,0x00,0x00,0x50, /* Style (WS_CHILD|WS_VISIBLE) */
1241 0x80,0x00, /* Width */
1242 0x80,0x00, /* Height */
1243 0x00,0x01,0x00,0x00, /* Control ID (256) */
1244 0xff,0xff,0x82,0x00, /* Class (Static) */
1245 'W',0x00,'I',0x00, /* Caption (unicode) */
1254 0x00,0x00, /* Size of extended data */
1256 0x00,0x00 /* Align to DWORD */
1261 LOGFONTW lfStaticFont
;
1262 NONCLIENTMETRICSW ncMetrics
;
1264 /* Check if the dialog can be created from the template. On Win9x, this should fail
1265 * because we are calling the W function which is not implemented, but that's what
1266 * we want, because passing such a template to CreateDialogIndirectParamA would crash
1269 hDlg
= CreateDialogIndirectParamW(g_hinst
, (LPCDLGTEMPLATE
)dlgTemplate
, NULL
, messageBoxFontDlgWinProc
, 0);
1272 win_skip("dialog wasn't created\n");
1276 hFont
= (HFONT
) SendDlgItemMessageW(hDlg
, 256, WM_GETFONT
, 0, 0);
1279 skip("dialog uses system font\n");
1280 DestroyWindow(hDlg
);
1283 GetObjectW(hFont
, sizeof(LOGFONTW
), &lfStaticFont
);
1285 ncMetrics
.cbSize
= FIELD_OFFSET(NONCLIENTMETRICSW
, iPaddedBorderWidth
);
1286 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &ncMetrics
, 0);
1287 ok( !memcmp(&lfStaticFont
, &ncMetrics
.lfMessageFont
, FIELD_OFFSET(LOGFONTW
, lfFaceName
)) &&
1288 !lstrcmpW(lfStaticFont
.lfFaceName
, ncMetrics
.lfMessageFont
.lfFaceName
),
1289 "dialog doesn't use message box font\n");
1290 DestroyWindow(hDlg
);
1293 static void test_SaveRestoreFocus(void)
1298 DLGTEMPLATE
* pTemplate
;
1302 /* create the dialog */
1303 hResource
= FindResourceA(g_hinst
, "MULTI_EDIT_DIALOG", RT_DIALOG
);
1304 hTemplate
= LoadResource(g_hinst
, hResource
);
1305 pTemplate
= LockResource(hTemplate
);
1307 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, messageBoxFontDlgWinProc
, 0);
1308 ok (hDlg
!= 0, "Failed to create test dialog.\n");
1310 foundId
= GetWindowLongPtr(GetFocus(), GWLP_ID
);
1311 ok (foundId
== 1000, "First edit box should have gained focus on dialog creation. Expected: %d, Found: %ld\n", 1000, foundId
);
1313 /* de- then reactivate the dialog */
1314 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
1315 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
1317 foundId
= GetWindowLongPtr(GetFocus(), GWLP_ID
);
1318 ok (foundId
== 1000, "First edit box should have regained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1000, foundId
);
1320 /* select the next tabbable item */
1321 SetFocus(GetNextDlgTabItem(hDlg
, GetFocus(), FALSE
));
1323 foundId
= GetWindowLongPtr(GetFocus(), GWLP_ID
);
1324 ok (foundId
== 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId
);
1326 /* de- then reactivate the dialog */
1327 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
1328 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
1330 foundId
= GetWindowLongPtr(GetFocus(), GWLP_ID
);
1331 ok (foundId
== 1001, "Second edit box should have gained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId
);
1333 /* disable the 2nd box */
1334 EnableWindow(GetFocus(), FALSE
);
1336 foundHwnd
= GetFocus();
1337 ok (foundHwnd
== NULL
, "Second edit box should have lost focus after being disabled. Expected: %p, Found: %p\n", NULL
, foundHwnd
);
1339 /* de- then reactivate the dialog */
1340 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
1341 SendMessage(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
1343 foundHwnd
= GetFocus();
1344 ok (foundHwnd
== NULL
, "No controls should have gained focus after dialog reactivation. Expected: %p, Found: %p\n", NULL
, foundHwnd
);
1347 DestroyWindow(hDlg
);
1350 static INT_PTR CALLBACK
timer_message_dlg_proc(HWND wnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1358 visible
= GetWindowLong(wnd
, GWL_STYLE
) & WS_VISIBLE
;
1359 ok(!visible
, "Dialog should not be visible.\n");
1360 SetTimer(wnd
, 1, 100, NULL
);
1365 if (LOWORD(wparam
) != IDCANCEL
) return FALSE
;
1366 EndDialog(wnd
, LOWORD(wparam
));
1370 if (wparam
!= 1) return FALSE
;
1371 visible
= GetWindowLong(wnd
, GWL_STYLE
) & WS_VISIBLE
;
1374 ok(!visible
, "Dialog should not be visible.\n");
1375 PostMessage(wnd
, WM_USER
, 0, 0);
1379 ok(visible
, "Dialog should be visible.\n");
1380 PostMessage(wnd
, WM_COMMAND
, IDCANCEL
, 0);
1385 visible
= GetWindowLong(wnd
, GWL_STYLE
) & WS_VISIBLE
;
1386 ok(visible
, "Dialog should be visible.\n");
1394 static void test_timer_message(void)
1396 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, timer_message_dlg_proc
);
1401 g_hinst
= GetModuleHandleA (0);
1403 if (!RegisterWindowClasses()) assert(0);
1405 test_GetNextDlgItem();
1406 test_IsDialogMessage();
1407 test_WM_NEXTDLGCTL();
1408 test_initial_focus();
1410 test_GetDlgItemText();
1411 test_DialogBoxParamA();
1412 test_DisabledDialogTest();
1413 test_MessageBoxFontTest();
1414 test_SaveRestoreFocus();
1415 test_timer_message();