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