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"
43 static HWND hwnd
[MAXHWNDS
];
44 static unsigned int numwnds
=1; /* 0 is reserved for null */
47 static HINSTANCE g_hinst
; /* This application's HINSTANCE */
48 static HWND g_hwndMain
, g_hwndButton1
, g_hwndButton2
, g_hwndButtonCancel
;
49 static HWND g_hwndTestDlg
, g_hwndTestDlgBut1
, g_hwndTestDlgBut2
, g_hwndTestDlgEdit
;
50 static HWND g_hwndInitialFocusT1
, g_hwndInitialFocusT2
, g_hwndInitialFocusGroupBox
;
52 static LONG g_styleInitialFocusT1
, g_styleInitialFocusT2
;
53 static BOOL g_bInitialFocusInitDlgResult
, g_bReceivedCommand
;
55 static BOOL g_terminated
;
56 static BOOL g_button1Clicked
;
65 static const h_entry hierarchy
[] = {
66 /* 0 is reserved for the null window */
67 { 1, 0, WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
},
68 { 20, 1, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
69 { 2, 1, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
70 { 60, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
71 /* What happens with groups when the parent is disabled */
72 { 8, 2, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, WS_EX_CONTROLPARENT
},
73 { 85, 8, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_GROUP
, 0},
74 { 9, 8, WS_CHILD
, WS_EX_CONTROLPARENT
},
75 { 86, 9, WS_CHILD
| WS_VISIBLE
, 0},
76 { 87, 9, WS_CHILD
| WS_VISIBLE
, 0},
77 { 31, 8, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
78 { 10, 2, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
79 { 88, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
80 { 11, 10, WS_CHILD
, WS_EX_CONTROLPARENT
},
81 { 89, 11, WS_CHILD
| WS_VISIBLE
, 0},
82 { 32, 11, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
83 { 90, 11, WS_CHILD
| WS_VISIBLE
, 0},
84 { 33, 10, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
85 { 21, 2, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
86 { 61, 2, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
87 { 3, 1, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
88 { 22, 3, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
89 { 62, 3, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
90 { 7, 3, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
91 { 4, 7, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
92 { 83, 4, WS_CHILD
| WS_VISIBLE
, 0},
93 { 5, 4, WS_CHILD
| WS_VISIBLE
| DS_CONTROL
, 0},
94 /* A couple of controls around the main dialog */
95 { 29, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
96 { 81, 5, WS_CHILD
| WS_VISIBLE
, 0},
97 /* The main dialog with lots of controls */
98 { 6, 5, WS_CHILD
| WS_VISIBLE
, WS_EX_CONTROLPARENT
},
99 /* At the start of a dialog */
100 /* Disabled controls are skipped */
101 { 63, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
102 /* Invisible controls are skipped */
103 { 64, 6, WS_CHILD
| WS_TABSTOP
, 0},
104 /* Invisible disabled controls are skipped */
105 { 65, 6, WS_CHILD
| WS_DISABLED
| WS_TABSTOP
, 0},
106 /* Non-tabstop controls are skipped for tabs but not for groups */
107 { 66, 6, WS_CHILD
| WS_VISIBLE
, 0},
108 /* End of first group, with no tabstops in it */
109 { 23, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
110 /* At last a tabstop */
111 { 67, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
112 /* A group that is totally disabled or invisible */
113 { 24, 6, WS_CHILD
| WS_DISABLED
| WS_GROUP
, 0},
114 { 68, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
115 { 69, 6, WS_CHILD
| WS_TABSTOP
, 0},
116 /* A valid group in the middle of the dialog (not the first nor last group*/
117 { 25, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
118 /* A non-tabstop item will be skipped for tabs */
119 { 70, 6, WS_CHILD
| WS_VISIBLE
, 0},
120 /* A disabled item will be skipped for tabs and groups */
121 { 71, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
122 /* A valid item will be found for tabs and groups */
123 { 72, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
124 /* A disabled item to skip when looking for the next group item */
125 { 73, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
126 /* The next group begins with an enabled visible label */
127 { 26, 6, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
128 { 74, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
129 { 75, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
130 /* That group is terminated by a disabled label */
131 { 27, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_GROUP
, 0},
132 { 76, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
133 { 77, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
134 /* That group is terminated by an invisible label */
135 { 28, 6, WS_CHILD
| WS_GROUP
, 0},
136 /* The end of the dialog with item for loop and recursion testing */
137 { 78, 6, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
138 /* No tabstop so skipped for prev tab, but found for prev group */
139 { 79, 6, WS_CHILD
| WS_VISIBLE
, 0},
140 { 80, 6, WS_CHILD
| WS_VISIBLE
| WS_DISABLED
| WS_TABSTOP
, 0},
141 /* A couple of controls after the main dialog */
142 { 82, 5, WS_CHILD
| WS_VISIBLE
, 0},
143 { 30, 5, WS_CHILD
| WS_VISIBLE
| WS_GROUP
, 0},
144 /* And around them */
145 { 84, 4, WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0},
149 static DWORD
get_button_style(HWND button
)
151 return GetWindowLongW(button
, GWL_STYLE
) & BS_TYPEMASK
;
154 static BOOL
CreateWindows (HINSTANCE hinst
)
156 const h_entry
*p
= hierarchy
;
160 DWORD style
, exstyle
;
163 /* Basically assert that the hierarchy is valid and track the
164 * maximum control number
166 if (p
->id
>= numwnds
)
168 if (p
->id
>= ARRAY_SIZE(hwnd
))
170 trace ("Control %ld is out of range\n", p
->id
);
178 trace ("Control %ld is out of range\n", p
->id
);
181 if (hwnd
[p
->id
] != 0)
183 trace ("Control %ld is used more than once\n", p
->id
);
187 /* Create the control */
188 sprintf (ctrlname
, "ctrl%4.4ld", p
->id
);
189 hwnd
[p
->id
] = CreateWindowExA(p
->exstyle
, p
->parent
? "static" : "GetNextDlgItemWindowClass", ctrlname
, p
->style
, 10, 10, 10, 10, hwnd
[p
->parent
], p
->parent
? (HMENU
) (2000 + p
->id
) : 0, hinst
, 0);
192 trace ("Failed to create control %ld\n", p
->id
);
196 /* Check that the styles are as we specified (except the main one
197 * which is quite frequently messed up). If this keeps breaking then
198 * we could mask out the bits that don't concern us.
202 style
= GetWindowLongA(hwnd
[p
->id
], GWL_STYLE
);
203 exstyle
= GetWindowLongA(hwnd
[p
->id
], GWL_EXSTYLE
);
204 if (style
!= p
->style
|| exstyle
!= p
->exstyle
)
206 trace ("Style mismatch at %ld: %8.8x %8.8x cf %8.8x %8.8x\n", p
->id
, style
, exstyle
, p
->style
, p
->exstyle
);
215 /* Form the lParam of a WM_KEYDOWN message */
216 static DWORD
KeyDownData (int repeat
, int scancode
, int extended
, int wasdown
)
218 return ((repeat
& 0x0000FFFF) | ((scancode
& 0x00FF) << 16) |
219 (extended
? 0x01000000 : 0) | (wasdown
? 0x40000000 : 0));
222 /* Form a WM_KEYDOWN VK_TAB message to the specified window */
223 static void FormTabMsg (MSG
*pMsg
, HWND hwnd
)
226 pMsg
->message
= WM_KEYDOWN
;
227 pMsg
->wParam
= VK_TAB
;
228 pMsg
->lParam
= KeyDownData (1, 0x0F, 0, 0);
229 /* pMsg->time is not set. It shouldn't be needed */
230 /* pMsg->pt is ignored */
233 /* Form a WM_KEYDOWN VK_RETURN message to the specified window */
234 static void FormEnterMsg (MSG
*pMsg
, HWND hwnd
)
237 pMsg
->message
= WM_KEYDOWN
;
238 pMsg
->wParam
= VK_RETURN
;
239 pMsg
->lParam
= KeyDownData (1, 0x1C, 0, 0);
240 /* pMsg->time is not set. It shouldn't be needed */
241 /* pMsg->pt is ignored */
244 /***********************************************************************
251 int isok
; /* or is it todo */
260 static int id (HWND h
)
263 for (i
= 0; i
< numwnds
; i
++)
271 * Tests 1-8 test the hCtl argument of null or the dialog itself.
273 * 1. Prev Group of null is null
274 * 2. Prev Tab of null is null
275 * 3. Prev Group of hDlg in hDlg is null
276 * 4. Prev Tab of hDlg in hDlg is null
277 * 5. Next Group of null is first visible enabled child
278 * Check it skips invisible, disabled and both.
279 * 6. Next Tab of null is first visible enabled tabstop
280 * Check it skips invisible, disabled, nontabstop, and in combination.
281 * 7. Next Group of hDlg in hDlg is as of null
282 * 8. Next Tab of hDlg in hDlg is as of null
284 * Tests 9-14 test descent
286 * 9. DS_CONTROL does not result in descending the hierarchy for Tab Next
287 * 10. DS_CONTROL does not result in descending the hierarchy for Group Next
288 * 11. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Next
289 * 12. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Next
290 * 13. WS_EX_CONTROLPARENT results in descending the hierarchy for Tab Prev
291 * 14. WS_EX_CONTROLPARENT results in descending the hierarchy for Group Prev
293 * Tests 15-24 are the basic Prev/Next Group tests
295 * 15. Next Group of a visible enabled non-group control is the next visible
296 * enabled non-group control, if there is one before the next group
297 * 16. Next Group of a visible enabled non-group control wraps around to the
298 * beginning of the group on finding a control that starts another group.
299 * Note that the group is in the middle of the dialog.
300 * 17. As 16 except note that the next group is started with a disabled
302 * 18. As 16 except note that the next group is started with an invisible
304 * 19. Next Group wraps around the controls of the dialog
305 * 20. Next Group is the same even if the initial control is disabled.
306 * 21. Next Group is the same even if the initial control is invisible.
307 * 22. Next Group is the same even if the initial control has the group style
308 * 23. Next Group returns the initial control if there is no visible enabled
309 * control in the group. (Initial control disabled and not group style).
310 * 24. Prev version of test 16.
311 * Prev Group of a visible enabled non-group control wraps around to the
312 * beginning of the group on finding a control that starts the group.
313 * Note that the group is in the middle of the dialog.
315 * In tests 25 to 28 the control is sitting under dialogs which do not have
316 * the WS_EX_CONTROLPARENT style and so cannot be reached from the top of
319 * 25. Next Group of an inaccessible control is as if it were accessible
320 * 26. Prev Group of an inaccessible control begins searching at the highest
321 * level ancestor that did not permit recursion down the hierarchy
322 * 27. Next Tab of an inaccessible control is as if it were accessible
323 * 28. Prev Tab of an inaccessible control begins searching at the highest
324 * level ancestor that did not permit recursion down the hierarchy.
326 * Tests 29- are the basic Tab tests
328 * 29. Next Tab of a control is the next visible enabled control with the
329 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
330 * 30. Prev Tab of a control is the previous visible enabled control with the
331 * Tabstop style (N.B. skips disabled, invisible and non-tabstop)
332 * 31. Next Tab test with at least two layers of descent and finding the
333 * result not at the first control.
334 * 32. Next Tab test with at least two layers of descent with the descent and
335 * control at the start of each level.
336 * 33. Prev Tab test with at least two layers of descent and finding the
337 * result not at the last control.
338 * 34. Prev Tab test with at least two layers of descent with the descent and
339 * control at the end of each level.
341 * 35. Passing NULL may result in the first child being the one returned.
343 * 36. Passing NULL may result in the first child being the one returned.
347 static void test_GetNextDlgItem(void)
349 static test_record test
[] =
351 /* isok test dlg ctl tab prev res */
353 { 1, 1, 6, 0, 0, 1, 0},
354 { 1, 2, 6, 0, 1, 1, 0},
355 { 1, 3, 6, 6, 0, 1, 0},
356 { 1, 4, 6, 6, 1, 1, 0},
357 { 1, 5, 6, 0, 0, 0, 66},
358 { 1, 6, 6, 0, 1, 0, 67},
359 { 1, 7, 6, 6, 0, 0, 66},
360 { 1, 8, 6, 6, 1, 0, 67},
362 { 1, 9, 4, 83, 1, 0, 84},
363 { 1, 10, 4, 83, 0, 0, 5},
364 { 1, 11, 5, 81, 1, 0, 67},
365 { 1, 12, 5, 81, 0, 0, 66},
366 { 1, 13, 5, 82, 1, 1, 78},
368 { 1, 14, 5, 82, 0, 1, 79},
369 { 1, 15, 6, 70, 0, 0, 72},
370 { 1, 16, 6, 72, 0, 0, 25},
371 { 1, 17, 6, 75, 0, 0, 26},
372 { 1, 18, 6, 77, 0, 0, 76},
373 { 1, 19, 6, 79, 0, 0, 66},
374 { 1, 20, 6, 71, 0, 0, 72},
375 { 1, 21, 6, 64, 0, 0, 66},
377 { 1, 22, 6, 25, 0, 0, 70},
378 { 1, 23, 6, 68, 0, 0, 68},
379 { 1, 24, 6, 25, 0, 1, 72},
380 { 1, 25, 1, 70, 0, 0, 72},
381 /*{ 0, 26, 1, 70, 0, 1, 3}, Crashes Win95*/
382 { 1, 27, 1, 70, 1, 0, 72},
383 /*{ 0, 28, 1, 70, 1, 1, 61}, Crashes Win95*/
385 { 1, 29, 6, 67, 1, 0, 72},
386 { 1, 30, 6, 72, 1, 1, 67},
388 { 1, 35, 2, 0, 0, 0, 60},
389 { 1, 36, 2, 0, 1, 0, 60},
391 { 0, 0, 0, 0, 0, 0, 0} /* End of test */
393 const test_record
*p
= test
;
395 ok (CreateWindows (g_hinst
), "Could not create test windows\n");
400 a
= (p
->tab
? GetNextDlgTabItem
: GetNextDlgGroupItem
) (hwnd
[p
->dlg
], hwnd
[p
->ctl
], p
->prev
);
401 todo_wine_if (!p
->isok
)
402 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
);
410 static BOOL
OnMainWindowCreate(HWND hwnd
, LPCREATESTRUCTA lpcs
)
412 g_hwndButton1
= CreateWindowA("button", "Button &1",
413 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_DEFPUSHBUTTON
| BS_TEXT
,
414 10, 10, 80, 80, hwnd
, (HMENU
)100, g_hinst
, 0);
415 if (!g_hwndButton1
) return FALSE
;
417 g_hwndButton2
= CreateWindowA("button", "Button &2",
418 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_TEXT
,
419 110, 10, 80, 80, hwnd
, (HMENU
)200, g_hinst
, 0);
420 if (!g_hwndButton2
) return FALSE
;
422 g_hwndButtonCancel
= CreateWindowA("button", "Cancel",
423 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
424 210, 10, 80, 80, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
425 if (!g_hwndButtonCancel
) return FALSE
;
435 static BOOL
OnTestDlgCreate (HWND hwnd
, LPCREATESTRUCTA lpcs
)
437 g_hwndTestDlgEdit
= CreateWindowExA( WS_EX_LEFT
| WS_EX_LTRREADING
|
438 WS_EX_RIGHTSCROLLBAR
| WS_EX_NOPARENTNOTIFY
| WS_EX_CLIENTEDGE
,
440 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| ES_LEFT
| ES_AUTOHSCROLL
,
441 16,33,184,24, hwnd
, (HMENU
)101, g_hinst
, 0);
442 if (!g_hwndTestDlgEdit
) return FALSE
;
444 g_hwndTestDlgBut1
= CreateWindowExA( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
445 | WS_EX_NOPARENTNOTIFY
,
446 "button", "Button &1",
447 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
448 204,33,30,24, hwnd
, (HMENU
)201, g_hinst
, 0);
449 if (!g_hwndTestDlgBut1
) return FALSE
;
451 g_hwndTestDlgBut2
= CreateWindowExA( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
452 | WS_EX_NOPARENTNOTIFY
, "button",
454 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
| BS_TEXT
,
455 90,102,80,24, hwnd
, (HMENU
)IDCANCEL
, g_hinst
, 0);
456 if (!g_hwndTestDlgBut2
) return FALSE
;
461 static LRESULT CALLBACK
main_window_procA (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
466 /* Add blank case statements for these to ensure we don't use them
469 case DM_GETDEFID
: break;
470 case DM_SETDEFID
: break;
473 return (OnMainWindowCreate (hwnd
,
474 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
476 if (wParam
== IDCANCEL
)
481 else if ((wParam
== 100 || wParam
== 0xFFFF) && lParam
)
483 g_button1Clicked
= TRUE
;
488 return DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
491 static LRESULT CALLBACK
disabled_test_proc (HWND hwnd
, UINT uiMsg
,
492 WPARAM wParam
, LPARAM lParam
)
501 dw
= SendMessageA(hwnd
, DM_GETDEFID
, 0, 0);
502 assert(DC_HASDEFID
== HIWORD(dw
));
503 hwndOk
= GetDlgItem(hwnd
, LOWORD(dw
));
505 EnableWindow(hwndOk
, FALSE
);
507 PostMessageA(hwnd
, WM_KEYDOWN
, VK_RETURN
, 0);
508 PostMessageA(hwnd
, WM_COMMAND
, IDCANCEL
, 0);
518 else if (wParam
== IDCANCEL
)
526 return DefWindowProcA (hwnd
, uiMsg
, wParam
, lParam
);
529 static LRESULT CALLBACK
testDlgWinProc (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
534 /* Add blank case statements for these to ensure we don't use them
537 case DM_GETDEFID
: break;
538 case DM_SETDEFID
: break;
541 return (OnTestDlgCreate (hwnd
,
542 (LPCREATESTRUCTA
) lParam
) ? 0 : (LRESULT
) -1);
544 if(LOWORD(wParam
) == 300) g_bReceivedCommand
= TRUE
;
547 return DefDlgProcA (hwnd
, uiMsg
, wParam
, lParam
);
550 static LRESULT CALLBACK
test_control_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
556 static const short sample
[] = { 10,1,2,3,4,5 };
557 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
558 short *data
= cs
->lpCreateParams
;
559 ok(!memcmp(data
, sample
, sizeof(sample
)), "data mismatch: %d,%d,%d,%d,%d\n", data
[0], data
[1], data
[2], data
[3], data
[4]);
567 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
570 static BOOL
RegisterWindowClasses (void)
575 cls
.lpfnWndProc
= DefWindowProcA
;
578 cls
.hInstance
= g_hinst
;
580 cls
.hCursor
= LoadCursorA (NULL
, (LPCSTR
)IDC_ARROW
);
581 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
582 cls
.lpszMenuName
= NULL
;
583 cls
.lpszClassName
= "GetNextDlgItemWindowClass";
585 if (!RegisterClassA (&cls
)) return FALSE
;
587 cls
.lpfnWndProc
= main_window_procA
;
588 cls
.lpszClassName
= "IsDialogMessageWindowClass";
589 if (!RegisterClassA (&cls
)) return FALSE
;
591 cls
.lpfnWndProc
= test_control_procA
;
592 cls
.lpszClassName
= "TESTCONTROL";
593 if (!RegisterClassA (&cls
)) return FALSE
;
595 GetClassInfoA(0, "#32770", &cls
);
596 cls
.lpfnWndProc
= testDlgWinProc
;
597 cls
.lpszClassName
= "WM_NEXTDLGCTLWndClass";
598 if (!RegisterClassA (&cls
)) return FALSE
;
603 static void test_WM_NEXTDLGCTL(void)
605 HWND child1
, child2
, child3
;
609 g_hwndTestDlg
= CreateWindowExA( WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
610 | WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
| WS_EX_APPWINDOW
,
611 "WM_NEXTDLGCTLWndClass",
612 "WM_NEXTDLGCTL Message test window",
613 WS_POPUPWINDOW
| WS_CLIPSIBLINGS
| WS_DLGFRAME
| WS_OVERLAPPED
|
614 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| DS_3DLOOK
| DS_SETFONT
| DS_MODALFRAME
,
616 NULL
, NULL
, g_hinst
, 0);
618 assert (g_hwndTestDlg
);
619 assert (g_hwndTestDlgBut1
);
620 assert (g_hwndTestDlgBut2
);
621 assert (g_hwndTestDlgEdit
);
624 * Test message DM_SETDEFID
627 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, IDCANCEL
, 0 );
628 DefDlgProcA( g_hwndTestDlgBut1
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, FALSE
);
629 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
631 ok ( IDCANCEL
== (LOWORD(dwVal
)), "Did not set default ID\n" );
634 * Check whether message WM_NEXTDLGCTL is changing the focus to next control and if
635 * the destination control is a button, style of the button should be changed to
636 * BS_DEFPUSHBUTTON with out making it default.
639 /* Keep the focus on Edit control. */
640 SetFocus(g_hwndTestDlgEdit
);
641 ok((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't set on Edit control\n");
643 /* Test message WM_NEXTDLGCTL */
644 DefDlgProcA(g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0);
645 ok((GetFocus() == g_hwndTestDlgBut1
), "Focus didn't move to first button\n");
647 /* Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL" */
648 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
649 ok(IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
652 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
653 * the style of default button changed to BS_PUSHBUTTON.
655 ok(get_button_style(g_hwndTestDlgBut1
) == BS_DEFPUSHBUTTON
, "Button1's style not set to BS_DEFPUSHBUTTON\n");
656 ok(get_button_style(g_hwndTestDlgBut2
) == BS_PUSHBUTTON
, "Button2's style not set to BS_PUSHBUTTON\n");
658 /* Move focus to Button2 using "WM_NEXTDLGCTL" */
659 DefDlgProcA(g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0);
660 ok((GetFocus() == g_hwndTestDlgBut2
), "Focus didn't move to second button\n");
662 /* Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL" */
663 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
664 ok(IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
667 * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and
668 * the style of button which lost the focus changed to BS_PUSHBUTTON.
670 ok(get_button_style(g_hwndTestDlgBut1
) == BS_PUSHBUTTON
, "Button1's style not set to BS_PUSHBUTTON\n");
671 ok(get_button_style(g_hwndTestDlgBut2
) == BS_DEFPUSHBUTTON
, "Button2's style not set to BS_DEFPUSHBUTTON\n");
673 /* Move focus to Edit control using "WM_NEXTDLGCTL" */
674 DefDlgProcA(g_hwndTestDlg
, WM_NEXTDLGCTL
, 0, 0);
675 ok((GetFocus() == g_hwndTestDlgEdit
), "Focus didn't move to Edit control\n");
677 /* Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL" */
678 dwVal
= DefDlgProcA(g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
679 ok(IDCANCEL
== (LOWORD(dwVal
)), "WM_NEXTDLGCTL changed default button\n");
681 /* test nested default buttons */
683 child1
= CreateWindowA("button", "child1", WS_VISIBLE
|WS_CHILD
, 0, 0, 50, 50,
684 g_hwndTestDlg
, (HMENU
)100, g_hinst
, NULL
);
685 ok(child1
!= NULL
, "failed to create first child\n");
686 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 60, 60, 30, 30,
687 g_hwndTestDlg
, (HMENU
)200, g_hinst
, NULL
);
688 ok(child2
!= NULL
, "failed to create second child\n");
689 /* create nested child */
690 child3
= CreateWindowA("button", "child3", WS_VISIBLE
|WS_CHILD
, 10, 10, 10, 10,
691 child1
, (HMENU
)300, g_hinst
, NULL
);
692 ok(child3
!= NULL
, "failed to create subchild\n");
694 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, 200, 0);
695 dwVal
= DefDlgProcA( g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
696 ok(LOWORD(dwVal
) == 200, "expected 200, got %x\n", dwVal
);
698 DefDlgProcA( g_hwndTestDlg
, DM_SETDEFID
, 300, 0);
699 dwVal
= DefDlgProcA( g_hwndTestDlg
, DM_GETDEFID
, 0, 0);
700 ok(LOWORD(dwVal
) == 300, "expected 300, got %x\n", dwVal
);
701 ok(SendMessageW( child3
, WM_GETDLGCODE
, 0, 0) != DLGC_DEFPUSHBUTTON
,
702 "expected child3 not to be marked as DLGC_DEFPUSHBUTTON\n");
704 g_bReceivedCommand
= FALSE
;
705 FormEnterMsg (&msg
, child3
);
706 ok(IsDialogMessageA(g_hwndTestDlg
, &msg
), "Did not handle the ENTER\n");
707 ok(g_bReceivedCommand
, "Did not trigger the default Button action\n");
709 DestroyWindow(child3
);
710 DestroyWindow(child2
);
711 DestroyWindow(child1
);
712 DestroyWindow(g_hwndTestDlg
);
715 static LRESULT CALLBACK
hook_proc(INT code
, WPARAM wParam
, LPARAM lParam
)
717 ok(0, "unexpected hook called, code %d\n", code
);
718 return CallNextHookEx(NULL
, code
, wParam
, lParam
);
721 static BOOL g_MSGF_DIALOGBOX
;
722 static LRESULT CALLBACK
hook_proc2(INT code
, WPARAM wParam
, LPARAM lParam
)
724 ok(code
== MSGF_DIALOGBOX
, "unexpected hook called, code %d\n", code
);
725 g_MSGF_DIALOGBOX
= code
== MSGF_DIALOGBOX
;
726 return CallNextHookEx(NULL
, code
, wParam
, lParam
);
729 static void test_IsDialogMessage(void)
734 g_hwndMain
= CreateWindowA("IsDialogMessageWindowClass", "IsDialogMessageWindowClass",
736 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
737 NULL
, NULL
, g_hinst
, 0);
740 assert (g_hwndButton1
);
741 assert (g_hwndButtonCancel
);
745 /* crashes on Windows */
746 IsDialogMessageA(NULL
, NULL
);
747 IsDialogMessageA(g_hwndMain
, NULL
);
750 /* The focus should initially be nowhere. The first TAB should take it
751 * to the first button. The second TAB should take it to the Cancel
755 /* valid window, invalid message window */
756 hook
= SetWindowsHookExA(WH_MSGFILTER
, hook_proc2
, NULL
, GetCurrentThreadId());
757 FormTabMsg (&msg
, (HWND
)0xbeefbeef);
758 ok (!IsDialogMessageA(g_hwndMain
, &msg
), "expected failure\n");
759 ok(g_MSGF_DIALOGBOX
, "hook wasn't called\n");
760 g_MSGF_DIALOGBOX
= FALSE
;
761 UnhookWindowsHookEx(hook
);
763 hook
= SetWindowsHookExA(WH_MSGFILTER
, hook_proc
, NULL
, GetCurrentThreadId());
764 FormTabMsg (&msg
, g_hwndMain
);
766 ok (!IsDialogMessageA(NULL
, &msg
), "expected failure\n");
767 ok (!IsDialogMessageA((HWND
)0xbeefbeef, &msg
), "expected failure\n");
769 UnhookWindowsHookEx(hook
);
771 ok (IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle first TAB\n");
772 ok ((GetFocus() == g_hwndButton1
), "Focus did not move to first button\n");
773 FormTabMsg (&msg
, g_hwndButton1
);
774 ok (IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle second TAB\n");
775 ok ((GetFocus() == g_hwndButtonCancel
),
776 "Focus did not move to cancel button\n");
777 FormEnterMsg (&msg
, g_hwndButtonCancel
);
778 ok (IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle the ENTER\n");
779 ok (g_terminated
, "ENTER did not terminate\n");
781 /* matching but invalid window handles, NULL */
782 hook
= SetWindowsHookExA(WH_MSGFILTER
, hook_proc
, NULL
, GetCurrentThreadId());
784 FormTabMsg (&msg
, NULL
);
785 ok (!IsDialogMessageA(msg
.hwnd
, &msg
), "expected failure\n");
787 /* matching but invalid window handles, not NULL */
788 FormTabMsg (&msg
, (HWND
)0xbeefbeef);
789 ok (!IsDialogMessageA(msg
.hwnd
, &msg
), "expected failure\n");
791 UnhookWindowsHookEx(hook
);
792 DestroyWindow(g_hwndMain
);
794 g_hwndMain
= CreateWindowA("IsDialogMessageWindowClass", "IsDialogMessageWindowClass", WS_OVERLAPPEDWINDOW
,
795 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, g_hinst
, 0);
796 SetFocus(g_hwndButton1
);
797 g_button1Clicked
= FALSE
;
798 FormEnterMsg(&msg
, g_hwndButton1
);
799 ok(IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle the ENTER\n");
800 ok(g_button1Clicked
, "Did not receive button 1 click notification\n");
802 g_button1Clicked
= FALSE
;
803 FormEnterMsg(&msg
, g_hwndMain
);
804 ok(IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle the ENTER\n");
805 ok(g_button1Clicked
, "Did not receive button 1 click notification\n");
807 g_button1Clicked
= FALSE
;
808 FormEnterMsg(&msg
, g_hwndButton2
);
809 ok(IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle the ENTER\n");
810 ok(g_button1Clicked
, "Did not receive button 1 click notification\n");
812 /* Button with id larger than 0xFFFF should also work */
813 g_button1Clicked
= FALSE
;
814 FormEnterMsg(&msg
, g_hwndMain
);
815 SetWindowLongPtrW(g_hwndButton1
, GWLP_ID
, 0x1FFFF);
816 ok(IsDialogMessageA(g_hwndMain
, &msg
), "Did not handle the ENTER\n");
817 ok(g_button1Clicked
, "Did not receive button 1 click notification\n");
819 DestroyWindow(g_hwndMain
);
823 static INT_PTR CALLBACK
delayFocusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
830 g_hwndInitialFocusGroupBox
= GetDlgItem(hDlg
,100);
831 g_hwndButton1
= GetDlgItem(hDlg
,200);
832 g_hwndButton2
= GetDlgItem(hDlg
,201);
833 g_hwndButtonCancel
= GetDlgItem(hDlg
,IDCANCEL
);
834 g_styleInitialFocusT1
= GetWindowLongA(g_hwndInitialFocusGroupBox
, GWL_STYLE
);
836 /* Initially check the second radio button */
837 SendMessageA(g_hwndButton1
, BM_SETCHECK
, BST_UNCHECKED
, 0);
838 SendMessageA(g_hwndButton2
, BM_SETCHECK
, BST_CHECKED
, 0);
839 /* Continue testing after dialog initialization */
840 PostMessageA(hDlg
, WM_USER
, 0, 0);
841 return g_bInitialFocusInitDlgResult
;
844 if (LOWORD(wParam
) == IDCANCEL
)
846 EndDialog(hDlg
, LOWORD(wParam
));
852 g_styleInitialFocusT2
= GetWindowLongA(hDlg
, GWL_STYLE
);
853 g_hwndInitialFocusT1
= GetFocus();
855 g_hwndInitialFocusT2
= GetFocus();
856 PostMessageA(hDlg
, WM_COMMAND
, IDCANCEL
, 0);
863 static INT_PTR CALLBACK
focusDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
869 SetWindowTextA(GetDlgItem(hDlg
, 200), "new caption");
873 if (LOWORD(wParam
) == 200)
875 if (HIWORD(wParam
) == EN_SETFOCUS
)
876 g_hwndInitialFocusT1
= (HWND
)lParam
;
884 static INT_PTR CALLBACK
EmptyProcUserTemplate(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
893 static INT_PTR CALLBACK
focusChildDlgWinProc (HWND hwnd
, UINT uiMsg
, WPARAM wParam
,
896 static HWND hChildDlg
;
905 WORD menu
,class,title
;
908 SetFocus( GetDlgItem(hwnd
, 200) );
910 GetClientRect(hwnd
,&rectHwnd
);
911 temp
.tmplate
.style
= WS_CHILD
| WS_CLIPSIBLINGS
| WS_VISIBLE
| DS_CONTROL
| DS_3DLOOK
;
912 temp
.tmplate
.dwExtendedStyle
= 0;
913 temp
.tmplate
.cdit
= 0;
918 temp
.menu
= temp
.class = temp
.title
= 0;
920 hChildDlg
= CreateDialogIndirectParamA(g_hinst
, &temp
.tmplate
,
921 hwnd
, (DLGPROC
)EmptyProcUserTemplate
, 0);
922 ok(hChildDlg
!= 0, "Failed to create test dialog.\n");
927 DestroyWindow(hChildDlg
);
934 /* Helper for InitialFocusTest */
935 static const char * GetHwndString(HWND hw
)
938 return "a null handle";
939 if (hw
== g_hwndMain
)
940 return "the dialog handle";
941 if (hw
== g_hwndInitialFocusGroupBox
)
942 return "the group box control";
943 if (hw
== g_hwndButton1
)
944 return "the first button";
945 if (hw
== g_hwndButton2
)
946 return "the second button";
947 if (hw
== g_hwndButtonCancel
)
948 return "the cancel button";
950 return "unknown handle";
953 static void test_focus(void)
956 * This test intentionally returns FALSE in response to WM_INITDIALOG
957 * without setting focus to a control. This is what MFC's CFormView does.
959 * Since the WM_INITDIALOG handler returns FALSE without setting the focus,
960 * the focus should initially be NULL. Later, when we manually set focus to
961 * the dialog, the default handler should set focus to the first control that
962 * is "visible, not disabled, and has the WS_TABSTOP style" (MSDN). Because the
963 * second radio button has been checked, it should be the first control
964 * that meets these criteria and should receive the focus.
967 g_bInitialFocusInitDlgResult
= FALSE
;
968 g_hwndInitialFocusT1
= (HWND
) -1;
969 g_hwndInitialFocusT2
= (HWND
) -1;
970 g_styleInitialFocusT1
= -1;
971 g_styleInitialFocusT2
= -1;
973 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
975 ok (((g_styleInitialFocusT1
& WS_TABSTOP
) == 0),
976 "Error in wrc - Detected WS_TABSTOP as default style for GROUPBOX\n");
978 ok (((g_styleInitialFocusT2
& WS_VISIBLE
) == 0),
979 "Modal dialogs should not be shown until the message queue first goes empty\n");
981 ok ((g_hwndInitialFocusT1
== NULL
),
982 "Error in initial focus when WM_INITDIALOG returned FALSE: "
983 "Expected NULL focus, got %s (%p).\n",
984 GetHwndString(g_hwndInitialFocusT1
), g_hwndInitialFocusT1
);
986 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
987 "Error after first SetFocus() when WM_INITDIALOG returned FALSE: "
988 "Expected the second button (%p), got %s (%p).\n",
989 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
990 g_hwndInitialFocusT2
);
993 * This is the same as above, except WM_INITDIALOG is made to return TRUE.
994 * This should cause the focus to go to the second radio button right away
995 * and stay there (until the user indicates otherwise).
998 g_bInitialFocusInitDlgResult
= TRUE
;
999 g_hwndInitialFocusT1
= (HWND
) -1;
1000 g_hwndInitialFocusT2
= (HWND
) -1;
1001 g_styleInitialFocusT1
= -1;
1002 g_styleInitialFocusT2
= -1;
1004 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, delayFocusDlgWinProc
);
1006 ok ((g_hwndInitialFocusT1
== g_hwndButton2
),
1007 "Error in initial focus when WM_INITDIALOG returned TRUE: "
1008 "Expected the second button (%p), got %s (%p).\n",
1009 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT1
),
1010 g_hwndInitialFocusT1
);
1012 ok ((g_hwndInitialFocusT2
== g_hwndButton2
),
1013 "Error after first SetFocus() when WM_INITDIALOG returned TRUE: "
1014 "Expected the second button (%p), got %s (%p).\n",
1015 g_hwndButton2
, GetHwndString(g_hwndInitialFocusT2
),
1016 g_hwndInitialFocusT2
);
1019 * If the dialog has DS_CONTROL and it's not visible then we shouldn't change focus */
1024 DLGTEMPLATE
* pTemplate
;
1026 DWORD selectionStart
= 0xdead, selectionEnd
= 0xbeef;
1028 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG", (LPCSTR
)RT_DIALOG
);
1029 hTemplate
= LoadResource(g_hinst
, hResource
);
1030 pTemplate
= LockResource(hTemplate
);
1032 g_hwndInitialFocusT1
= 0;
1033 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
1034 ok (hDlg
!= 0, "Failed to create test dialog.\n");
1036 ok ((g_hwndInitialFocusT1
== 0),
1037 "Focus should not be set for an invisible DS_CONTROL dialog %p.\n", g_hwndInitialFocusT1
);
1039 /* Also make sure that WM_SETFOCUS selects the textbox's text */
1040 hTextbox
= GetDlgItem(hDlg
, 200);
1041 SendMessageA(hTextbox
, WM_SETTEXT
, 0, (LPARAM
)"Hello world");
1043 SendMessageA(hDlg
, WM_SETFOCUS
, 0, 0);
1044 SendMessageA(hTextbox
, EM_GETSEL
, (WPARAM
)&selectionStart
, (LPARAM
)&selectionEnd
);
1045 ok(selectionStart
== 0 && selectionEnd
== 11, "Text selection after WM_SETFOCUS is [%i, %i) expected [0, 11)\n", selectionStart
, selectionEnd
);
1047 /* but WM_ACTIVATE does not */
1048 SendMessageA(hTextbox
, EM_SETSEL
, 0, 0);
1049 SendMessageA(hDlg
, WM_ACTIVATE
, WA_ACTIVE
, 0);
1050 SendMessageA(hTextbox
, EM_GETSEL
, (WPARAM
)&selectionStart
, (LPARAM
)&selectionEnd
);
1051 ok(selectionStart
== 0 && selectionEnd
== 0, "Text selection after WM_ACTIVATE is [%i, %i) expected [0, 0)\n", selectionStart
, selectionEnd
);
1053 DestroyWindow(hDlg
);
1057 * If the dialog has no tab-accessible controls, set focus to first control */
1062 DLGTEMPLATE
* pTemplate
;
1065 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG_2", (LPCSTR
)RT_DIALOG
);
1066 hTemplate
= LoadResource(g_hinst
, hResource
);
1067 pTemplate
= LockResource(hTemplate
);
1069 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
1070 ok(hDlg
!= 0, "Failed to create test dialog.\n");
1071 hLabel
= GetDlgItem(hDlg
, 200);
1073 ok(GetFocus() == hLabel
, "Focus not set to label, focus=%p dialog=%p label=%p\n", GetFocus(), hDlg
, hLabel
);
1075 DestroyWindow(hDlg
);
1077 /* Also check focus after WM_ACTIVATE and WM_SETFOCUS */
1078 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, NULL
, 0);
1079 ok(hDlg
!= 0, "Failed to create test dialog.\n");
1080 hLabel
= GetDlgItem(hDlg
, 200);
1083 SendMessageA(hDlg
, WM_ACTIVATE
, WA_ACTIVE
, 0);
1084 ok(GetFocus() == NULL
, "Focus set on WM_ACTIVATE, focus=%p dialog=%p label=%p\n", GetFocus(), hDlg
, hLabel
);
1087 SendMessageA(hDlg
, WM_SETFOCUS
, 0, 0);
1088 ok(GetFocus() == hLabel
, "Focus not set to label on WM_SETFOCUS, focus=%p dialog=%p label=%p\n", GetFocus(), hDlg
, hLabel
);
1090 DestroyWindow(hDlg
);
1094 * Select textbox's text on creation */
1099 DLGTEMPLATE
* pTemplate
;
1101 DWORD selectionStart
= 0xdead, selectionEnd
= 0xbeef;
1103 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG_3", (LPCSTR
)RT_DIALOG
);
1104 hTemplate
= LoadResource(g_hinst
, hResource
);
1105 pTemplate
= LockResource(hTemplate
);
1107 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusDlgWinProc
, 0);
1108 ok(hDlg
!= 0, "Failed to create test dialog.\n");
1109 edit
= GetDlgItem(hDlg
, 200);
1111 ok(GetFocus() == edit
, "Focus not set to edit, focus=%p, dialog=%p, edit=%p\n",
1112 GetFocus(), hDlg
, edit
);
1113 SendMessageA(edit
, EM_GETSEL
, (WPARAM
)&selectionStart
, (LPARAM
)&selectionEnd
);
1114 ok(selectionStart
== 0 && selectionEnd
== 11,
1115 "Text selection after WM_SETFOCUS is [%i, %i) expected [0, 11)\n",
1116 selectionStart
, selectionEnd
);
1118 DestroyWindow(hDlg
);
1122 * Select textbox's text on creation when WM_INITDIALOG creates a child dialog. */
1127 DLGTEMPLATE
* pTemplate
;
1130 hResource
= FindResourceA(g_hinst
,"FOCUS_TEST_DIALOG_3", (LPCSTR
)RT_DIALOG
);
1131 hTemplate
= LoadResource(g_hinst
, hResource
);
1132 pTemplate
= LockResource(hTemplate
);
1134 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, focusChildDlgWinProc
, 0);
1135 ok(hDlg
!= 0, "Failed to create test dialog.\n");
1136 edit
= GetDlgItem(hDlg
, 200);
1138 ok(GetFocus() == edit
, "Focus not set to edit, focus=%p, dialog=%p, edit=%p\n",
1139 GetFocus(), hDlg
, edit
);
1141 DestroyWindow(hDlg
);
1145 static void test_GetDlgItemText(void)
1150 strcpy(string
, "Overwrite Me");
1151 ret
= GetDlgItemTextA(NULL
, 0, string
, ARRAY_SIZE(string
));
1152 ok(!ret
, "GetDlgItemText(NULL) shouldn't have succeeded\n");
1154 ok(string
[0] == '\0' || broken(!strcmp(string
, "Overwrite Me")),
1155 "string retrieved using GetDlgItemText should have been NULL terminated\n");
1158 static INT_PTR CALLBACK
getdlgitem_test_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1160 if (msg
== WM_INITDIALOG
)
1167 hwnd
= GetDlgItem(hdlg
, -1);
1168 ok(hwnd
!= NULL
, "Expected dialog item.\n");
1171 ret
= GetDlgItemTextA(hdlg
, -1, text
, ARRAY_SIZE(text
));
1172 ok(ret
&& !strcmp(text
, "Text1"), "Unexpected item text.\n");
1174 val
= GetWindowLongA(hwnd
, GWLP_ID
);
1175 ok(val
== -1, "Unexpected id.\n");
1177 val
= GetWindowLongPtrA(hwnd
, GWLP_ID
);
1178 ok(val
== -1, "Unexpected id %ld.\n", val
);
1180 hwnd
= GetDlgItem(hdlg
, -2);
1181 ok(hwnd
!= NULL
, "Expected dialog item.\n");
1183 val
= GetWindowLongA(hwnd
, GWLP_ID
);
1184 ok(val
== -2, "Unexpected id.\n");
1186 val
= GetWindowLongPtrA(hwnd
, GWLP_ID
);
1187 ok(val
== -2, "Unexpected id %ld.\n", val
);
1189 EndDialog(hdlg
, 0xdead);
1195 static void test_GetDlgItem(void)
1197 HWND hwnd
, child1
, child2
, hwnd2
;
1201 hwnd
= CreateWindowA("button", "parent", WS_VISIBLE
, 0, 0, 100, 100, NULL
, 0, g_hinst
, NULL
);
1202 ok(hwnd
!= NULL
, "failed to created window\n");
1204 /* created with the same ID */
1205 child1
= CreateWindowA("button", "child1", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, hwnd
, 0, g_hinst
, NULL
);
1206 ok(child1
!= NULL
, "failed to create first child\n");
1207 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, hwnd
, 0, g_hinst
, NULL
);
1208 ok(child2
!= NULL
, "failed to create second child\n");
1210 hwnd2
= GetDlgItem(hwnd
, 0);
1211 ok(hwnd2
== child1
, "expected first child, got %p\n", hwnd2
);
1213 hwnd2
= GetTopWindow(hwnd
);
1214 ok(hwnd2
== child1
, "expected first child to be top, got %p\n", hwnd2
);
1216 ret
= SetWindowPos(child1
, child2
, 0, 0, 0, 0, SWP_NOMOVE
);
1217 ok(ret
, "got %d\n", ret
);
1218 hwnd2
= GetTopWindow(hwnd
);
1219 ok(hwnd2
== child2
, "expected second child to be top, got %p\n", hwnd2
);
1221 /* top window from child list is picked */
1222 hwnd2
= GetDlgItem(hwnd
, 0);
1223 ok(hwnd2
== child2
, "expected second child, got %p\n", hwnd2
);
1225 /* Now test how GetDlgItem searches */
1226 DestroyWindow(child2
);
1227 child2
= CreateWindowA("button", "child2", WS_VISIBLE
|WS_CHILD
, 0, 0, 10, 10, child1
, 0, g_hinst
, NULL
);
1228 ok(child2
!= NULL
, "failed to create second child\n");
1230 /* give child2 an ID */
1231 SetWindowLongA(child2
, GWLP_ID
, 100);
1233 hwnd2
= GetDlgItem(hwnd
, 100);
1234 ok(!hwnd2
, "expected child to not be found, got %p\n", hwnd2
);
1236 /* make the ID of child2 public with a WS_EX_CONTROLPARENT parent */
1237 SetWindowLongA(child1
, GWL_EXSTYLE
, WS_EX_CONTROLPARENT
);
1239 hwnd2
= GetDlgItem(hwnd
, 100);
1240 ok(!hwnd2
, "expected child to not be found, got %p\n", hwnd2
);
1242 DestroyWindow(child1
);
1243 DestroyWindow(child2
);
1244 DestroyWindow(hwnd
);
1246 retval
= DialogBoxParamA(g_hinst
, "GETDLGITEM_TEST_DIALOG", NULL
, getdlgitem_test_dialog_proc
, 0);
1247 ok(retval
== 0xdead, "Unexpected return value.\n");
1250 static INT_PTR CALLBACK
DestroyDlgWinProc (HWND hDlg
, UINT uiMsg
,
1251 WPARAM wParam
, LPARAM lParam
)
1253 if (uiMsg
== WM_INITDIALOG
)
1255 DestroyWindow(hDlg
);
1261 static INT_PTR CALLBACK
DestroyOnCloseDlgWinProc (HWND hDlg
, UINT uiMsg
,
1262 WPARAM wParam
, LPARAM lParam
)
1267 PostMessageA(hDlg
, WM_CLOSE
, 0, 0);
1270 DestroyWindow(hDlg
);
1279 static INT_PTR CALLBACK
TestInitDialogHandleProc (HWND hDlg
, UINT uiMsg
,
1280 WPARAM wParam
, LPARAM lParam
)
1282 if (uiMsg
== WM_INITDIALOG
)
1284 HWND expected
= GetNextDlgTabItem(hDlg
, NULL
, FALSE
);
1285 ok(expected
== (HWND
)wParam
,
1286 "Expected wParam to be the handle to the first tabstop control (%p), got %p\n",
1287 expected
, (HWND
)wParam
);
1289 EndDialog(hDlg
, LOWORD(SendMessageA(hDlg
, DM_GETDEFID
, 0, 0)));
1295 static INT_PTR CALLBACK
TestDefButtonDlgProc (HWND hDlg
, UINT uiMsg
,
1296 WPARAM wParam
, LPARAM lParam
)
1301 EndDialog(hDlg
, LOWORD(SendMessageA(hDlg
, DM_GETDEFID
, 0, 0)));
1307 static INT_PTR CALLBACK
TestReturnKeyDlgProc (HWND hDlg
, UINT uiMsg
,
1308 WPARAM wParam
, LPARAM lParam
)
1310 static int received_idok
;
1316 MSG msg
= {hDlg
, WM_KEYDOWN
, VK_RETURN
, 0x011c0001};
1319 IsDialogMessageA(hDlg
, &msg
);
1320 ok(received_idok
== 0xdead, "WM_COMMAND/0xdead not received\n");
1323 IsDialogMessageA(hDlg
, &msg
);
1324 ok(received_idok
== IDOK
, "WM_COMMAND/IDOK not received\n");
1331 if (received_idok
== -1)
1333 HWND hwnd
= GetDlgItem(hDlg
, 0xdead);
1334 ok(!hwnd
, "dialog item with ID 0xdead should not exist\n");
1335 SetWindowLongA(hDlg
, DWLP_MSGRESULT
, MAKELRESULT(0xdead, DC_HASDEFID
));
1341 received_idok
= wParam
;
1347 static INT_PTR CALLBACK
TestControlStyleDlgProc(HWND hdlg
, UINT msg
,
1348 WPARAM wparam
, LPARAM lparam
)
1351 DWORD style
, exstyle
;
1357 control
= GetDlgItem(hdlg
, 7);
1358 ok(control
!= 0, "dialog control with id 7 not found\n");
1359 style
= GetWindowLongA(control
, GWL_STYLE
);
1360 ok(style
== (WS_CHILD
|WS_VISIBLE
), "expected WS_CHILD|WS_VISIBLE, got %#x\n", style
);
1361 exstyle
= GetWindowLongA(control
, GWL_EXSTYLE
);
1362 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
);
1364 GetWindowTextA(control
, buf
, sizeof(buf
));
1365 ok(strcmp(buf
, "bump7") == 0, "expected bump7, got %s\n", buf
);
1367 control
= GetDlgItem(hdlg
, 8);
1368 ok(control
!= 0, "dialog control with id 8 not found\n");
1369 style
= GetWindowLongA(control
, GWL_STYLE
);
1370 ok(style
== (WS_CHILD
|WS_VISIBLE
), "expected WS_CHILD|WS_VISIBLE, got %#x\n", style
);
1371 exstyle
= GetWindowLongA(control
, GWL_EXSTYLE
);
1372 ok(exstyle
== (WS_EX_NOPARENTNOTIFY
|WS_EX_TRANSPARENT
), "expected WS_EX_NOPARENTNOTIFY|WS_EX_TRANSPARENT, got %#x\n", exstyle
);
1374 GetWindowTextA(control
, buf
, sizeof(buf
));
1375 ok(strcmp(buf
, "bump8") == 0, "expected bump8, got %s\n", buf
);
1377 EndDialog(hdlg
, -7);
1383 static const WCHAR testtextW
[] = {'W','n','d','T','e','x','t',0};
1384 static const char *testtext
= "WndText";
1386 enum defdlgproc_text
1388 DLGPROCTEXT_SNDMSGA
= 0,
1389 DLGPROCTEXT_SNDMSGW
,
1390 DLGPROCTEXT_DLGPROCA
,
1391 DLGPROCTEXT_DLGPROCW
,
1392 DLGPROCTEXT_SETTEXTA
,
1393 DLGPROCTEXT_SETTEXTW
,
1396 static const char *testmodes
[] =
1406 static INT_PTR CALLBACK
test_aw_conversion_dlgprocA(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1408 int mode
= HandleToULong(GetPropA(hdlg
, "test_mode"));
1409 WCHAR
*text
= (WCHAR
*)lparam
;
1410 char *textA
= (char *)lparam
;
1415 case WM_WININICHANGE
:
1416 case WM_DEVMODECHANGE
:
1423 case DLGPROCTEXT_DLGPROCA
:
1424 ok(textA
== testtext
, "%s: %s, unexpected text %s.\n", IsWindowUnicode(hdlg
) ? "U" : "A",
1425 testmodes
[mode
], textA
);
1427 case DLGPROCTEXT_DLGPROCW
:
1428 ok(text
== testtextW
, "%s: %s, unexpected text %s.\n", IsWindowUnicode(hdlg
) ? "U" : "A", testmodes
[mode
],
1429 wine_dbgstr_w(text
));
1431 case DLGPROCTEXT_SNDMSGA
:
1432 case DLGPROCTEXT_SETTEXTA
:
1433 if (IsWindowUnicode(hdlg
))
1435 ok(text
!= testtextW
&& !lstrcmpW(text
, testtextW
),
1436 "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1439 ok(textA
== testtext
, "A: %s, unexpected text %s.\n", testmodes
[mode
], textA
);
1441 case DLGPROCTEXT_SNDMSGW
:
1442 case DLGPROCTEXT_SETTEXTW
:
1443 if (IsWindowUnicode(hdlg
))
1444 ok(text
== testtextW
, "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1446 ok(textA
!= testtext
&& !strcmp(textA
, testtext
), "A: %s, unexpected text %s.\n",
1447 testmodes
[mode
], textA
);
1453 return DefWindowProcW(hdlg
, msg
, wparam
, lparam
);
1456 static INT_PTR CALLBACK
test_aw_conversion_dlgprocW(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1458 int mode
= HandleToULong(GetPropA(hdlg
, "test_mode"));
1459 WCHAR
*text
= (WCHAR
*)lparam
;
1460 char *textA
= (char *)lparam
;
1465 case WM_WININICHANGE
:
1466 case WM_DEVMODECHANGE
:
1473 case DLGPROCTEXT_DLGPROCA
:
1474 ok(textA
== testtext
, "%s: %s, unexpected text %s.\n", IsWindowUnicode(hdlg
) ? "U" : "A",
1475 testmodes
[mode
], textA
);
1477 case DLGPROCTEXT_DLGPROCW
:
1478 ok(text
== testtextW
, "%s: %s, unexpected text %s.\n", IsWindowUnicode(hdlg
) ? "U" : "A", testmodes
[mode
],
1479 wine_dbgstr_w(text
));
1481 case DLGPROCTEXT_SNDMSGA
:
1482 case DLGPROCTEXT_SETTEXTA
:
1483 if (IsWindowUnicode(hdlg
))
1484 ok(text
!= testtextW
&& !lstrcmpW(text
, testtextW
),
1485 "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1487 ok(textA
== testtext
, "A: %s, unexpected text %s.\n", testmodes
[mode
], textA
);
1489 case DLGPROCTEXT_SNDMSGW
:
1490 case DLGPROCTEXT_SETTEXTW
:
1491 if (IsWindowUnicode(hdlg
))
1492 ok(text
== testtextW
, "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1494 ok(textA
!= testtext
&& !strcmp(textA
, testtext
), "A: %s, unexpected text %s.\n",
1495 testmodes
[mode
], textA
);
1501 return DefWindowProcA(hdlg
, msg
, wparam
, lparam
);
1504 static void dlg_test_aw_message(HWND hdlg
, UINT msg
)
1506 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SNDMSGA
));
1507 SendMessageA(hdlg
, msg
, 0, (LPARAM
)testtext
);
1509 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SNDMSGW
));
1510 SendMessageW(hdlg
, msg
, 0, (LPARAM
)testtextW
);
1512 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_DLGPROCA
));
1513 DefDlgProcA(hdlg
, msg
, 0, (LPARAM
)testtext
);
1515 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_DLGPROCW
));
1516 DefDlgProcW(hdlg
, msg
, 0, (LPARAM
)testtextW
);
1519 static INT_PTR CALLBACK
test_aw_conversion_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1521 ULONG_PTR dlgproc
, originalproc
;
1530 ok(IsWindowUnicode(hdlg
), "Expected unicode window.\n");
1532 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1533 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1534 dlg_test_aw_message(hdlg
, CB_DIR
);
1535 dlg_test_aw_message(hdlg
, LB_DIR
);
1536 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1537 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1538 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1540 /* WM_SETTEXT/WM_GETTEXT */
1541 originalproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1542 ok(originalproc
== (ULONG_PTR
)test_aw_conversion_dlgproc
, "Unexpected dlg proc %#lx.\n", originalproc
);
1544 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1545 ok(dlgproc
!= (ULONG_PTR
)test_aw_conversion_dlgproc
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1547 dlgproc
= SetWindowLongPtrA(hdlg
, DWLP_DLGPROC
, (UINT_PTR
)test_aw_conversion_dlgprocA
);
1548 ok(IsWindowUnicode(hdlg
), "Expected unicode window.\n");
1550 dlgproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1551 ok(dlgproc
!= (ULONG_PTR
)test_aw_conversion_dlgprocA
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1553 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1554 ok(dlgproc
== (ULONG_PTR
)test_aw_conversion_dlgprocA
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1556 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTA
));
1557 ret
= SetWindowTextA(hdlg
, testtext
);
1559 ok(ret
, "Failed to set window text.\n");
1561 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTW
));
1562 ret
= SetWindowTextW(hdlg
, testtextW
);
1564 ok(ret
, "Failed to set window text.\n");
1566 memset(buff
, 'A', sizeof(buff
));
1567 len
= GetWindowTextA(hdlg
, buff
, sizeof(buff
));
1568 ok(buff
[0] == 0 && buff
[1] == 'A' && len
== 0, "Unexpected window text %#x, %#x, len %d\n",
1569 (BYTE
)buff
[0], (BYTE
)buff
[1], len
);
1571 memset(buffW
, 0xff, sizeof(buffW
));
1572 len
= GetWindowTextW(hdlg
, buffW
, 64);
1573 ok(!lstrcmpW(buffW
, testtextW
) && len
== 0, "Unexpected window text %s, len %d\n", wine_dbgstr_w(buffW
), len
);
1575 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1576 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1577 dlg_test_aw_message(hdlg
, CB_DIR
);
1578 dlg_test_aw_message(hdlg
, LB_DIR
);
1579 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1580 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1581 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1583 dlgproc
= SetWindowLongPtrW(hdlg
, DWLP_DLGPROC
, (UINT_PTR
)test_aw_conversion_dlgprocW
);
1584 ok(IsWindowUnicode(hdlg
), "Expected unicode window.\n");
1586 dlgproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1587 ok(dlgproc
== (ULONG_PTR
)test_aw_conversion_dlgprocW
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1589 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1590 ok(dlgproc
!= (ULONG_PTR
)test_aw_conversion_dlgprocW
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1592 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTA
));
1593 ret
= SetWindowTextA(hdlg
, testtext
);
1595 ok(ret
, "Failed to set window text.\n");
1597 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTW
));
1598 ret
= SetWindowTextW(hdlg
, testtextW
);
1600 ok(ret
, "Failed to set window text.\n");
1602 memset(buff
, 'A', sizeof(buff
));
1603 len
= GetWindowTextA(hdlg
, buff
, sizeof(buff
));
1604 ok(buff
[0] == 0 && buff
[1] == 'A' && len
== 0, "Unexpected window text %#x, %#x, len %d\n",
1605 (BYTE
)buff
[0], (BYTE
)buff
[1], len
);
1607 memset(buffW
, 0xff, sizeof(buffW
));
1608 len
= GetWindowTextW(hdlg
, buffW
, ARRAY_SIZE(buffW
));
1609 ok(buffW
[0] == 'W' && buffW
[1] == 0xffff && len
== 0, "Unexpected window text %#x, %#x, len %d\n",
1610 buffW
[0], buffW
[1], len
);
1612 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1613 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1614 dlg_test_aw_message(hdlg
, CB_DIR
);
1615 dlg_test_aw_message(hdlg
, LB_DIR
);
1616 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1617 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1618 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1620 SetWindowLongPtrA(hdlg
, DWLP_DLGPROC
, originalproc
);
1621 EndDialog(hdlg
, -123);
1627 static INT_PTR CALLBACK
test_aw_conversion_dlgproc2(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1629 ULONG_PTR dlgproc
, originalproc
;
1638 ok(!IsWindowUnicode(hdlg
), "Unexpected unicode window.\n");
1640 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1641 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1642 dlg_test_aw_message(hdlg
, CB_DIR
);
1643 dlg_test_aw_message(hdlg
, LB_DIR
);
1644 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1645 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1646 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1648 originalproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1649 ok(originalproc
!= (ULONG_PTR
)test_aw_conversion_dlgproc2
, "Unexpected dlg proc %#lx.\n", originalproc
);
1651 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1652 ok(dlgproc
== (ULONG_PTR
)test_aw_conversion_dlgproc2
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1654 dlgproc
= SetWindowLongPtrA(hdlg
, DWLP_DLGPROC
, (UINT_PTR
)test_aw_conversion_dlgprocW
);
1655 ok(!IsWindowUnicode(hdlg
), "Unexpected unicode window.\n");
1657 dlgproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1658 ok(dlgproc
!= (ULONG_PTR
)test_aw_conversion_dlgprocW
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1660 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1661 ok(dlgproc
== (ULONG_PTR
)test_aw_conversion_dlgprocW
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1663 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTA
));
1664 ret
= SetWindowTextA(hdlg
, testtext
);
1666 ok(ret
, "Failed to set window text.\n");
1668 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTW
));
1669 ret
= SetWindowTextW(hdlg
, testtextW
);
1671 ok(ret
, "Failed to set window text.\n");
1673 memset(buff
, 'A', sizeof(buff
));
1674 len
= GetWindowTextA(hdlg
, buff
, sizeof(buff
));
1675 ok(!strcmp(buff
, testtext
) && len
== 0, "Unexpected window text %s, len %d\n", buff
, len
);
1677 memset(buffW
, 0xff, sizeof(buffW
));
1678 len
= GetWindowTextW(hdlg
, buffW
, 64);
1679 ok(buffW
[0] == 0 && buffW
[1] == 0xffff && len
== 0, "Unexpected window text %s, len %d\n",
1680 wine_dbgstr_w(buffW
), len
);
1682 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1683 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1684 dlg_test_aw_message(hdlg
, CB_DIR
);
1685 dlg_test_aw_message(hdlg
, LB_DIR
);
1686 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1687 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1688 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1690 dlgproc
= SetWindowLongPtrW(hdlg
, DWLP_DLGPROC
, (UINT_PTR
)test_aw_conversion_dlgprocA
);
1691 ok(!IsWindowUnicode(hdlg
), "Unexpected unicode window.\n");
1693 dlgproc
= GetWindowLongPtrW(hdlg
, DWLP_DLGPROC
);
1694 ok(dlgproc
== (ULONG_PTR
)test_aw_conversion_dlgprocA
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1696 dlgproc
= GetWindowLongPtrA(hdlg
, DWLP_DLGPROC
);
1697 ok(dlgproc
!= (ULONG_PTR
)test_aw_conversion_dlgprocA
, "Unexpected dlg proc %#lx.\n", dlgproc
);
1699 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTA
));
1700 ret
= SetWindowTextA(hdlg
, testtext
);
1702 ok(ret
, "Failed to set window text.\n");
1704 SetPropA(hdlg
, "test_mode", ULongToHandle(DLGPROCTEXT_SETTEXTW
));
1705 ret
= SetWindowTextW(hdlg
, testtextW
);
1707 ok(ret
, "Failed to set window text.\n");
1709 memset(buff
, 'A', sizeof(buff
));
1710 len
= GetWindowTextA(hdlg
, buff
, sizeof(buff
));
1711 ok(!strcmp(buff
, testtext
) && len
== 0, "Unexpected window text %s, len %d\n", buff
, len
);
1713 memset(buffW
, 0xff, sizeof(buffW
));
1714 len
= GetWindowTextW(hdlg
, buffW
, ARRAY_SIZE(buffW
));
1715 ok(buffW
[0] == 0 && buffW
[1] == 0xffff && len
== 0, "Unexpected window text %#x, %#x, len %d\n",
1716 buffW
[0], buffW
[1], len
);
1718 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1719 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1720 dlg_test_aw_message(hdlg
, CB_DIR
);
1721 dlg_test_aw_message(hdlg
, LB_DIR
);
1722 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1723 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1724 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1726 SetWindowLongPtrA(hdlg
, DWLP_DLGPROC
, originalproc
);
1727 EndDialog(hdlg
, -123);
1733 static LRESULT CALLBACK
test_aw_conversion_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1735 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
1736 int mode
= HandleToULong(GetPropA(hwnd
, "test_mode"));
1737 WCHAR
*text
= (WCHAR
*)lparam
;
1738 char *textA
= (char *)lparam
;
1743 case WM_WININICHANGE
:
1744 case WM_DEVMODECHANGE
:
1751 case DLGPROCTEXT_SNDMSGA
:
1752 if (IsWindowUnicode(hwnd
))
1753 ok(text
!= testtextW
&& !lstrcmpW(text
, testtextW
),
1754 "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1756 ok(textA
== testtext
, "A: %s, unexpected text %s.\n", testmodes
[mode
], textA
);
1758 case DLGPROCTEXT_SNDMSGW
:
1759 if (IsWindowUnicode(hwnd
))
1760 ok(text
== testtextW
, "U: %s, unexpected text %s.\n", testmodes
[mode
], wine_dbgstr_w(text
));
1762 ok(textA
!= testtext
&& !strcmp(textA
, testtext
), "A: %s, unexpected text %s.\n",
1763 testmodes
[mode
], textA
);
1766 ok(0, "Unexpected test mode %d.\n", mode
);
1771 return IsWindowUnicode(hwnd
) ? CallWindowProcW(oldproc
, hwnd
, msg
, wparam
, lparam
) :
1772 CallWindowProcA(oldproc
, hwnd
, msg
, wparam
, lparam
);
1775 static INT_PTR CALLBACK
test_aw_conversion_dlgproc3(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1777 BOOL is_unicode
= !!lparam
;
1783 ok(is_unicode
== IsWindowUnicode(hdlg
), "Unexpected unicode window property.\n");
1785 oldproc
= SetWindowLongPtrA(hdlg
, GWLP_WNDPROC
, (LONG_PTR
)test_aw_conversion_wndproc
);
1786 SetWindowLongPtrA(hdlg
, GWLP_USERDATA
, oldproc
);
1787 ok(!IsWindowUnicode(hdlg
), "Unexpected unicode window.\n");
1789 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1790 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1791 dlg_test_aw_message(hdlg
, CB_DIR
);
1792 dlg_test_aw_message(hdlg
, LB_DIR
);
1793 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1794 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1795 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1797 SetWindowLongPtrW(hdlg
, GWLP_WNDPROC
, (LONG_PTR
)test_aw_conversion_wndproc
);
1798 ok(IsWindowUnicode(hdlg
), "Expected unicode window.\n");
1800 dlg_test_aw_message(hdlg
, WM_WININICHANGE
);
1801 dlg_test_aw_message(hdlg
, WM_DEVMODECHANGE
);
1802 dlg_test_aw_message(hdlg
, CB_DIR
);
1803 dlg_test_aw_message(hdlg
, LB_DIR
);
1804 dlg_test_aw_message(hdlg
, LB_ADDFILE
);
1805 dlg_test_aw_message(hdlg
, EM_REPLACESEL
);
1806 dlg_test_aw_message(hdlg
, WM_SETTEXT
);
1808 SetWindowLongPtrA(hdlg
, GWLP_WNDPROC
, oldproc
);
1809 EndDialog(hdlg
, -123);
1815 static void test_DialogBoxParam(void)
1817 static const WCHAR nameW
[] = {'T','E','S','T','_','E','M','P','T','Y','_','D','I','A','L','O','G',0};
1819 HWND hwnd_invalid
= (HWND
)0x4444;
1821 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_DLG_CHILD_POPUP", 0, TestControlStyleDlgProc
, 0);
1822 ok(ret
== -7, "expected -7, got %ld\n", ret
);
1824 SetLastError(0xdeadbeef);
1825 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "IDD_DIALOG" , hwnd_invalid
, 0 , 0);
1826 ok(0 == ret
|| broken(ret
== -1), "DialogBoxParamA returned %ld, expected 0\n", ret
);
1827 ok(ERROR_INVALID_WINDOW_HANDLE
== GetLastError() ||
1828 broken(GetLastError() == 0xdeadbeef),
1829 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n",GetLastError());
1831 /* Test a dialog which destroys itself on WM_INITDIALOG. */
1832 SetLastError(0xdeadbeef);
1833 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "IDD_DIALOG", 0, DestroyDlgWinProc
, 0);
1834 ok(-1 == ret
, "DialogBoxParamA returned %ld, expected -1\n", ret
);
1835 ok(ERROR_INVALID_WINDOW_HANDLE
== GetLastError() ||
1836 GetLastError() == ERROR_SUCCESS
||
1837 broken(GetLastError() == 0xdeadbeef),
1838 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n",GetLastError());
1840 /* Test a dialog which destroys itself on WM_CLOSE. */
1841 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "IDD_DIALOG", 0, DestroyOnCloseDlgWinProc
, 0);
1842 ok(0 == ret
, "DialogBoxParamA returned %ld, expected 0\n", ret
);
1844 SetLastError(0xdeadbeef);
1845 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "RESOURCE_INVALID" , 0, 0, 0);
1846 ok(-1 == ret
, "DialogBoxParamA returned %ld, expected -1\n", ret
);
1847 ok(ERROR_RESOURCE_NAME_NOT_FOUND
== GetLastError() ||
1848 broken(GetLastError() == 0xdeadbeef),
1849 "got %d, expected ERROR_RESOURCE_NAME_NOT_FOUND\n",GetLastError());
1851 SetLastError(0xdeadbeef);
1852 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_DIALOG_INVALID_CLASS", 0, DestroyDlgWinProc
, 0);
1853 ok(ret
== -1, "DialogBoxParamA returned %ld, expected -1\n", ret
);
1854 ok(GetLastError() == 0, "got %d\n", GetLastError());
1856 SetLastError(0xdeadbeef);
1857 ret
= DefDlgProcA(0, WM_ERASEBKGND
, 0, 0);
1858 ok(ret
== 0, "DefDlgProcA returned %ld, expected 0\n", ret
);
1859 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
1860 broken(GetLastError() == 0xdeadbeef),
1861 "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
1863 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", 0, TestInitDialogHandleProc
, 0);
1864 ok(ret
== IDOK
, "Expected IDOK\n");
1866 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", 0, TestDefButtonDlgProc
, 0);
1867 ok(ret
== IDOK
, "Expected IDOK\n");
1869 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", 0, TestReturnKeyDlgProc
, 0);
1870 ok(ret
== 0, "Unexpected ret value %ld.\n", ret
);
1872 /* WM_SETTEXT handling in case of A/W dialog procedures vs A/W dialog window. */
1873 ret
= DialogBoxParamW(GetModuleHandleA(NULL
), nameW
, 0, test_aw_conversion_dlgproc
, 0);
1874 ok(ret
== -123, "Unexpected ret value %ld.\n", ret
);
1876 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", 0, test_aw_conversion_dlgproc2
, 0);
1877 ok(ret
== -123, "Unexpected ret value %ld.\n", ret
);
1879 ret
= DialogBoxParamW(GetModuleHandleA(NULL
), nameW
, 0, test_aw_conversion_dlgproc3
, 1);
1880 ok(ret
== -123, "Unexpected ret value %ld.\n", ret
);
1882 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", 0, test_aw_conversion_dlgproc3
, 0);
1883 ok(ret
== -123, "Unexpected ret value %ld.\n", ret
);
1886 static void test_DisabledDialogTest(void)
1888 g_terminated
= FALSE
;
1889 DialogBoxParamA(g_hinst
, "IDD_DIALOG", NULL
, disabled_test_proc
, 0);
1890 ok(FALSE
== g_terminated
, "dialog with disabled ok button has been terminated\n");
1893 static INT_PTR CALLBACK
messageBoxFontDlgWinProc (HWND hDlg
, UINT uiMsg
, WPARAM wParam
,
1896 if (uiMsg
== WM_INITDIALOG
) {
1904 static void test_MessageBoxFontTest(void)
1906 /* This dialog template defines a dialog template which got 0x7fff as its
1907 * font size and omits the other font members. On WinNT, passing such a
1908 * dialog template to CreateDialogIndirectParamW will result in a dialog
1909 * being created which uses the message box font. We test that here.
1912 static unsigned char dlgTemplate
[] =
1915 0x01,0x00, /* Version */
1916 0xff,0xff, /* Extended template marker */
1917 0x00,0x00,0x00,0x00, /* Context Help ID */
1918 0x00,0x00,0x00,0x00, /* Extended style */
1919 0xc0,0x00,0xc8,0x80, /* Style (WS_SYSMENU|WS_CAPTION|WS_POPUP|DS_SETFONT|DS_MODALFRAME) */
1920 0x01,0x00, /* Control count */
1923 0x80,0x00, /* Width */
1924 0x80,0x00, /* Height */
1925 0x00,0x00, /* Menu name */
1926 0x00,0x00, /* Class name */
1927 'T',0x00,'e',0x00, /* Caption (unicode) */
1930 0xff,0x7f, /* Font height (0x7fff = message box font) */
1933 0x00,0x00, /* Align to DWORD (header is 42 bytes) */
1934 0x00,0x00,0x00,0x00, /* Context Help ID */
1935 0x00,0x00,0x00,0x00, /* Extended style */
1936 0x00,0x00,0x00,0x50, /* Style (WS_CHILD|WS_VISIBLE) */
1939 0x80,0x00, /* Width */
1940 0x80,0x00, /* Height */
1941 0x00,0x01,0x00,0x00, /* Control ID (256) */
1942 0xff,0xff,0x82,0x00, /* Class (Static) */
1943 'W',0x00,'I',0x00, /* Caption (unicode) */
1952 0x00,0x00, /* Size of extended data */
1954 0x00,0x00 /* Align to DWORD */
1959 LOGFONTW lfStaticFont
;
1960 NONCLIENTMETRICSW ncMetrics
;
1962 /* Check if the dialog can be created from the template. On Win9x, this should fail
1963 * because we are calling the W function which is not implemented, but that's what
1964 * we want, because passing such a template to CreateDialogIndirectParamA would crash
1967 hDlg
= CreateDialogIndirectParamW(g_hinst
, (LPCDLGTEMPLATEW
)dlgTemplate
, NULL
, messageBoxFontDlgWinProc
, 0);
1970 win_skip("dialog wasn't created\n");
1974 hFont
= (HFONT
) SendDlgItemMessageW(hDlg
, 256, WM_GETFONT
, 0, 0);
1977 skip("dialog uses system font\n");
1978 DestroyWindow(hDlg
);
1981 GetObjectW(hFont
, sizeof(LOGFONTW
), &lfStaticFont
);
1983 ncMetrics
.cbSize
= FIELD_OFFSET(NONCLIENTMETRICSW
, iPaddedBorderWidth
);
1984 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &ncMetrics
, 0);
1985 /* The height doesn't match on Windows 10 1709+. */
1986 ncMetrics
.lfMessageFont
.lfHeight
= lfStaticFont
.lfHeight
;
1987 ok( !memcmp(&lfStaticFont
, &ncMetrics
.lfMessageFont
, FIELD_OFFSET(LOGFONTW
, lfFaceName
)) &&
1988 !lstrcmpW(lfStaticFont
.lfFaceName
, ncMetrics
.lfMessageFont
.lfFaceName
),
1989 "dialog doesn't use message box font\n");
1990 DestroyWindow(hDlg
);
1993 static void test_SaveRestoreFocus(void)
1998 DLGTEMPLATE
* pTemplate
;
2002 /* create the dialog */
2003 hResource
= FindResourceA(g_hinst
, "MULTI_EDIT_DIALOG", (LPCSTR
)RT_DIALOG
);
2004 hTemplate
= LoadResource(g_hinst
, hResource
);
2005 pTemplate
= LockResource(hTemplate
);
2007 hDlg
= CreateDialogIndirectParamA(g_hinst
, pTemplate
, NULL
, messageBoxFontDlgWinProc
, 0);
2008 ok (hDlg
!= 0, "Failed to create test dialog.\n");
2010 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2011 ok (foundId
== 1000, "First edit box should have gained focus on dialog creation. Expected: %d, Found: %ld\n", 1000, foundId
);
2013 SetFocus(GetNextDlgTabItem(hDlg
, GetFocus(), FALSE
));
2014 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
2015 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2016 ok (foundId
== 1001, "First edit box should have regained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId
);
2017 SetFocus(GetNextDlgTabItem(hDlg
, NULL
, FALSE
));
2019 /* de- then reactivate the dialog */
2020 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
2021 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
2023 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2024 ok (foundId
== 1000, "First edit box should have regained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1000, foundId
);
2026 /* select the next tabbable item */
2027 SetFocus(GetNextDlgTabItem(hDlg
, GetFocus(), FALSE
));
2029 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2030 ok (foundId
== 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId
);
2032 /* de- then reactivate the dialog */
2033 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
2034 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
2036 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2037 ok (foundId
== 1001, "Second edit box should have gained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId
);
2039 /* set focus to the dialog */
2042 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2043 ok (foundId
== 1000, "First edit box should have gained focus on dialog focus. Expected: %d, Found: %ld\n", 1000, foundId
);
2045 /* select second tabbable item */
2046 SetFocus(GetNextDlgTabItem(hDlg
, GetNextDlgTabItem(hDlg
, NULL
, FALSE
), FALSE
));
2048 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2049 ok (foundId
== 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId
);
2051 /* send WM_ACTIVATE message to already active dialog */
2052 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
2054 foundId
= GetWindowLongPtrA(GetFocus(), GWLP_ID
);
2055 ok (foundId
== 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId
);
2057 /* disable the 2nd box */
2058 EnableWindow(GetFocus(), FALSE
);
2060 foundHwnd
= GetFocus();
2061 ok (foundHwnd
== NULL
, "Second edit box should have lost focus after being disabled. Expected: %p, Found: %p\n", NULL
, foundHwnd
);
2063 /* de- then reactivate the dialog */
2064 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_INACTIVE
, 0), 0);
2065 SendMessageA(hDlg
, WM_ACTIVATE
, MAKEWPARAM(WA_ACTIVE
, 0), 0);
2067 foundHwnd
= GetFocus();
2068 ok (foundHwnd
== NULL
, "No controls should have gained focus after dialog reactivation. Expected: %p, Found: %p\n", NULL
, foundHwnd
);
2071 DestroyWindow(hDlg
);
2074 static INT_PTR CALLBACK
timer_message_dlg_proc(HWND wnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2082 visible
= GetWindowLongA(wnd
, GWL_STYLE
) & WS_VISIBLE
;
2083 ok(!visible
, "Dialog should not be visible.\n");
2084 SetTimer(wnd
, 1, 100, NULL
);
2089 if (LOWORD(wparam
) != IDCANCEL
) return FALSE
;
2090 EndDialog(wnd
, LOWORD(wparam
));
2094 if (wparam
!= 1) return FALSE
;
2095 visible
= GetWindowLongA(wnd
, GWL_STYLE
) & WS_VISIBLE
;
2098 ok(!visible
, "Dialog should not be visible.\n");
2099 PostMessageA(wnd
, WM_USER
, 0, 0);
2103 ok(visible
, "Dialog should be visible.\n");
2104 PostMessageA(wnd
, WM_COMMAND
, IDCANCEL
, 0);
2109 visible
= GetWindowLongA(wnd
, GWL_STYLE
) & WS_VISIBLE
;
2110 ok(visible
, "Dialog should be visible.\n");
2118 static void test_timer_message(void)
2120 DialogBoxA(g_hinst
, "RADIO_TEST_DIALOG", NULL
, timer_message_dlg_proc
);
2123 static LRESULT CALLBACK
msgbox_hook_proc(INT code
, WPARAM wParam
, LPARAM lParam
)
2125 if (code
== HCBT_ACTIVATE
)
2127 HWND msgbox
= (HWND
)wParam
, msghwnd
;
2133 GetWindowTextA(msgbox
, text
, sizeof(text
));
2134 ok(!strcmp(text
, "MSGBOX caption"), "Unexpected window text \"%s\"\n", text
);
2136 msghwnd
= GetDlgItem(msgbox
, 0xffff);
2137 ok(msghwnd
!= NULL
, "Expected static control\n");
2140 GetWindowTextA(msghwnd
, text
, sizeof(text
));
2141 ok(!strcmp(text
, "Text"), "Unexpected window text \"%s\"\n", text
);
2143 SendDlgItemMessageA(msgbox
, IDCANCEL
, WM_LBUTTONDOWN
, 0, 0);
2144 SendDlgItemMessageA(msgbox
, IDCANCEL
, WM_LBUTTONUP
, 0, 0);
2148 return CallNextHookEx(NULL
, code
, wParam
, lParam
);
2151 static void test_MessageBox(void)
2156 hook
= SetWindowsHookExA(WH_CBT
, msgbox_hook_proc
, NULL
, GetCurrentThreadId());
2158 ret
= MessageBoxA(NULL
, "Text", "MSGBOX caption", MB_OKCANCEL
);
2159 ok(ret
== IDCANCEL
, "got %d\n", ret
);
2161 UnhookWindowsHookEx(hook
);
2164 static INT_PTR CALLBACK
custom_test_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2166 if (msg
== WM_INITDIALOG
)
2172 static void test_dialog_custom_data(void)
2174 DialogBoxA(g_hinst
, "CUSTOM_TEST_DIALOG", NULL
, custom_test_dialog_proc
);
2177 static INT_PTR CALLBACK
capture_release_proc(HWND dialog
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2179 if (message
== WM_INITDIALOG
)
2181 HWND child
= (HWND
)lparam
;
2184 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
2185 style
= GetWindowLongA(child
, GWL_STYLE
);
2186 ok(!(style
& WS_DISABLED
), "child should not be disabled\n");
2188 PostMessageA(dialog
, WM_USER
, 0, (LPARAM
)child
);
2190 else if (message
== WM_USER
)
2192 HWND child
= (HWND
)lparam
;
2195 ok(!GetCapture(), "got capture %p\n", GetCapture());
2196 style
= GetWindowLongA(child
, GWL_STYLE
);
2197 ok(!(style
& WS_DISABLED
), "child should not be disabled\n");
2199 EndDialog(dialog
, 1);
2204 static INT_PTR CALLBACK
capture_release_modeless_proc(HWND dialog
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2206 if (message
== WM_INITDIALOG
)
2208 HWND child
= (HWND
)lparam
;
2211 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
2212 style
= GetWindowLongA(child
, GWL_STYLE
);
2213 ok(!(style
& WS_DISABLED
), "child should not be disabled\n");
2215 PostMessageA(dialog
, WM_QUIT
, 0, 0);
2220 static void test_capture_release(void)
2222 HWND window
, child
, dialog
;
2226 /* Set the capture to a child window. The main window will receive
2227 * WM_CANCELMODE when being disabled, but the child window will retain
2230 window
= CreateWindowA("static", "parent", 0, 100, 200, 300, 400, NULL
, NULL
, NULL
, NULL
);
2231 child
= CreateWindowA("static", "child", WS_CHILD
, 10, 20, 100, 100, window
, NULL
, NULL
, NULL
);
2234 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", NULL
, capture_release_proc
, (LPARAM
)child
);
2235 ok(ret
== 1, "got %#Ix\n", ret
);
2236 ok(!GetCapture(), "got capture %p\n", GetCapture());
2239 ret
= DialogBoxParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG", window
, capture_release_proc
, (LPARAM
)child
);
2240 ok(ret
== 1, "got %#Ix\n", ret
);
2241 ok(!GetCapture(), "got capture %p\n", GetCapture());
2244 dialog
= CreateDialogParamA(GetModuleHandleA(NULL
), "TEST_EMPTY_DIALOG",
2245 window
, capture_release_modeless_proc
, (LPARAM
)child
);
2246 ok(!!dialog
, "failed to create dialog\n");
2247 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
2248 ShowWindow(dialog
, SW_SHOWNORMAL
);
2249 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
2250 while (GetMessageA(&msg
, NULL
, 0, 0))
2251 DispatchMessageA(&msg
);
2252 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
2254 DestroyWindow(dialog
);
2256 DestroyWindow(child
);
2257 DestroyWindow(window
);
2262 g_hinst
= GetModuleHandleA (0);
2264 if (!RegisterWindowClasses()) assert(0);
2266 test_dialog_custom_data();
2267 test_GetNextDlgItem();
2268 test_IsDialogMessage();
2269 test_WM_NEXTDLGCTL();
2272 test_GetDlgItemText();
2273 test_DialogBoxParam();
2274 test_DisabledDialogTest();
2275 test_MessageBoxFontTest();
2276 test_SaveRestoreFocus();
2277 test_timer_message();
2279 test_capture_release();