user: ChangeDisplaySettings virtual desktop mode handling fix.
[wine] / dlls / user / dialog.c
1 /*
2  * Dialog functions
3  *
4  * Copyright 1993, 1994, 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <ctype.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winnls.h"
37 #include "wine/winuser16.h"
38 #include "wine/unicode.h"
39 #include "controls.h"
40 #include "win.h"
41 #include "user_private.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
45
46
47   /* Dialog control information */
48 typedef struct
49 {
50     DWORD      style;
51     DWORD      exStyle;
52     DWORD      helpId;
53     INT16      x;
54     INT16      y;
55     INT16      cx;
56     INT16      cy;
57     UINT_PTR   id;
58     LPCWSTR    className;
59     LPCWSTR    windowName;
60     LPCVOID    data;
61 } DLG_CONTROL_INFO;
62
63   /* Dialog template */
64 typedef struct
65 {
66     DWORD      style;
67     DWORD      exStyle;
68     DWORD      helpId;
69     UINT16     nbItems;
70     INT16      x;
71     INT16      y;
72     INT16      cx;
73     INT16      cy;
74     LPCWSTR    menuName;
75     LPCWSTR    className;
76     LPCWSTR    caption;
77     INT16      pointSize;
78     WORD       weight;
79     BOOL       italic;
80     LPCWSTR    faceName;
81     BOOL       dialogEx;
82 } DLG_TEMPLATE;
83
84   /* Radio button group */
85 typedef struct
86 {
87     UINT firstID;
88     UINT lastID;
89     UINT checkID;
90 } RADIOGROUP;
91
92
93 /*********************************************************************
94  * dialog class descriptor
95  */
96 const struct builtin_class_descr DIALOG_builtin_class =
97 {
98     DIALOG_CLASS_ATOMA,  /* name */
99     CS_SAVEBITS | CS_DBLCLKS, /* style  */
100     DefDlgProcA,        /* procA */
101     DefDlgProcW,        /* procW */
102     DLGWINDOWEXTRA,     /* extra */
103     IDC_ARROW,          /* cursor */
104     0                   /* brush */
105 };
106
107
108 /***********************************************************************
109  *           DIALOG_EnableOwner
110  *
111  * Helper function for modal dialogs to enable again the
112  * owner of the dialog box.
113  */
114 void DIALOG_EnableOwner( HWND hOwner )
115 {
116     /* Owner must be a top-level window */
117     if (hOwner)
118         hOwner = GetAncestor( hOwner, GA_ROOT );
119     if (!hOwner) return;
120     EnableWindow( hOwner, TRUE );
121 }
122
123
124 /***********************************************************************
125  *           DIALOG_DisableOwner
126  *
127  * Helper function for modal dialogs to disable the
128  * owner of the dialog box. Returns TRUE if owner was enabled.
129  */
130 BOOL DIALOG_DisableOwner( HWND hOwner )
131 {
132     /* Owner must be a top-level window */
133     if (hOwner)
134         hOwner = GetAncestor( hOwner, GA_ROOT );
135     if (!hOwner) return FALSE;
136     if (IsWindowEnabled( hOwner ))
137     {
138         EnableWindow( hOwner, FALSE );
139         return TRUE;
140     }
141     else
142         return FALSE;
143 }
144
145 /***********************************************************************
146  *           DIALOG_GetControl32
147  *
148  * Return the class and text of the control pointed to by ptr,
149  * fill the header structure and return a pointer to the next control.
150  */
151 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
152                                         BOOL dialogEx )
153 {
154     if (dialogEx)
155     {
156         info->helpId  = GET_DWORD(p); p += 2;
157         info->exStyle = GET_DWORD(p); p += 2;
158         info->style   = GET_DWORD(p); p += 2;
159     }
160     else
161     {
162         info->helpId  = 0;
163         info->style   = GET_DWORD(p); p += 2;
164         info->exStyle = GET_DWORD(p); p += 2;
165     }
166     info->x       = GET_WORD(p); p++;
167     info->y       = GET_WORD(p); p++;
168     info->cx      = GET_WORD(p); p++;
169     info->cy      = GET_WORD(p); p++;
170
171     if (dialogEx)
172     {
173         /* id is a DWORD for DIALOGEX */
174         info->id = GET_DWORD(p);
175         p += 2;
176     }
177     else
178     {
179         info->id = GET_WORD(p);
180         p++;
181     }
182
183     if (GET_WORD(p) == 0xffff)
184     {
185         static const WCHAR class_names[6][10] =
186         {
187             { 'B','u','t','t','o','n', },             /* 0x80 */
188             { 'E','d','i','t', },                     /* 0x81 */
189             { 'S','t','a','t','i','c', },             /* 0x82 */
190             { 'L','i','s','t','B','o','x', },         /* 0x83 */
191             { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
192             { 'C','o','m','b','o','B','o','x', }      /* 0x85 */
193         };
194         WORD id = GET_WORD(p+1);
195         /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
196         if ((id >= 0x80) && (id <= 0x85)) id -= 0x80;
197         if (id <= 5)
198             info->className = class_names[id];
199         else
200         {
201             info->className = NULL;
202             ERR("Unknown built-in class id %04x\n", id );
203         }
204         p += 2;
205     }
206     else
207     {
208         info->className = (LPCWSTR)p;
209         p += strlenW( info->className ) + 1;
210     }
211
212     if (GET_WORD(p) == 0xffff)  /* Is it an integer id? */
213     {
214         info->windowName = MAKEINTRESOURCEW(GET_WORD(p + 1));
215         p += 2;
216     }
217     else
218     {
219         info->windowName = (LPCWSTR)p;
220         p += strlenW( info->windowName ) + 1;
221     }
222
223     TRACE("    %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
224           debugstr_w( info->className ), debugstr_w( info->windowName ),
225           info->id, info->x, info->y, info->cx, info->cy,
226           info->style, info->exStyle, info->helpId );
227
228     if (GET_WORD(p))
229     {
230         if (TRACE_ON(dialog))
231         {
232             WORD i, count = GET_WORD(p) / sizeof(WORD);
233             TRACE("  BEGIN\n");
234             TRACE("    ");
235             for (i = 0; i < count; i++) TRACE( "%04x,", GET_WORD(p+i+1) );
236             TRACE("\n");
237             TRACE("  END\n" );
238         }
239         info->data = p + 1;
240         p += GET_WORD(p) / sizeof(WORD);
241     }
242     else info->data = NULL;
243     p++;
244
245     /* Next control is on dword boundary */
246     return (const WORD *)(((UINT_PTR)p + 3) & ~3);
247 }
248
249
250 /***********************************************************************
251  *           DIALOG_CreateControls32
252  *
253  * Create the control windows for a dialog.
254  */
255 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
256                                      HINSTANCE hInst, BOOL unicode )
257 {
258     DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd, TRUE );
259     DLG_CONTROL_INFO info;
260     HWND hwndCtrl, hwndDefButton = 0;
261     INT items = dlgTemplate->nbItems;
262
263     TRACE(" BEGIN\n" );
264     while (items--)
265     {
266         template = (LPCSTR)DIALOG_GetControl32( (const WORD *)template, &info,
267                                                 dlgTemplate->dialogEx );
268         /* Is this it? */
269         if (info.style & WS_BORDER)
270         {
271             info.style &= ~WS_BORDER;
272             info.exStyle |= WS_EX_CLIENTEDGE;
273         }
274         if (unicode)
275         {
276             hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
277                                         info.className, info.windowName,
278                                         info.style | WS_CHILD,
279                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
280                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
281                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
282                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
283                                         hwnd, (HMENU)info.id,
284                                         hInst, (LPVOID)info.data );
285         }
286         else
287         {
288             LPSTR class = (LPSTR)info.className;
289             LPSTR caption = (LPSTR)info.windowName;
290
291             if (HIWORD(class))
292             {
293                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
294                 class = HeapAlloc( GetProcessHeap(), 0, len );
295                 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
296             }
297             if (HIWORD(caption))
298             {
299                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
300                 caption = HeapAlloc( GetProcessHeap(), 0, len );
301                 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
302             }
303             hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
304                                         class, caption, info.style | WS_CHILD,
305                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
306                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
307                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
308                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
309                                         hwnd, (HMENU)info.id,
310                                         hInst, (LPVOID)info.data );
311             if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
312             if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
313         }
314         if (!hwndCtrl)
315         {
316             if (dlgTemplate->style & DS_NOFAILCREATE) continue;
317             return FALSE;
318         }
319
320             /* Send initialisation messages to the control */
321         if (dlgInfo->hUserFont) SendMessageW( hwndCtrl, WM_SETFONT,
322                                              (WPARAM)dlgInfo->hUserFont, 0 );
323         if (SendMessageW(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
324         {
325               /* If there's already a default push-button, set it back */
326               /* to normal and use this one instead. */
327             if (hwndDefButton)
328                 SendMessageW( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
329             hwndDefButton = hwndCtrl;
330             dlgInfo->idResult = GetWindowLongPtrA( hwndCtrl, GWLP_ID );
331         }
332     }
333     TRACE(" END\n" );
334     return TRUE;
335 }
336
337
338 /***********************************************************************
339  *           DIALOG_ParseTemplate32
340  *
341  * Fill a DLG_TEMPLATE structure from the dialog template, and return
342  * a pointer to the first control.
343  */
344 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
345 {
346     const WORD *p = (const WORD *)template;
347     WORD signature;
348     WORD dlgver;
349
350     signature = GET_WORD(p); p++;
351     dlgver = GET_WORD(p); p++;
352
353     if (signature == 1 && dlgver == 0xffff)  /* DIALOGEX resource */
354     {
355         result->dialogEx = TRUE;
356         result->helpId   = GET_DWORD(p); p += 2;
357         result->exStyle  = GET_DWORD(p); p += 2;
358         result->style    = GET_DWORD(p); p += 2;
359     }
360     else
361     {
362         result->style = GET_DWORD(p - 2);
363         result->dialogEx = FALSE;
364         result->helpId   = 0;
365         result->exStyle  = GET_DWORD(p); p += 2;
366     }
367     result->nbItems = GET_WORD(p); p++;
368     result->x       = GET_WORD(p); p++;
369     result->y       = GET_WORD(p); p++;
370     result->cx      = GET_WORD(p); p++;
371     result->cy      = GET_WORD(p); p++;
372     TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
373            result->dialogEx ? "EX" : "", result->x, result->y,
374            result->cx, result->cy, result->helpId );
375     TRACE(" STYLE 0x%08lx\n", result->style );
376     TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
377
378     /* Get the menu name */
379
380     switch(GET_WORD(p))
381     {
382     case 0x0000:
383         result->menuName = NULL;
384         p++;
385         break;
386     case 0xffff:
387         result->menuName = MAKEINTRESOURCEW(GET_WORD( p + 1 ));
388         p += 2;
389         TRACE(" MENU %04x\n", LOWORD(result->menuName) );
390         break;
391     default:
392         result->menuName = (LPCWSTR)p;
393         TRACE(" MENU %s\n", debugstr_w(result->menuName) );
394         p += strlenW( result->menuName ) + 1;
395         break;
396     }
397
398     /* Get the class name */
399
400     switch(GET_WORD(p))
401     {
402     case 0x0000:
403         result->className = DIALOG_CLASS_ATOMW;
404         p++;
405         break;
406     case 0xffff:
407         result->className = MAKEINTRESOURCEW(GET_WORD( p + 1 ));
408         p += 2;
409         TRACE(" CLASS %04x\n", LOWORD(result->className) );
410         break;
411     default:
412         result->className = (LPCWSTR)p;
413         TRACE(" CLASS %s\n", debugstr_w( result->className ));
414         p += strlenW( result->className ) + 1;
415         break;
416     }
417
418     /* Get the window caption */
419
420     result->caption = (LPCWSTR)p;
421     p += strlenW( result->caption ) + 1;
422     TRACE(" CAPTION %s\n", debugstr_w( result->caption ) );
423
424     /* Get the font name */
425
426     result->pointSize = 0;
427     result->faceName = NULL;
428     result->weight = FW_DONTCARE;
429     result->italic = FALSE;
430
431     if (result->style & DS_SETFONT)
432     {
433         result->pointSize = GET_WORD(p);
434         p++;
435         if (result->dialogEx)
436         {
437             result->weight = GET_WORD(p); p++;
438             result->italic = LOBYTE(GET_WORD(p)); p++;
439         }
440         result->faceName = (LPCWSTR)p;
441         p += strlenW( result->faceName ) + 1;
442         TRACE(" FONT %d, %s, %d, %s\n",
443               result->pointSize, debugstr_w( result->faceName ),
444               result->weight, result->italic ? "TRUE" : "FALSE" );
445     }
446
447     /* First control is on dword boundary */
448     return (LPCSTR)(((UINT_PTR)p + 3) & ~3);
449 }
450
451
452 /***********************************************************************
453  *           DIALOG_CreateIndirect
454  *       Creates a dialog box window
455  *
456  *       modal = TRUE if we are called from a modal dialog box.
457  *       (it's more compatible to do it here, as under Windows the owner
458  *       is never disabled if the dialog fails because of an invalid template)
459  */
460 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
461                                    HWND owner, DLGPROC dlgProc, LPARAM param,
462                                    BOOL unicode, BOOL modal )
463 {
464     HWND hwnd;
465     RECT rect;
466     DLG_TEMPLATE template;
467     DIALOGINFO * dlgInfo = NULL;
468     DWORD units = GetDialogBaseUnits();
469     BOOL ownerEnabled = TRUE;
470     HMENU hMenu = 0;
471     HFONT hUserFont = 0;
472     UINT flags = 0;
473     UINT xBaseUnit = LOWORD(units);
474     UINT yBaseUnit = HIWORD(units);
475
476       /* Parse dialog template */
477
478     if (!dlgTemplate) return 0;
479     dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
480
481       /* Load menu */
482
483     if (template.menuName) hMenu = LoadMenuW( hInst, template.menuName );
484
485       /* Create custom font if needed */
486
487     if (template.style & DS_SETFONT)
488     {
489           /* We convert the size to pixels and then make it -ve.  This works
490            * for both +ve and -ve template.pointSize */
491         HDC dc;
492         int pixels;
493         dc = GetDC(0);
494         pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
495         hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
496                                           template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
497                                           PROOF_QUALITY, FF_DONTCARE,
498                                           template.faceName );
499         if (hUserFont)
500         {
501             SIZE charSize;
502             HFONT hOldFont = SelectObject( dc, hUserFont );
503             charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy );
504             if (charSize.cx)
505             {
506                 xBaseUnit = charSize.cx;
507                 yBaseUnit = charSize.cy;
508             }
509             SelectObject( dc, hOldFont );
510         }
511         ReleaseDC(0, dc);
512         TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
513     }
514
515     /* Create dialog main window */
516
517     rect.left = rect.top = 0;
518     rect.right = MulDiv(template.cx, xBaseUnit, 4);
519     rect.bottom =  MulDiv(template.cy, yBaseUnit, 8);
520     if (template.style & WS_CHILD)
521         template.style &= ~(WS_CAPTION|WS_SYSMENU);
522     if (template.style & DS_MODALFRAME)
523         template.exStyle |= WS_EX_DLGMODALFRAME;
524     if (template.style & DS_CONTROL)
525         template.exStyle |= WS_EX_CONTROLPARENT;
526     AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
527     rect.right -= rect.left;
528     rect.bottom -= rect.top;
529
530     if (template.x == CW_USEDEFAULT16)
531     {
532         rect.left = rect.top = CW_USEDEFAULT;
533     }
534     else
535     {
536         if (template.style & DS_CENTER)
537         {
538             rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
539             rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
540         }
541         else
542         {
543             rect.left += MulDiv(template.x, xBaseUnit, 4);
544             rect.top += MulDiv(template.y, yBaseUnit, 8);
545         }
546         if ( !(template.style & WS_CHILD) )
547         {
548             INT dX, dY;
549
550             if( !(template.style & DS_ABSALIGN) )
551                 ClientToScreen( owner, (POINT *)&rect );
552
553             /* try to fit it into the desktop */
554
555             if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
556                  - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
557             if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
558                  - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
559             if( rect.left < 0 ) rect.left = 0;
560             if( rect.top < 0 ) rect.top = 0;
561         }
562     }
563
564     if (modal)
565     {
566         ownerEnabled = DIALOG_DisableOwner( owner );
567         if (ownerEnabled) flags |= DF_OWNERENABLED;
568     }
569
570     if (unicode)
571     {
572         hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
573                                template.style & ~WS_VISIBLE,
574                                rect.left, rect.top, rect.right, rect.bottom,
575                                owner, hMenu, hInst, NULL );
576     }
577     else
578     {
579         LPSTR class = (LPSTR)template.className;
580         LPSTR caption = (LPSTR)template.caption;
581
582         if (HIWORD(class))
583         {
584             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
585             class = HeapAlloc( GetProcessHeap(), 0, len );
586             WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
587         }
588         if (HIWORD(caption))
589         {
590             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
591             caption = HeapAlloc( GetProcessHeap(), 0, len );
592             WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
593         }
594         hwnd = CreateWindowExA(template.exStyle, class, caption,
595                                template.style & ~WS_VISIBLE,
596                                rect.left, rect.top, rect.right, rect.bottom,
597                                owner, hMenu, hInst, NULL );
598         if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
599         if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
600     }
601
602     if (!hwnd)
603     {
604         if (hUserFont) DeleteObject( hUserFont );
605         if (hMenu) DestroyMenu( hMenu );
606         if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
607         return 0;
608     }
609
610     /* moved this from the top of the method to here as DIALOGINFO structure
611     will be valid only after WM_CREATE message has been handled in DefDlgProc
612     All the members of the structure get filled here using temp variables */
613     dlgInfo = DIALOG_get_info( hwnd, TRUE );
614     dlgInfo->hwndFocus   = 0;
615     dlgInfo->hUserFont   = hUserFont;
616     dlgInfo->hMenu       = hMenu;
617     dlgInfo->xBaseUnit   = xBaseUnit;
618     dlgInfo->yBaseUnit   = yBaseUnit;
619     dlgInfo->idResult    = 0;
620     dlgInfo->flags       = flags;
621     dlgInfo->hDialogHeap = 0;
622
623     if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
624
625     if (unicode) SetWindowLongPtrW( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
626     else SetWindowLongPtrA( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
627
628     if (dlgInfo->hUserFont)
629         SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
630
631     /* Create controls */
632
633     if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
634     {
635         /* Send initialisation messages and set focus */
636
637         if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ) &&
638             ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
639         {
640             /* By returning TRUE, app has requested a default focus assignment */
641             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
642             if( dlgInfo->hwndFocus )
643                 SetFocus( dlgInfo->hwndFocus );
644         }
645
646         if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
647         {
648            ShowWindow( hwnd, SW_SHOWNORMAL );   /* SW_SHOW doesn't always work */
649         }
650         return hwnd;
651     }
652     if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
653     if( IsWindow(hwnd) ) DestroyWindow( hwnd );
654     return 0;
655 }
656
657
658 /***********************************************************************
659  *              CreateDialogParamA (USER32.@)
660  */
661 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name, HWND owner,
662                                 DLGPROC dlgProc, LPARAM param )
663 {
664     HRSRC hrsrc;
665     LPCDLGTEMPLATEA ptr;
666
667     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
668     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
669     return CreateDialogIndirectParamA( hInst, ptr, owner, dlgProc, param );
670 }
671
672
673 /***********************************************************************
674  *              CreateDialogParamW (USER32.@)
675  */
676 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name, HWND owner,
677                                 DLGPROC dlgProc, LPARAM param )
678 {
679     HRSRC hrsrc;
680     LPCDLGTEMPLATEA ptr;
681
682     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
683     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
684     return CreateDialogIndirectParamW( hInst, ptr, owner, dlgProc, param );
685 }
686
687
688 /***********************************************************************
689  *              CreateDialogIndirectParamAorW (USER32.@)
690  */
691 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst, LPCVOID dlgTemplate,
692                                            HWND owner, DLGPROC dlgProc, LPARAM param,
693                                            DWORD flags )
694 {
695     return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, !flags, FALSE );
696 }
697
698 /***********************************************************************
699  *              CreateDialogIndirectParamA (USER32.@)
700  */
701 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst, LPCDLGTEMPLATEA dlgTemplate,
702                                         HWND owner, DLGPROC dlgProc, LPARAM param )
703 {
704     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 2 );
705 }
706
707 /***********************************************************************
708  *              CreateDialogIndirectParamW (USER32.@)
709  */
710 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst, LPCDLGTEMPLATEW dlgTemplate,
711                                         HWND owner, DLGPROC dlgProc, LPARAM param )
712 {
713     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 0 );
714 }
715
716
717 /***********************************************************************
718  *           DIALOG_DoDialogBox
719  */
720 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
721 {
722     DIALOGINFO * dlgInfo;
723     MSG msg;
724     INT retval;
725     HWND ownerMsg = GetAncestor( owner, GA_ROOT );
726     BOOL bFirstEmpty;
727
728     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE ))) return -1;
729
730     bFirstEmpty = TRUE;
731     if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
732     {
733         for (;;)
734         {
735             if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
736             {
737                 if (bFirstEmpty)
738                 {
739                     /* ShowWindow the first time the queue goes empty */
740                     ShowWindow( hwnd, SW_SHOWNORMAL );
741                     bFirstEmpty = FALSE;
742                 }
743                 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
744                {
745                     /* No message present -> send ENTERIDLE and wait */
746                     SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
747                 }
748                 if (!GetMessageW( &msg, 0, 0, 0 )) break;
749             }
750
751             if (!IsWindow( hwnd )) return -1;
752             if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
753             {
754                 TranslateMessage( &msg );
755                 DispatchMessageW( &msg );
756             }
757             if (dlgInfo->flags & DF_END) break;
758         }
759     }
760     if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
761     retval = dlgInfo->idResult;
762     DestroyWindow( hwnd );
763     return retval;
764 }
765
766
767 /***********************************************************************
768  *              DialogBoxParamA (USER32.@)
769  */
770 INT_PTR WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
771                                 HWND owner, DLGPROC dlgProc, LPARAM param )
772 {
773     HWND hwnd;
774     HRSRC hrsrc;
775     LPCDLGTEMPLATEA ptr;
776
777     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
778     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
779     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, FALSE, TRUE );
780     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
781     return -1;
782 }
783
784
785 /***********************************************************************
786  *              DialogBoxParamW (USER32.@)
787  */
788 INT_PTR WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
789                                 HWND owner, DLGPROC dlgProc, LPARAM param )
790 {
791     HWND hwnd;
792     HRSRC hrsrc;
793     LPCDLGTEMPLATEW ptr;
794
795     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
796     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
797     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, TRUE, TRUE );
798     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
799     return -1;
800 }
801
802
803 /***********************************************************************
804  *              DialogBoxIndirectParamAorW (USER32.@)
805  */
806 INT_PTR WINAPI DialogBoxIndirectParamAorW( HINSTANCE hInstance, LPCVOID template,
807                                            HWND owner, DLGPROC dlgProc,
808                                            LPARAM param, DWORD flags )
809 {
810     HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, !flags, TRUE );
811     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
812     return -1;
813 }
814
815 /***********************************************************************
816  *              DialogBoxIndirectParamA (USER32.@)
817  */
818 INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCDLGTEMPLATEA template,
819                                        HWND owner, DLGPROC dlgProc, LPARAM param )
820 {
821     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 2 );
822 }
823
824
825 /***********************************************************************
826  *              DialogBoxIndirectParamW (USER32.@)
827  */
828 INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCDLGTEMPLATEW template,
829                                        HWND owner, DLGPROC dlgProc, LPARAM param )
830 {
831     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 0 );
832 }
833
834 /***********************************************************************
835  *              EndDialog (USER32.@)
836  */
837 BOOL WINAPI EndDialog( HWND hwnd, INT_PTR retval )
838 {
839     BOOL wasEnabled = TRUE;
840     DIALOGINFO * dlgInfo;
841     HWND owner;
842
843     TRACE("%p %d\n", hwnd, retval );
844
845     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE )))
846     {
847         ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
848         return FALSE;
849     }
850     dlgInfo->idResult = retval;
851     dlgInfo->flags |= DF_END;
852     wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
853
854     if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
855         DIALOG_EnableOwner( owner );
856
857     /* Windows sets the focus to the dialog itself in EndDialog */
858
859     if (IsChild(hwnd, GetFocus()))
860        SetFocus( hwnd );
861
862     /* Don't have to send a ShowWindow(SW_HIDE), just do
863        SetWindowPos with SWP_HIDEWINDOW as done in Windows */
864
865     SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
866                  | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
867
868     if (hwnd == GetActiveWindow()) WINPOS_ActivateOtherWindow( hwnd );
869
870     /* unblock dialog loop */
871     PostMessageA(hwnd, WM_NULL, 0, 0);
872     return TRUE;
873 }
874
875
876 /***********************************************************************
877  *           DIALOG_IsAccelerator
878  */
879 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
880 {
881     HWND hwndControl = hwnd;
882     HWND hwndNext;
883     INT dlgCode;
884     WCHAR buffer[128];
885
886     do
887     {
888         DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
889         if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
890         {
891             dlgCode = SendMessageW( hwndControl, WM_GETDLGCODE, 0, 0 );
892             if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
893                  GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
894             {
895                 /* find the accelerator key */
896                 LPWSTR p = buffer - 2;
897
898                 do
899                 {
900                     p = strchrW( p + 2, '&' );
901                 }
902                 while (p != NULL && p[1] == '&');
903
904                 /* and check if it's the one we're looking for */
905                 if (p != NULL && toupperW( p[1] ) == toupperW( wParam ) )
906                 {
907                     if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
908                     {
909                         /* set focus to the control */
910                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
911                         /* and bump it on to next */
912                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, 0, 0);
913                     }
914                     else if (dlgCode & DLGC_BUTTON)
915                     {
916                         /* send BM_CLICK message to the control */
917                         SendMessageW( hwndControl, BM_CLICK, 0, 0 );
918                     }
919                     return TRUE;
920                 }
921             }
922             hwndNext = GetWindow( hwndControl, GW_CHILD );
923         }
924         else hwndNext = 0;
925
926         if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
927
928         while (!hwndNext && hwndControl)
929         {
930             hwndControl = GetParent( hwndControl );
931             if (hwndControl == hwndDlg)
932             {
933                 if(hwnd==hwndDlg)   /* prevent endless loop */
934                 {
935                     hwndNext=hwnd;
936                     break;
937                 }
938                 hwndNext = GetWindow( hwndDlg, GW_CHILD );
939             }
940             else
941                 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
942         }
943         hwndControl = hwndNext;
944     }
945     while (hwndControl && (hwndControl != hwnd));
946
947     return FALSE;
948 }
949
950 /***********************************************************************
951  *           DIALOG_FindMsgDestination
952  *
953  * The messages that IsDialogMessage sends may not go to the dialog
954  * calling IsDialogMessage if that dialog is a child, and it has the
955  * DS_CONTROL style set.
956  * We propagate up until we hit one that does not have DS_CONTROL, or
957  * whose parent is not a dialog.
958  *
959  * This is undocumented behaviour.
960  */
961 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
962 {
963     while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
964     {
965         WND *pParent;
966         HWND hParent = GetParent(hwndDlg);
967         if (!hParent) break;
968
969         pParent = WIN_GetPtr(hParent);
970         if (!pParent || pParent == WND_OTHER_PROCESS || pParent == WND_DESKTOP) break;
971
972         if (!(pParent->flags & WIN_ISDIALOG))
973         {
974             WIN_ReleasePtr(pParent);
975             break;
976         }
977         WIN_ReleasePtr(pParent);
978
979         hwndDlg = hParent;
980     }
981
982     return hwndDlg;
983 }
984
985 /***********************************************************************
986  *              DIALOG_FixOneChildOnChangeFocus
987  *
988  * Callback helper for DIALOG_FixChildrenOnChangeFocus
989  */
990
991 static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
992         LPARAM lParam)
993 {
994     /* If a default pushbutton then no longer default */
995     if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
996         SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
997     return TRUE;
998 }
999
1000 /***********************************************************************
1001  *              DIALOG_FixChildrenOnChangeFocus
1002  *
1003  * Following the change of focus that occurs for example after handling
1004  * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
1005  * children may be required.
1006  */
1007 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
1008 {
1009     INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
1010     /* INT dlgcode_dlg  = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
1011     /* Windows does ask for this.  I don't know why yet */
1012
1013     EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
1014
1015     /* If the button that is getting the focus WAS flagged as the default
1016      * pushbutton then ask the dialog what it thinks the default is and
1017      * set that in the default style.
1018      */
1019     if (dlgcode_next & DLGC_DEFPUSHBUTTON)
1020     {
1021         DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
1022         if (HIWORD(def_id) == DC_HASDEFID)
1023         {
1024             HWND hwndDef;
1025             def_id = LOWORD(def_id);
1026             hwndDef = GetDlgItem (hwndDlg, def_id);
1027             if (hwndDef)
1028             {
1029                 INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
1030                 /* I know that if it is a button then it should already be a
1031                  * UNDEFPUSHBUTTON, since we have just told the buttons to 
1032                  * change style.  But maybe they ignored our request
1033                  */
1034                 if ((dlgcode_def & DLGC_BUTTON) &&
1035                         (dlgcode_def &  DLGC_UNDEFPUSHBUTTON))
1036                 {
1037                     SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1038                 }
1039             }
1040         }
1041     }
1042     else if ((dlgcode_next & DLGC_BUTTON) && (dlgcode_next & DLGC_UNDEFPUSHBUTTON))
1043     {
1044         SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1045         /* I wonder why it doesn't send a DM_SETDEFID */
1046     }
1047 }
1048
1049 /***********************************************************************
1050  *              IsDialogMessageW (USER32.@)
1051  */
1052 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1053 {
1054     INT dlgCode = 0;
1055
1056     if (CallMsgFilterW( msg, MSGF_DIALOGBOX )) return TRUE;
1057
1058     hwndDlg = WIN_GetFullHandle( hwndDlg );
1059     if (hwndDlg == GetDesktopWindow()) return FALSE;
1060     if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
1061
1062     hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1063
1064     switch(msg->message)
1065     {
1066     case WM_KEYDOWN:
1067         dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1068         if (dlgCode & DLGC_WANTMESSAGE) break;
1069
1070         switch(msg->wParam)
1071         {
1072         case VK_TAB:
1073             if (!(dlgCode & DLGC_WANTTAB))
1074             {
1075                 BOOL fIsDialog = TRUE;
1076                 WND *pWnd = WIN_GetPtr( hwndDlg );
1077
1078                 if (pWnd && pWnd != WND_OTHER_PROCESS)
1079                 {
1080                     fIsDialog = (pWnd->flags & WIN_ISDIALOG) != 0;
1081                     WIN_ReleasePtr(pWnd);
1082                 }
1083
1084                 /* I am not sure under which circumstances the TAB is handled
1085                  * each way.  All I do know is that it does not always simply
1086                  * send WM_NEXTDLGCTL.  (Personally I have never yet seen it
1087                  * do so but I presume someone has)
1088                  */
1089                 if (fIsDialog)
1090                     SendMessageW( hwndDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1091                 else
1092                 {
1093                     /* It would appear that GetNextDlgTabItem can handle being
1094                      * passed hwndDlg rather than NULL but that is undocumented
1095                      * so let's do it properly
1096                      */
1097                     HWND hwndFocus = GetFocus();
1098                     HWND hwndNext = GetNextDlgTabItem (hwndDlg,
1099                             hwndFocus == hwndDlg ? NULL : hwndFocus,
1100                             GetKeyState (VK_SHIFT) & 0x8000);
1101                     if (hwndNext)
1102                     {
1103                         dlgCode = SendMessageW (hwndNext, WM_GETDLGCODE,
1104                                 msg->wParam, (LPARAM)msg);
1105                         if (dlgCode & DLGC_HASSETSEL)
1106                         {
1107                             INT maxlen = 1 + SendMessageW (hwndNext, WM_GETTEXTLENGTH, 0, 0);
1108                             WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
1109                             if (buffer)
1110                             {
1111                                 INT length;
1112                                 SendMessageW (hwndNext, WM_GETTEXT, maxlen, (LPARAM) buffer);
1113                                 length = strlenW (buffer);
1114                                 HeapFree (GetProcessHeap(), 0, buffer);
1115                                 SendMessageW (hwndNext, EM_SETSEL, 0, length);
1116                             }
1117                         }
1118                         SetFocus (hwndNext);
1119                         DIALOG_FixChildrenOnChangeFocus (hwndDlg, hwndNext);
1120                     }
1121                     else
1122                         return FALSE;
1123                 }
1124                 return TRUE;
1125             }
1126             break;
1127
1128         case VK_RIGHT:
1129         case VK_DOWN:
1130         case VK_LEFT:
1131         case VK_UP:
1132             if (!(dlgCode & DLGC_WANTARROWS))
1133             {
1134                 BOOL fPrevious = (msg->wParam == VK_LEFT || msg->wParam == VK_UP);
1135                 HWND hwndNext = GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1136                 SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1137                 return TRUE;
1138             }
1139             break;
1140
1141         case VK_CANCEL:
1142         case VK_ESCAPE:
1143             SendMessageW( hwndDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1144             return TRUE;
1145
1146         case VK_EXECUTE:
1147         case VK_RETURN:
1148             {
1149                 DWORD dw;
1150                 if ((GetFocus() == msg->hwnd) &&
1151                     (SendMessageW (msg->hwnd, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1152                 {
1153                     SendMessageW (hwndDlg, WM_COMMAND, MAKEWPARAM (GetDlgCtrlID(msg->hwnd),BN_CLICKED), (LPARAM)msg->hwnd); 
1154                 }
1155                 else if (DC_HASDEFID == HIWORD(dw = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0)))
1156                 {
1157                     SendMessageW( hwndDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1158                                     (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1159                 }
1160                 else
1161                 {
1162                     SendMessageW( hwndDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1163
1164                 }
1165             }
1166             return TRUE;
1167         }
1168         break;
1169
1170     case WM_CHAR:
1171         /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
1172          * It does NOT get sent in the test program I have
1173          */
1174         dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1175         if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
1176         if (msg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
1177         /* drop through */
1178
1179     case WM_SYSCHAR:
1180         if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg->hwnd), hwndDlg, msg->wParam ))
1181         {
1182             /* don't translate or dispatch */
1183             return TRUE;
1184         }
1185         break;
1186     }
1187
1188     TranslateMessage( msg );
1189     DispatchMessageW( msg );
1190     return TRUE;
1191 }
1192
1193
1194 /***********************************************************************
1195  *              GetDlgCtrlID (USER32.@)
1196  */
1197 INT WINAPI GetDlgCtrlID( HWND hwnd )
1198 {
1199     return GetWindowLongPtrW( hwnd, GWLP_ID );
1200 }
1201
1202
1203 /***********************************************************************
1204  *              GetDlgItem (USER32.@)
1205  */
1206 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1207 {
1208     int i;
1209     HWND *list = WIN_ListChildren( hwndDlg );
1210     HWND ret = 0;
1211
1212     if (!list) return 0;
1213
1214     for (i = 0; list[i]; i++) if (GetWindowLongPtrW( list[i], GWLP_ID ) == id) break;
1215     ret = list[i];
1216     HeapFree( GetProcessHeap(), 0, list );
1217     return ret;
1218 }
1219
1220
1221 /*******************************************************************
1222  *              SendDlgItemMessageA (USER32.@)
1223  */
1224 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1225                                       WPARAM wParam, LPARAM lParam )
1226 {
1227     HWND hwndCtrl = GetDlgItem( hwnd, id );
1228     if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1229     else return 0;
1230 }
1231
1232
1233 /*******************************************************************
1234  *              SendDlgItemMessageW (USER32.@)
1235  */
1236 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1237                                       WPARAM wParam, LPARAM lParam )
1238 {
1239     HWND hwndCtrl = GetDlgItem( hwnd, id );
1240     if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1241     else return 0;
1242 }
1243
1244
1245 /*******************************************************************
1246  *              SetDlgItemTextA (USER32.@)
1247  */
1248 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1249 {
1250     return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1251 }
1252
1253
1254 /*******************************************************************
1255  *              SetDlgItemTextW (USER32.@)
1256  */
1257 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1258 {
1259     return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1260 }
1261
1262
1263 /***********************************************************************
1264  *              GetDlgItemTextA (USER32.@)
1265  */
1266 UINT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, INT len )
1267 {
1268     if (str && (len > 0)) str[0] = '\0';
1269     return (UINT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1270                                          len, (LPARAM)str );
1271 }
1272
1273
1274 /***********************************************************************
1275  *              GetDlgItemTextW (USER32.@)
1276  */
1277 UINT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, INT len )
1278 {
1279     if (str && (len > 0)) str[0] = '\0';
1280     return (UINT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1281                                          len, (LPARAM)str );
1282 }
1283
1284
1285 /*******************************************************************
1286  *              SetDlgItemInt (USER32.@)
1287  */
1288 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1289                              BOOL fSigned )
1290 {
1291     char str[20];
1292
1293     if (fSigned) sprintf( str, "%d", (INT)value );
1294     else sprintf( str, "%u", value );
1295     SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1296     return TRUE;
1297 }
1298
1299
1300 /***********************************************************************
1301  *              GetDlgItemInt (USER32.@)
1302  */
1303 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1304                                BOOL fSigned )
1305 {
1306     char str[30];
1307     char * endptr;
1308     long result = 0;
1309
1310     if (translated) *translated = FALSE;
1311     if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1312         return 0;
1313     if (fSigned)
1314     {
1315         result = strtol( str, &endptr, 10 );
1316         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
1317             return 0;
1318         if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1319             return 0;
1320     }
1321     else
1322     {
1323         result = strtoul( str, &endptr, 10 );
1324         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
1325             return 0;
1326         if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1327     }
1328     if (translated) *translated = TRUE;
1329     return (UINT)result;
1330 }
1331
1332
1333 /***********************************************************************
1334  *              CheckDlgButton (USER32.@)
1335  */
1336 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1337 {
1338     SendDlgItemMessageW( hwnd, id, BM_SETCHECK, check, 0 );
1339     return TRUE;
1340 }
1341
1342
1343 /***********************************************************************
1344  *              IsDlgButtonChecked (USER32.@)
1345  */
1346 UINT WINAPI IsDlgButtonChecked( HWND hwnd, int id )
1347 {
1348     return (UINT)SendDlgItemMessageW( hwnd, id, BM_GETCHECK, 0, 0 );
1349 }
1350
1351
1352 /***********************************************************************
1353  *           CheckRB
1354  *
1355  * Callback function used to check/uncheck radio buttons that fall
1356  * within a specific range of IDs.
1357  */
1358 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1359 {
1360     LONG lChildID = GetWindowLongPtrW(hwndChild, GWLP_ID);
1361     RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1362
1363     if ((lChildID >= lpRadioGroup->firstID) &&
1364         (lChildID <= lpRadioGroup->lastID))
1365     {
1366         if (lChildID == lpRadioGroup->checkID)
1367         {
1368             SendMessageW(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1369         }
1370         else
1371         {
1372             SendMessageW(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1373         }
1374     }
1375
1376     return TRUE;
1377 }
1378
1379
1380 /***********************************************************************
1381  *              CheckRadioButton (USER32.@)
1382  */
1383 BOOL WINAPI CheckRadioButton( HWND hwndDlg, int firstID,
1384                               int lastID, int checkID )
1385 {
1386     RADIOGROUP radioGroup;
1387
1388     radioGroup.firstID = firstID;
1389     radioGroup.lastID = lastID;
1390     radioGroup.checkID = checkID;
1391
1392     return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1393                             (LPARAM)&radioGroup);
1394 }
1395
1396
1397 /***********************************************************************
1398  *              GetDialogBaseUnits (USER.243)
1399  *              GetDialogBaseUnits (USER32.@)
1400  */
1401 DWORD WINAPI GetDialogBaseUnits(void)
1402 {
1403     static DWORD units;
1404
1405     if (!units)
1406     {
1407         HDC hdc;
1408         SIZE size;
1409
1410         if ((hdc = GetDC(0)))
1411         {
1412             size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy );
1413             if (size.cx) units = MAKELONG( size.cx, size.cy );
1414             ReleaseDC( 0, hdc );
1415         }
1416         TRACE("base units = %d,%d\n", LOWORD(units), HIWORD(units) );
1417     }
1418     return units;
1419 }
1420
1421
1422 /***********************************************************************
1423  *              MapDialogRect (USER32.@)
1424  */
1425 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1426 {
1427     DIALOGINFO * dlgInfo;
1428     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE ))) return FALSE;
1429     rect->left   = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1430     rect->right  = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1431     rect->top    = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1432     rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1433     return TRUE;
1434 }
1435
1436
1437 /***********************************************************************
1438  *              GetNextDlgGroupItem (USER32.@)
1439  *
1440  * Corrections to MSDN documentation
1441  *
1442  * (Under Windows 2000 at least, where hwndDlg is not actually a dialog)
1443  * 1. hwndCtrl can be hwndDlg in which case it behaves as for NULL
1444  * 2. Prev of NULL or hwndDlg fails
1445  */
1446 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1447 {
1448     HWND hwnd, hwndNext, retvalue, hwndLastGroup = 0;
1449     BOOL fLooped=FALSE;
1450     BOOL fSkipping=FALSE;
1451
1452     hwndDlg = WIN_GetFullHandle( hwndDlg );
1453     hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1454
1455     if (hwndDlg == hwndCtrl) hwndCtrl = NULL;
1456     if (!hwndCtrl && fPrevious) return 0;
1457
1458     if (hwndCtrl)
1459     {
1460         if (!IsChild (hwndDlg, hwndCtrl)) return 0;
1461     }
1462     else
1463     {
1464         /* No ctrl specified -> start from the beginning */
1465         if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1466         /* MSDN is wrong. fPrevious does not result in the last child */
1467
1468         /* Maybe that first one is valid.  If so then we don't want to skip it*/
1469         if ((GetWindowLongW( hwndCtrl, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1470         {
1471             return hwndCtrl;
1472         }
1473     }
1474
1475     /* Always go forward around the group and list of controls; for the 
1476      * previous control keep track; for the next break when you find one
1477      */
1478     retvalue = hwndCtrl;
1479     hwnd = hwndCtrl;
1480     while (hwndNext = GetWindow (hwnd, GW_HWNDNEXT),
1481            1)
1482     {
1483         while (!hwndNext)
1484         {
1485             /* Climb out until there is a next sibling of the ancestor or we
1486              * reach the top (in which case we loop back to the start)
1487              */
1488             if (hwndDlg == GetParent (hwnd))
1489             {
1490                 /* Wrap around to the beginning of the list, within the same
1491                  * group. (Once only)
1492                  */
1493                 if (fLooped) goto end;
1494                 fLooped = TRUE;
1495                 hwndNext = GetWindow (hwndDlg, GW_CHILD);
1496             }
1497             else
1498             {
1499                 hwnd = GetParent (hwnd);
1500                 hwndNext = GetWindow (hwnd, GW_HWNDNEXT);
1501             }
1502         }
1503         hwnd = hwndNext;
1504
1505         /* Wander down the leading edge of controlparents */
1506         while ( (GetWindowLongW (hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
1507                 ((GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) &&
1508                 (hwndNext = GetWindow (hwnd, GW_CHILD)))
1509             hwnd = hwndNext;
1510         /* Question.  If the control is a control parent but either has no
1511          * children or is not visible/enabled then if it has a WS_GROUP does
1512          * it count?  For that matter does it count anyway?
1513          * I believe it doesn't count.
1514          */
1515
1516         if ((GetWindowLongW (hwnd, GWL_STYLE) & WS_GROUP))
1517         {
1518             hwndLastGroup = hwnd;
1519             if (!fSkipping)
1520             {
1521                 /* Look for the beginning of the group */
1522                 fSkipping = TRUE;
1523             }
1524         }
1525
1526         if (hwnd == hwndCtrl)
1527         {
1528             if (!fSkipping) break;
1529             if (hwndLastGroup == hwnd) break;
1530             hwnd = hwndLastGroup;
1531             fSkipping = FALSE;
1532             fLooped = FALSE;
1533         }
1534
1535         if (!fSkipping &&
1536             (GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE|WS_DISABLED)) ==
1537              WS_VISIBLE)
1538         {
1539             retvalue = hwnd;
1540             if (!fPrevious) break;
1541         }
1542     }
1543 end:
1544     return retvalue;
1545 }
1546
1547
1548 /***********************************************************************
1549  *           DIALOG_GetNextTabItem
1550  *
1551  * Recursive helper for GetNextDlgTabItem
1552  */
1553 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1554 {
1555     LONG dsStyle;
1556     LONG exStyle;
1557     UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1558     HWND retWnd = 0;
1559     HWND hChildFirst = 0;
1560
1561     if(!hwndCtrl)
1562     {
1563         hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1564         if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1565     }
1566     else if (IsChild( hwndMain, hwndCtrl ))
1567     {
1568         hChildFirst = GetWindow(hwndCtrl,wndSearch);
1569         if(!hChildFirst)
1570         {
1571             if(GetParent(hwndCtrl) != hwndMain)
1572                 /* i.e. if we are not at the top level of the recursion */
1573                 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1574             else
1575                 hChildFirst = GetWindow(hwndCtrl, fPrevious ? GW_HWNDLAST : GW_HWNDFIRST);
1576         }
1577     }
1578
1579     while(hChildFirst)
1580     {
1581         dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1582         exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1583         if( (exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1584         {
1585             HWND retWnd;
1586             retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1587             if (retWnd) return (retWnd);
1588         }
1589         else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1590         {
1591             return (hChildFirst);
1592         }
1593         hChildFirst = GetWindow(hChildFirst,wndSearch);
1594     }
1595     if(hwndCtrl)
1596     {
1597         HWND hParent = GetParent(hwndCtrl);
1598         while(hParent)
1599         {
1600             if(hParent == hwndMain) break;
1601             retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1602             if(retWnd) break;
1603             hParent = GetParent(hParent);
1604         }
1605         if(!retWnd)
1606             retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1607     }
1608     return retWnd ? retWnd : hwndCtrl;
1609 }
1610
1611 /***********************************************************************
1612  *              GetNextDlgTabItem (USER32.@)
1613  */
1614 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1615                                    BOOL fPrevious )
1616 {
1617     hwndDlg = WIN_GetFullHandle( hwndDlg );
1618     hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1619
1620     /* Undocumented but tested under Win2000 and WinME */
1621     if (hwndDlg == hwndCtrl) hwndCtrl = NULL;
1622
1623     /* Contrary to MSDN documentation, tested under Win2000 and WinME
1624      * NB GetLastError returns whatever was set before the function was
1625      * called.
1626      */
1627     if (!hwndCtrl && fPrevious) return 0;
1628
1629     return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1630 }
1631
1632 /**********************************************************************
1633  *           DIALOG_DlgDirSelect
1634  *
1635  * Helper function for DlgDirSelect*
1636  */
1637 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPWSTR str, INT len,
1638                                  INT id, BOOL unicode, BOOL combo )
1639 {
1640     WCHAR *buffer, *ptr;
1641     INT item, size;
1642     BOOL ret;
1643     HWND listbox = GetDlgItem( hwnd, id );
1644
1645     TRACE("%p '%s' %d\n", hwnd, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str), id );
1646     if (!listbox) return FALSE;
1647
1648     item = SendMessageW(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1649     if (item == LB_ERR) return FALSE;
1650
1651     size = SendMessageW(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1652     if (size == LB_ERR) return FALSE;
1653
1654     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1655
1656     SendMessageW( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1657
1658     if ((ret = (buffer[0] == '[')))  /* drive or directory */
1659     {
1660         if (buffer[1] == '-')  /* drive */
1661         {
1662             buffer[3] = ':';
1663             buffer[4] = 0;
1664             ptr = buffer + 2;
1665         }
1666         else
1667         {
1668             buffer[strlenW(buffer)-1] = '\\';
1669             ptr = buffer + 1;
1670         }
1671     }
1672     else ptr = buffer;
1673
1674     if (!unicode)
1675     {
1676         if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, ptr, -1, (LPSTR)str, len, 0, 0 ))
1677             ((LPSTR)str)[len-1] = 0;
1678     }
1679     else lstrcpynW( str, ptr, len );
1680     HeapFree( GetProcessHeap(), 0, buffer );
1681     TRACE("Returning %d '%s'\n", ret, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str) );
1682     return ret;
1683 }
1684
1685
1686 /**********************************************************************
1687  *          DIALOG_DlgDirListW
1688  *
1689  * Helper function for DlgDirList*W
1690  */
1691 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1692                                INT idStatic, UINT attrib, BOOL combo )
1693 {
1694     HWND hwnd;
1695     LPWSTR orig_spec = spec;
1696     WCHAR any[] = {'*','.','*',0};
1697
1698 #define SENDMSG(msg,wparam,lparam) \
1699     ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1700                              : SendMessageW( hwnd, msg, wparam, lparam ))
1701
1702     TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib );
1703
1704     /* If the path exists and is a directory, chdir to it */
1705     if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any;
1706     else
1707     {
1708         WCHAR *p, *p2;
1709         p = spec;
1710         if ((p2 = strrchrW( p, '\\' ))) p = p2;
1711         if ((p2 = strrchrW( p, '/' ))) p = p2;
1712         if (p != spec)
1713         {
1714             WCHAR sep = *p;
1715             *p = 0;
1716             if (!SetCurrentDirectoryW( spec ))
1717             {
1718                 *p = sep;  /* Restore the original spec */
1719                 return FALSE;
1720             }
1721             spec = p + 1;
1722         }
1723     }
1724
1725     TRACE( "mask=%s\n", debugstr_w(spec) );
1726
1727     if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1728     {
1729         SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1730         if (attrib & DDL_DIRECTORY)
1731         {
1732             if (!(attrib & DDL_EXCLUSIVE))
1733             {
1734                 if (SENDMSG( combo ? CB_DIR : LB_DIR,
1735                              attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1736                              (LPARAM)spec ) == LB_ERR)
1737                     return FALSE;
1738             }
1739             if (SENDMSG( combo ? CB_DIR : LB_DIR,
1740                        (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1741                          (LPARAM)any ) == LB_ERR)
1742                 return FALSE;
1743         }
1744         else
1745         {
1746             if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
1747                          (LPARAM)spec ) == LB_ERR)
1748                 return FALSE;
1749         }
1750     }
1751
1752     if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1753     {
1754         WCHAR temp[MAX_PATH];
1755         GetCurrentDirectoryW( sizeof(temp)/sizeof(WCHAR), temp );
1756         CharLowerW( temp );
1757         /* Can't use PostMessage() here, because the string is on the stack */
1758         SetDlgItemTextW( hDlg, idStatic, temp );
1759     }
1760
1761     if (orig_spec && (spec != orig_spec))
1762     {
1763         /* Update the original file spec */
1764         WCHAR *p = spec;
1765         while ((*orig_spec++ = *p++));
1766     }
1767
1768     return TRUE;
1769 #undef SENDMSG
1770 }
1771
1772
1773 /**********************************************************************
1774  *          DIALOG_DlgDirListA
1775  *
1776  * Helper function for DlgDirList*A
1777  */
1778 static INT DIALOG_DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1779                                INT idStatic, UINT attrib, BOOL combo )
1780 {
1781     if (spec)
1782     {
1783         INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
1784         LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1785         MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
1786         ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
1787         WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );
1788         HeapFree( GetProcessHeap(), 0, specW );
1789         return ret;
1790     }
1791     return DIALOG_DlgDirListW( hDlg, NULL, idLBox, idStatic, attrib, combo );
1792 }
1793
1794
1795 /**********************************************************************
1796  *              DlgDirSelectExA (USER32.@)
1797  */
1798 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
1799 {
1800     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, FALSE );
1801 }
1802
1803
1804 /**********************************************************************
1805  *              DlgDirSelectExW (USER32.@)
1806  */
1807 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
1808 {
1809     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE );
1810 }
1811
1812
1813 /**********************************************************************
1814  *              DlgDirSelectComboBoxExA (USER32.@)
1815  */
1816 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
1817                                          INT id )
1818 {
1819     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, TRUE );
1820 }
1821
1822
1823 /**********************************************************************
1824  *              DlgDirSelectComboBoxExW (USER32.@)
1825  */
1826 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
1827                                          INT id)
1828 {
1829     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, TRUE );
1830 }
1831
1832
1833 /**********************************************************************
1834  *              DlgDirListA (USER32.@)
1835  */
1836 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1837                             INT idStatic, UINT attrib )
1838 {
1839     return DIALOG_DlgDirListA( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1840 }
1841
1842
1843 /**********************************************************************
1844  *              DlgDirListW (USER32.@)
1845  */
1846 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1847                             INT idStatic, UINT attrib )
1848 {
1849     return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1850 }
1851
1852
1853 /**********************************************************************
1854  *              DlgDirListComboBoxA (USER32.@)
1855  */
1856 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
1857                                     INT idStatic, UINT attrib )
1858 {
1859     return DIALOG_DlgDirListA( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1860 }
1861
1862
1863 /**********************************************************************
1864  *              DlgDirListComboBoxW (USER32.@)
1865  */
1866 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
1867                                     INT idStatic, UINT attrib )
1868 {
1869     return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1870 }