Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[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., 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 "winpos.h"
42 #include "user_private.h"
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
46
47
48   /* Dialog control information */
49 typedef struct
50 {
51     DWORD      style;
52     DWORD      exStyle;
53     DWORD      helpId;
54     INT16      x;
55     INT16      y;
56     INT16      cx;
57     INT16      cy;
58     UINT       id;
59     LPCWSTR    className;
60     LPCWSTR    windowName;
61     LPCVOID    data;
62 } DLG_CONTROL_INFO;
63
64   /* Dialog template */
65 typedef struct
66 {
67     DWORD      style;
68     DWORD      exStyle;
69     DWORD      helpId;
70     UINT16     nbItems;
71     INT16      x;
72     INT16      y;
73     INT16      cx;
74     INT16      cy;
75     LPCWSTR    menuName;
76     LPCWSTR    className;
77     LPCWSTR    caption;
78     INT16      pointSize;
79     WORD       weight;
80     BOOL       italic;
81     LPCWSTR    faceName;
82     BOOL       dialogEx;
83 } DLG_TEMPLATE;
84
85   /* Radio button group */
86 typedef struct
87 {
88     UINT firstID;
89     UINT lastID;
90     UINT checkID;
91 } RADIOGROUP;
92
93
94 /*********************************************************************
95  * dialog class descriptor
96  */
97 const struct builtin_class_descr DIALOG_builtin_class =
98 {
99     DIALOG_CLASS_ATOMA,  /* name */
100     CS_SAVEBITS | CS_DBLCLKS, /* style  */
101     DefDlgProcA,        /* procA */
102     DefDlgProcW,        /* procW */
103     DLGWINDOWEXTRA,     /* extra */
104     IDC_ARROW,          /* cursor */
105     0                   /* brush */
106 };
107
108
109 /***********************************************************************
110  *           DIALOG_EnableOwner
111  *
112  * Helper function for modal dialogs to enable again the
113  * owner of the dialog box.
114  */
115 void DIALOG_EnableOwner( HWND hOwner )
116 {
117     /* Owner must be a top-level window */
118     if (hOwner)
119         hOwner = GetAncestor( hOwner, GA_ROOT );
120     if (!hOwner) return;
121     EnableWindow( hOwner, TRUE );
122 }
123
124
125 /***********************************************************************
126  *           DIALOG_DisableOwner
127  *
128  * Helper function for modal dialogs to disable the
129  * owner of the dialog box. Returns TRUE if owner was enabled.
130  */
131 BOOL DIALOG_DisableOwner( HWND hOwner )
132 {
133     /* Owner must be a top-level window */
134     if (hOwner)
135         hOwner = GetAncestor( hOwner, GA_ROOT );
136     if (!hOwner) return FALSE;
137     if (IsWindowEnabled( hOwner ))
138     {
139         EnableWindow( hOwner, FALSE );
140         return TRUE;
141     }
142     else
143         return FALSE;
144 }
145
146 /***********************************************************************
147  *           DIALOG_GetCharSize
148  *
149  * Despite most of MSDN insisting that the horizontal base unit is
150  * tmAveCharWidth it isn't.  Knowledge base article Q145994
151  * "HOWTO: Calculate Dialog Units When Not Using the System Font",
152  * says that we should take the average of the 52 English upper and lower
153  * case characters.
154  */
155 BOOL DIALOG_GetCharSize( HDC hDC, HFONT hFont, SIZE * pSize )
156 {
157     HFONT hFontPrev = 0;
158     const char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
159     SIZE sz;
160     TEXTMETRICA tm;
161
162     if(!hDC) return FALSE;
163
164     if(hFont) hFontPrev = SelectObject(hDC, hFont);
165     if(!GetTextMetricsA(hDC, &tm)) return FALSE;
166     if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
167
168     pSize->cy = tm.tmHeight;
169     pSize->cx = (sz.cx / 26 + 1) / 2;
170
171     if (hFontPrev) SelectObject(hDC, hFontPrev);
172
173     TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy);
174     return TRUE;
175 }
176
177
178 /***********************************************************************
179  *           DIALOG_GetControl32
180  *
181  * Return the class and text of the control pointed to by ptr,
182  * fill the header structure and return a pointer to the next control.
183  */
184 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
185                                         BOOL dialogEx )
186 {
187     if (dialogEx)
188     {
189         info->helpId  = GET_DWORD(p); p += 2;
190         info->exStyle = GET_DWORD(p); p += 2;
191         info->style   = GET_DWORD(p); p += 2;
192     }
193     else
194     {
195         info->helpId  = 0;
196         info->style   = GET_DWORD(p); p += 2;
197         info->exStyle = GET_DWORD(p); p += 2;
198     }
199     info->x       = GET_WORD(p); p++;
200     info->y       = GET_WORD(p); p++;
201     info->cx      = GET_WORD(p); p++;
202     info->cy      = GET_WORD(p); p++;
203
204     if (dialogEx)
205     {
206         /* id is a DWORD for DIALOGEX */
207         info->id = GET_DWORD(p);
208         p += 2;
209     }
210     else
211     {
212         info->id = GET_WORD(p);
213         p++;
214     }
215
216     if (GET_WORD(p) == 0xffff)
217     {
218         static const WCHAR class_names[6][10] =
219         {
220             { 'B','u','t','t','o','n', },             /* 0x80 */
221             { 'E','d','i','t', },                     /* 0x81 */
222             { 'S','t','a','t','i','c', },             /* 0x82 */
223             { 'L','i','s','t','B','o','x', },         /* 0x83 */
224             { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
225             { 'C','o','m','b','o','B','o','x', }      /* 0x85 */
226         };
227         WORD id = GET_WORD(p+1);
228         /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
229         if ((id >= 0x80) && (id <= 0x85)) id -= 0x80;
230         if (id <= 5)
231             info->className = class_names[id];
232         else
233         {
234             info->className = NULL;
235             ERR("Unknown built-in class id %04x\n", id );
236         }
237         p += 2;
238     }
239     else
240     {
241         info->className = (LPCWSTR)p;
242         p += strlenW( info->className ) + 1;
243     }
244
245     if (GET_WORD(p) == 0xffff)  /* Is it an integer id? */
246     {
247         info->windowName = (LPCWSTR)(UINT)GET_WORD(p + 1);
248         p += 2;
249     }
250     else
251     {
252         info->windowName = (LPCWSTR)p;
253         p += strlenW( info->windowName ) + 1;
254     }
255
256     TRACE("    %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
257           debugstr_w( info->className ), debugstr_w( info->windowName ),
258           info->id, info->x, info->y, info->cx, info->cy,
259           info->style, info->exStyle, info->helpId );
260
261     if (GET_WORD(p))
262     {
263         if (TRACE_ON(dialog))
264         {
265             WORD i, count = GET_WORD(p) / sizeof(WORD);
266             TRACE("  BEGIN\n");
267             TRACE("    ");
268             for (i = 0; i < count; i++) TRACE( "%04x,", GET_WORD(p+i+1) );
269             TRACE("\n");
270             TRACE("  END\n" );
271         }
272         info->data = p + 1;
273         p += GET_WORD(p) / sizeof(WORD);
274     }
275     else info->data = NULL;
276     p++;
277
278     /* Next control is on dword boundary */
279     return (const WORD *)((((int)p) + 3) & ~3);
280 }
281
282
283 /***********************************************************************
284  *           DIALOG_CreateControls32
285  *
286  * Create the control windows for a dialog.
287  */
288 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
289                                      HINSTANCE hInst, BOOL unicode )
290 {
291     DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd, TRUE );
292     DLG_CONTROL_INFO info;
293     HWND hwndCtrl, hwndDefButton = 0;
294     INT items = dlgTemplate->nbItems;
295
296     TRACE(" BEGIN\n" );
297     while (items--)
298     {
299         template = (LPCSTR)DIALOG_GetControl32( (const WORD *)template, &info,
300                                                 dlgTemplate->dialogEx );
301         /* Is this it? */
302         if (info.style & WS_BORDER)
303         {
304             info.style &= ~WS_BORDER;
305             info.exStyle |= WS_EX_CLIENTEDGE;
306         }
307         if (unicode)
308         {
309             hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
310                                         info.className, info.windowName,
311                                         info.style | WS_CHILD,
312                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
313                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
314                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
315                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
316                                         hwnd, (HMENU)info.id,
317                                         hInst, (LPVOID)info.data );
318         }
319         else
320         {
321             LPSTR class = (LPSTR)info.className;
322             LPSTR caption = (LPSTR)info.windowName;
323
324             if (HIWORD(class))
325             {
326                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
327                 class = HeapAlloc( GetProcessHeap(), 0, len );
328                 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
329             }
330             if (HIWORD(caption))
331             {
332                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
333                 caption = HeapAlloc( GetProcessHeap(), 0, len );
334                 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
335             }
336             hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
337                                         class, caption, info.style | WS_CHILD,
338                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
339                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
340                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
341                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
342                                         hwnd, (HMENU)info.id,
343                                         hInst, (LPVOID)info.data );
344             if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
345             if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
346         }
347         if (!hwndCtrl)
348         {
349             if (dlgTemplate->style & DS_NOFAILCREATE) continue;
350             return FALSE;
351         }
352
353             /* Send initialisation messages to the control */
354         if (dlgInfo->hUserFont) SendMessageW( hwndCtrl, WM_SETFONT,
355                                              (WPARAM)dlgInfo->hUserFont, 0 );
356         if (SendMessageW(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
357         {
358               /* If there's already a default push-button, set it back */
359               /* to normal and use this one instead. */
360             if (hwndDefButton)
361                 SendMessageW( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
362             hwndDefButton = hwndCtrl;
363             dlgInfo->idResult = GetWindowLongPtrA( hwndCtrl, GWLP_ID );
364         }
365     }
366     TRACE(" END\n" );
367     return TRUE;
368 }
369
370
371 /***********************************************************************
372  *           DIALOG_ParseTemplate32
373  *
374  * Fill a DLG_TEMPLATE structure from the dialog template, and return
375  * a pointer to the first control.
376  */
377 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
378 {
379     const WORD *p = (const WORD *)template;
380     WORD signature;
381     WORD dlgver;
382
383     signature = GET_WORD(p); p++;
384     dlgver = GET_WORD(p); p++;
385
386     if (signature == 1 && dlgver == 0xffff)  /* DIALOGEX resource */
387     {
388         result->dialogEx = TRUE;
389         result->helpId   = GET_DWORD(p); p += 2;
390         result->exStyle  = GET_DWORD(p); p += 2;
391         result->style    = GET_DWORD(p); p += 2;
392     }
393     else
394     {
395         result->style = GET_DWORD(p - 2);
396         result->dialogEx = FALSE;
397         result->helpId   = 0;
398         result->exStyle  = GET_DWORD(p); p += 2;
399     }
400     result->nbItems = GET_WORD(p); p++;
401     result->x       = GET_WORD(p); p++;
402     result->y       = GET_WORD(p); p++;
403     result->cx      = GET_WORD(p); p++;
404     result->cy      = GET_WORD(p); p++;
405     TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
406            result->dialogEx ? "EX" : "", result->x, result->y,
407            result->cx, result->cy, result->helpId );
408     TRACE(" STYLE 0x%08lx\n", result->style );
409     TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
410
411     /* Get the menu name */
412
413     switch(GET_WORD(p))
414     {
415     case 0x0000:
416         result->menuName = NULL;
417         p++;
418         break;
419     case 0xffff:
420         result->menuName = (LPCWSTR)(UINT)GET_WORD( p + 1 );
421         p += 2;
422         TRACE(" MENU %04x\n", LOWORD(result->menuName) );
423         break;
424     default:
425         result->menuName = (LPCWSTR)p;
426         TRACE(" MENU %s\n", debugstr_w(result->menuName) );
427         p += strlenW( result->menuName ) + 1;
428         break;
429     }
430
431     /* Get the class name */
432
433     switch(GET_WORD(p))
434     {
435     case 0x0000:
436         result->className = DIALOG_CLASS_ATOMW;
437         p++;
438         break;
439     case 0xffff:
440         result->className = (LPCWSTR)(UINT)GET_WORD( p + 1 );
441         p += 2;
442         TRACE(" CLASS %04x\n", LOWORD(result->className) );
443         break;
444     default:
445         result->className = (LPCWSTR)p;
446         TRACE(" CLASS %s\n", debugstr_w( result->className ));
447         p += strlenW( result->className ) + 1;
448         break;
449     }
450
451     /* Get the window caption */
452
453     result->caption = (LPCWSTR)p;
454     p += strlenW( result->caption ) + 1;
455     TRACE(" CAPTION %s\n", debugstr_w( result->caption ) );
456
457     /* Get the font name */
458
459     if (result->style & DS_SETFONT)
460     {
461         result->pointSize = GET_WORD(p);
462         p++;
463         if (result->dialogEx)
464         {
465             result->weight = GET_WORD(p); p++;
466             result->italic = LOBYTE(GET_WORD(p)); p++;
467         }
468         else
469         {
470             result->weight = FW_DONTCARE;
471             result->italic = FALSE;
472         }
473         result->faceName = (LPCWSTR)p;
474         p += strlenW( result->faceName ) + 1;
475         TRACE(" FONT %d, %s, %d, %s\n",
476               result->pointSize, debugstr_w( result->faceName ),
477               result->weight, result->italic ? "TRUE" : "FALSE" );
478     }
479
480     /* First control is on dword boundary */
481     return (LPCSTR)((((int)p) + 3) & ~3);
482 }
483
484
485 /***********************************************************************
486  *           DIALOG_CreateIndirect
487  *       Creates a dialog box window
488  *
489  *       modal = TRUE if we are called from a modal dialog box.
490  *       (it's more compatible to do it here, as under Windows the owner
491  *       is never disabled if the dialog fails because of an invalid template)
492  */
493 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
494                                    HWND owner, DLGPROC dlgProc, LPARAM param,
495                                    BOOL unicode, BOOL modal )
496 {
497     HWND hwnd;
498     RECT rect;
499     DLG_TEMPLATE template;
500     DIALOGINFO * dlgInfo = NULL;
501     DWORD units = GetDialogBaseUnits();
502     BOOL ownerEnabled = TRUE;
503     HMENU hMenu = 0;
504     HFONT hUserFont = 0;
505     UINT flags = 0;
506     UINT xBaseUnit = LOWORD(units);
507     UINT yBaseUnit = HIWORD(units);
508
509       /* Parse dialog template */
510
511     if (!dlgTemplate) return 0;
512     dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
513
514       /* Load menu */
515
516     if (template.menuName) hMenu = LoadMenuW( hInst, template.menuName );
517
518       /* Create custom font if needed */
519
520     if (template.style & DS_SETFONT)
521     {
522           /* We convert the size to pixels and then make it -ve.  This works
523            * for both +ve and -ve template.pointSize */
524         HDC dc;
525         int pixels;
526         dc = GetDC(0);
527         pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
528         hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
529                                           template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
530                                           PROOF_QUALITY, FF_DONTCARE,
531                                           template.faceName );
532         if (hUserFont)
533         {
534             SIZE charSize;
535             if (DIALOG_GetCharSize( dc, hUserFont, &charSize ))
536             {
537                 xBaseUnit = charSize.cx;
538                 yBaseUnit = charSize.cy;
539             }
540         }
541         ReleaseDC(0, dc);
542         TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
543     }
544
545     /* Create dialog main window */
546
547     rect.left = rect.top = 0;
548     rect.right = MulDiv(template.cx, xBaseUnit, 4);
549     rect.bottom =  MulDiv(template.cy, yBaseUnit, 8);
550     if (template.style & WS_CHILD)
551         template.style &= ~(WS_CAPTION|WS_SYSMENU);
552     if (template.style & DS_MODALFRAME)
553         template.exStyle |= WS_EX_DLGMODALFRAME;
554     if (template.style & DS_CONTROL)
555         template.exStyle |= WS_EX_CONTROLPARENT;
556     AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
557     rect.right -= rect.left;
558     rect.bottom -= rect.top;
559
560     if (template.x == CW_USEDEFAULT16)
561     {
562         rect.left = rect.top = CW_USEDEFAULT;
563     }
564     else
565     {
566         if (template.style & DS_CENTER)
567         {
568             rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
569             rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
570         }
571         else
572         {
573             rect.left += MulDiv(template.x, xBaseUnit, 4);
574             rect.top += MulDiv(template.y, yBaseUnit, 8);
575         }
576         if ( !(template.style & WS_CHILD) )
577         {
578             INT dX, dY;
579
580             if( !(template.style & DS_ABSALIGN) )
581                 ClientToScreen( owner, (POINT *)&rect );
582
583             /* try to fit it into the desktop */
584
585             if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
586                  - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
587             if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
588                  - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
589             if( rect.left < 0 ) rect.left = 0;
590             if( rect.top < 0 ) rect.top = 0;
591         }
592     }
593
594     if (modal)
595     {
596         ownerEnabled = DIALOG_DisableOwner( owner );
597         if (ownerEnabled) flags |= DF_OWNERENABLED;
598     }
599
600     if (unicode)
601     {
602         hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
603                                template.style & ~WS_VISIBLE,
604                                rect.left, rect.top, rect.right, rect.bottom,
605                                owner, hMenu, hInst, NULL );
606     }
607     else
608     {
609         LPSTR class = (LPSTR)template.className;
610         LPSTR caption = (LPSTR)template.caption;
611
612         if (HIWORD(class))
613         {
614             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
615             class = HeapAlloc( GetProcessHeap(), 0, len );
616             WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
617         }
618         if (HIWORD(caption))
619         {
620             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
621             caption = HeapAlloc( GetProcessHeap(), 0, len );
622             WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
623         }
624         hwnd = CreateWindowExA(template.exStyle, class, caption,
625                                template.style & ~WS_VISIBLE,
626                                rect.left, rect.top, rect.right, rect.bottom,
627                                owner, hMenu, hInst, NULL );
628         if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
629         if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
630     }
631
632     if (!hwnd)
633     {
634         if (hUserFont) DeleteObject( hUserFont );
635         if (hMenu) DestroyMenu( hMenu );
636         if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
637         return 0;
638     }
639
640     /* moved this from the top of the method to here as DIALOGINFO structure
641     will be valid only after WM_CREATE message has been handled in DefDlgProc
642     All the members of the structure get filled here using temp variables */
643     dlgInfo = DIALOG_get_info( hwnd, TRUE );
644     dlgInfo->hwndFocus   = 0;
645     dlgInfo->hUserFont   = hUserFont;
646     dlgInfo->hMenu       = hMenu;
647     dlgInfo->xBaseUnit   = xBaseUnit;
648     dlgInfo->yBaseUnit   = yBaseUnit;
649     dlgInfo->idResult    = 0;
650     dlgInfo->flags       = flags;
651     dlgInfo->hDialogHeap = 0;
652
653     if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
654
655     if (unicode) SetWindowLongPtrW( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
656     else SetWindowLongPtrA( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
657
658     if (dlgInfo->hUserFont)
659         SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
660
661     /* Create controls */
662
663     if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
664     {
665         /* Send initialisation messages and set focus */
666
667         if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ) &&
668             ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
669         {
670             /* By returning TRUE, app has requested a default focus assignment */
671             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
672             if( dlgInfo->hwndFocus )
673                 SetFocus( dlgInfo->hwndFocus );
674         }
675
676         if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
677         {
678            ShowWindow( hwnd, SW_SHOWNORMAL );   /* SW_SHOW doesn't always work */
679         }
680         return hwnd;
681     }
682     if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
683     if( IsWindow(hwnd) ) DestroyWindow( hwnd );
684     return 0;
685 }
686
687
688 /***********************************************************************
689  *              CreateDialogParamA (USER32.@)
690  */
691 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name, HWND owner,
692                                 DLGPROC dlgProc, LPARAM param )
693 {
694     HRSRC hrsrc;
695     LPCDLGTEMPLATEA ptr;
696
697     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
698     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
699     return CreateDialogIndirectParamA( hInst, ptr, owner, dlgProc, param );
700 }
701
702
703 /***********************************************************************
704  *              CreateDialogParamW (USER32.@)
705  */
706 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name, HWND owner,
707                                 DLGPROC dlgProc, LPARAM param )
708 {
709     HRSRC hrsrc;
710     LPCDLGTEMPLATEA ptr;
711
712     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
713     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
714     return CreateDialogIndirectParamW( hInst, ptr, owner, dlgProc, param );
715 }
716
717
718 /***********************************************************************
719  *              CreateDialogIndirectParamAorW (USER32.@)
720  */
721 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst, LPCVOID dlgTemplate,
722                                            HWND owner, DLGPROC dlgProc, LPARAM param,
723                                            DWORD flags )
724 {
725     return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, !flags, FALSE );
726 }
727
728 /***********************************************************************
729  *              CreateDialogIndirectParamA (USER32.@)
730  */
731 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst, LPCDLGTEMPLATEA dlgTemplate,
732                                         HWND owner, DLGPROC dlgProc, LPARAM param )
733 {
734     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 2 );
735 }
736
737 /***********************************************************************
738  *              CreateDialogIndirectParamW (USER32.@)
739  */
740 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst, LPCDLGTEMPLATEW dlgTemplate,
741                                         HWND owner, DLGPROC dlgProc, LPARAM param )
742 {
743     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 0 );
744 }
745
746
747 /***********************************************************************
748  *           DIALOG_DoDialogBox
749  */
750 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
751 {
752     DIALOGINFO * dlgInfo;
753     MSG msg;
754     INT retval;
755     HWND ownerMsg = GetAncestor( owner, GA_ROOT );
756     BOOL bFirstEmpty;
757
758     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE ))) return -1;
759
760     bFirstEmpty = TRUE;
761     if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
762     {
763         for (;;)
764         {
765             if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
766             {
767                 if (bFirstEmpty)
768                 {
769                     /* ShowWindow the first time the queue goes empty */
770                     ShowWindow( hwnd, SW_SHOWNORMAL );
771                     bFirstEmpty = FALSE;
772                 }
773                 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
774                {
775                     /* No message present -> send ENTERIDLE and wait */
776                     SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
777                 }
778                 if (!GetMessageW( &msg, 0, 0, 0 )) break;
779             }
780
781             if (!IsWindow( hwnd )) return -1;
782             if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
783             {
784                 TranslateMessage( &msg );
785                 DispatchMessageW( &msg );
786             }
787             if (dlgInfo->flags & DF_END) break;
788         }
789     }
790     if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
791     retval = dlgInfo->idResult;
792     DestroyWindow( hwnd );
793     return retval;
794 }
795
796
797 /***********************************************************************
798  *              DialogBoxParamA (USER32.@)
799  */
800 INT_PTR WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
801                                 HWND owner, DLGPROC dlgProc, LPARAM param )
802 {
803     HWND hwnd;
804     HRSRC hrsrc;
805     LPCDLGTEMPLATEA ptr;
806
807     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
808     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
809     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, FALSE, TRUE );
810     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
811     return -1;
812 }
813
814
815 /***********************************************************************
816  *              DialogBoxParamW (USER32.@)
817  */
818 INT_PTR WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
819                                 HWND owner, DLGPROC dlgProc, LPARAM param )
820 {
821     HWND hwnd;
822     HRSRC hrsrc;
823     LPCDLGTEMPLATEW ptr;
824
825     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
826     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
827     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, TRUE, TRUE );
828     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
829     return -1;
830 }
831
832
833 /***********************************************************************
834  *              DialogBoxIndirectParamAorW (USER32.@)
835  */
836 INT_PTR WINAPI DialogBoxIndirectParamAorW( HINSTANCE hInstance, LPCVOID template,
837                                            HWND owner, DLGPROC dlgProc,
838                                            LPARAM param, DWORD flags )
839 {
840     HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, !flags, TRUE );
841     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
842     return -1;
843 }
844
845 /***********************************************************************
846  *              DialogBoxIndirectParamA (USER32.@)
847  */
848 INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCDLGTEMPLATEA template,
849                                        HWND owner, DLGPROC dlgProc, LPARAM param )
850 {
851     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 2 );
852 }
853
854
855 /***********************************************************************
856  *              DialogBoxIndirectParamW (USER32.@)
857  */
858 INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCDLGTEMPLATEW template,
859                                        HWND owner, DLGPROC dlgProc, LPARAM param )
860 {
861     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 0 );
862 }
863
864 /***********************************************************************
865  *              EndDialog (USER32.@)
866  */
867 BOOL WINAPI EndDialog( HWND hwnd, INT_PTR retval )
868 {
869     BOOL wasEnabled = TRUE;
870     DIALOGINFO * dlgInfo;
871     HWND owner;
872
873     TRACE("%p %d\n", hwnd, retval );
874
875     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE )))
876     {
877         ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
878         return FALSE;
879     }
880     dlgInfo->idResult = retval;
881     dlgInfo->flags |= DF_END;
882     wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
883
884     if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
885         DIALOG_EnableOwner( owner );
886
887     /* Windows sets the focus to the dialog itself in EndDialog */
888
889     if (IsChild(hwnd, GetFocus()))
890        SetFocus( hwnd );
891
892     /* Don't have to send a ShowWindow(SW_HIDE), just do
893        SetWindowPos with SWP_HIDEWINDOW as done in Windows */
894
895     SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
896                  | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
897
898     if (hwnd == GetActiveWindow()) WINPOS_ActivateOtherWindow( hwnd );
899
900     /* unblock dialog loop */
901     PostMessageA(hwnd, WM_NULL, 0, 0);
902     return TRUE;
903 }
904
905
906 /***********************************************************************
907  *           DIALOG_IsAccelerator
908  */
909 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
910 {
911     HWND hwndControl = hwnd;
912     HWND hwndNext;
913     INT dlgCode;
914     WCHAR buffer[128];
915
916     do
917     {
918         DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
919         if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
920         {
921             dlgCode = SendMessageW( hwndControl, WM_GETDLGCODE, 0, 0 );
922             if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
923                  GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
924             {
925                 /* find the accelerator key */
926                 LPWSTR p = buffer - 2;
927
928                 do
929                 {
930                     p = strchrW( p + 2, '&' );
931                 }
932                 while (p != NULL && p[1] == '&');
933
934                 /* and check if it's the one we're looking for */
935                 if (p != NULL && toupperW( p[1] ) == toupperW( wParam ) )
936                 {
937                     if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
938                     {
939                         /* set focus to the control */
940                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
941                         /* and bump it on to next */
942                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, 0, 0);
943                     }
944                     else if (dlgCode & DLGC_BUTTON)
945                     {
946                         /* send BM_CLICK message to the control */
947                         SendMessageW( hwndControl, BM_CLICK, 0, 0 );
948                     }
949                     return TRUE;
950                 }
951             }
952             hwndNext = GetWindow( hwndControl, GW_CHILD );
953         }
954         else hwndNext = 0;
955
956         if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
957
958         while (!hwndNext && hwndControl)
959         {
960             hwndControl = GetParent( hwndControl );
961             if (hwndControl == hwndDlg)
962             {
963                 if(hwnd==hwndDlg)   /* prevent endless loop */
964                 {
965                     hwndNext=hwnd;
966                     break;
967                 }
968                 hwndNext = GetWindow( hwndDlg, GW_CHILD );
969             }
970             else
971                 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
972         }
973         hwndControl = hwndNext;
974     }
975     while (hwndControl && (hwndControl != hwnd));
976
977     return FALSE;
978 }
979
980 /***********************************************************************
981  *           DIALOG_FindMsgDestination
982  *
983  * The messages that IsDialogMessage sends may not go to the dialog
984  * calling IsDialogMessage if that dialog is a child, and it has the
985  * DS_CONTROL style set.
986  * We propagate up until we hit one that does not have DS_CONTROL, or
987  * whose parent is not a dialog.
988  *
989  * This is undocumented behaviour.
990  */
991 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
992 {
993     while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
994     {
995         WND *pParent;
996         HWND hParent = GetParent(hwndDlg);
997         if (!hParent) break;
998
999         pParent = WIN_GetPtr(hParent);
1000         if (!pParent || pParent == WND_OTHER_PROCESS || pParent == WND_DESKTOP) break;
1001
1002         if (!(pParent->flags & WIN_ISDIALOG))
1003         {
1004             WIN_ReleasePtr(pParent);
1005             break;
1006         }
1007         WIN_ReleasePtr(pParent);
1008
1009         hwndDlg = hParent;
1010     }
1011
1012     return hwndDlg;
1013 }
1014
1015 /***********************************************************************
1016  *              DIALOG_FixOneChildOnChangeFocus
1017  *
1018  * Callback helper for DIALOG_FixChildrenOnChangeFocus
1019  */
1020
1021 static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
1022         LPARAM lParam)
1023 {
1024     /* If a default pushbutton then no longer default */
1025     if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
1026         SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
1027     return TRUE;
1028 }
1029
1030 /***********************************************************************
1031  *              DIALOG_FixChildrenOnChangeFocus
1032  *
1033  * Following the change of focus that occurs for example after handling
1034  * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
1035  * children may be required.
1036  */
1037 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
1038 {
1039     INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
1040     /* INT dlgcode_dlg  = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
1041     /* Windows does ask for this.  I don't know why yet */
1042
1043     EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
1044
1045     /* If the button that is getting the focus WAS flagged as the default
1046      * pushbutton then ask the dialog what it thinks the default is and
1047      * set that in the default style.
1048      */
1049     if (dlgcode_next & DLGC_DEFPUSHBUTTON)
1050     {
1051         DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
1052         if (HIWORD(def_id) == DC_HASDEFID)
1053         {
1054             HWND hwndDef;
1055             def_id = LOWORD(def_id);
1056             hwndDef = GetDlgItem (hwndDlg, def_id);
1057             if (hwndDef)
1058             {
1059                 INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
1060                 /* I know that if it is a button then it should already be a
1061                  * UNDEFPUSHBUTTON, since we have just told the buttons to 
1062                  * change style.  But maybe they ignored our request
1063                  */
1064                 if ((dlgcode_def & DLGC_BUTTON) &&
1065                         (dlgcode_def &  DLGC_UNDEFPUSHBUTTON))
1066                 {
1067                     SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1068                 }
1069             }
1070         }
1071     }
1072     else
1073     {
1074         SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1075         /* I wonder why it doesn't send a DM_SETDEFID */
1076     }
1077 }
1078
1079 /***********************************************************************
1080  *              IsDialogMessageW (USER32.@)
1081  */
1082 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1083 {
1084     INT dlgCode = 0;
1085
1086     if (CallMsgFilterW( msg, MSGF_DIALOGBOX )) return TRUE;
1087
1088     hwndDlg = WIN_GetFullHandle( hwndDlg );
1089     if (hwndDlg == GetDesktopWindow()) return FALSE;
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 GetWindowLongPtrW( hwnd, GWLP_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 (GetWindowLongPtrW( list[i], GWLP_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     SendDlgItemMessageW( 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)SendDlgItemMessageW( 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 = GetWindowLongPtrW(hwndChild, GWLP_ID);
1389     RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1390
1391     if ((lChildID >= lpRadioGroup->firstID) &&
1392         (lChildID <= lpRadioGroup->lastID))
1393     {
1394         if (lChildID == lpRadioGroup->checkID)
1395         {
1396             SendMessageW(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1397         }
1398         else
1399         {
1400             SendMessageW(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, FALSE ))) 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, LPWSTR str, INT len,
1665                                  INT id, BOOL unicode, BOOL combo )
1666 {
1667     WCHAR *buffer, *ptr;
1668     INT item, size;
1669     BOOL ret;
1670     HWND listbox = GetDlgItem( hwnd, id );
1671
1672     TRACE("%p '%s' %d\n", hwnd, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str), id );
1673     if (!listbox) return FALSE;
1674
1675     item = SendMessageW(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1676     if (item == LB_ERR) return FALSE;
1677
1678     size = SendMessageW(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1679     if (size == LB_ERR) return FALSE;
1680
1681     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1682
1683     SendMessageW( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1684
1685     if ((ret = (buffer[0] == '[')))  /* drive or directory */
1686     {
1687         if (buffer[1] == '-')  /* drive */
1688         {
1689             buffer[3] = ':';
1690             buffer[4] = 0;
1691             ptr = buffer + 2;
1692         }
1693         else
1694         {
1695             buffer[strlenW(buffer)-1] = '\\';
1696             ptr = buffer + 1;
1697         }
1698     }
1699     else ptr = buffer;
1700
1701     if (!unicode)
1702     {
1703         if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, ptr, -1, (LPSTR)str, len, 0, 0 ))
1704             ((LPSTR)str)[len-1] = 0;
1705     }
1706     else lstrcpynW( str, ptr, len );
1707     HeapFree( GetProcessHeap(), 0, buffer );
1708     TRACE("Returning %d '%s'\n", ret, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str) );
1709     return ret;
1710 }
1711
1712
1713 /**********************************************************************
1714  *          DIALOG_DlgDirListW
1715  *
1716  * Helper function for DlgDirList*W
1717  */
1718 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1719                                INT idStatic, UINT attrib, BOOL combo )
1720 {
1721     HWND hwnd;
1722     LPWSTR orig_spec = spec;
1723     WCHAR any[] = {'*','.','*',0};
1724
1725 #define SENDMSG(msg,wparam,lparam) \
1726     ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1727                              : SendMessageW( hwnd, msg, wparam, lparam ))
1728
1729     TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib );
1730
1731     /* If the path exists and is a directory, chdir to it */
1732     if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any;
1733     else
1734     {
1735         WCHAR *p, *p2;
1736         p = spec;
1737         if ((p2 = strrchrW( p, '\\' ))) p = p2;
1738         if ((p2 = strrchrW( p, '/' ))) p = p2;
1739         if (p != spec)
1740         {
1741             WCHAR sep = *p;
1742             *p = 0;
1743             if (!SetCurrentDirectoryW( spec ))
1744             {
1745                 *p = sep;  /* Restore the original spec */
1746                 return FALSE;
1747             }
1748             spec = p + 1;
1749         }
1750     }
1751
1752     TRACE( "mask=%s\n", debugstr_w(spec) );
1753
1754     if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1755     {
1756         SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1757         if (attrib & DDL_DIRECTORY)
1758         {
1759             if (!(attrib & DDL_EXCLUSIVE))
1760             {
1761                 if (SENDMSG( combo ? CB_DIR : LB_DIR,
1762                              attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1763                              (LPARAM)spec ) == LB_ERR)
1764                     return FALSE;
1765             }
1766             if (SENDMSG( combo ? CB_DIR : LB_DIR,
1767                        (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1768                          (LPARAM)any ) == LB_ERR)
1769                 return FALSE;
1770         }
1771         else
1772         {
1773             if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
1774                          (LPARAM)spec ) == LB_ERR)
1775                 return FALSE;
1776         }
1777     }
1778
1779     if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1780     {
1781         WCHAR temp[MAX_PATH];
1782         GetCurrentDirectoryW( sizeof(temp)/sizeof(WCHAR), temp );
1783         CharLowerW( temp );
1784         /* Can't use PostMessage() here, because the string is on the stack */
1785         SetDlgItemTextW( hDlg, idStatic, temp );
1786     }
1787
1788     if (orig_spec && (spec != orig_spec))
1789     {
1790         /* Update the original file spec */
1791         WCHAR *p = spec;
1792         while ((*orig_spec++ = *p++));
1793     }
1794
1795     return TRUE;
1796 #undef SENDMSG
1797 }
1798
1799
1800 /**********************************************************************
1801  *          DIALOG_DlgDirListA
1802  *
1803  * Helper function for DlgDirList*A
1804  */
1805 static INT DIALOG_DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1806                                INT idStatic, UINT attrib, BOOL combo )
1807 {
1808     if (spec)
1809     {
1810         INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
1811         LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1812         MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
1813         ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
1814         WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );
1815         HeapFree( GetProcessHeap(), 0, specW );
1816         return ret;
1817     }
1818     return DIALOG_DlgDirListW( hDlg, NULL, idLBox, idStatic, attrib, combo );
1819 }
1820
1821
1822 /**********************************************************************
1823  *              DlgDirSelectExA (USER32.@)
1824  */
1825 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
1826 {
1827     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, FALSE );
1828 }
1829
1830
1831 /**********************************************************************
1832  *              DlgDirSelectExW (USER32.@)
1833  */
1834 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
1835 {
1836     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE );
1837 }
1838
1839
1840 /**********************************************************************
1841  *              DlgDirSelectComboBoxExA (USER32.@)
1842  */
1843 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
1844                                          INT id )
1845 {
1846     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, TRUE );
1847 }
1848
1849
1850 /**********************************************************************
1851  *              DlgDirSelectComboBoxExW (USER32.@)
1852  */
1853 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
1854                                          INT id)
1855 {
1856     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, TRUE );
1857 }
1858
1859
1860 /**********************************************************************
1861  *              DlgDirListA (USER32.@)
1862  */
1863 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1864                             INT idStatic, UINT attrib )
1865 {
1866     return DIALOG_DlgDirListA( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1867 }
1868
1869
1870 /**********************************************************************
1871  *              DlgDirListW (USER32.@)
1872  */
1873 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1874                             INT idStatic, UINT attrib )
1875 {
1876     return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1877 }
1878
1879
1880 /**********************************************************************
1881  *              DlgDirListComboBoxA (USER32.@)
1882  */
1883 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
1884                                     INT idStatic, UINT attrib )
1885 {
1886     return DIALOG_DlgDirListA( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1887 }
1888
1889
1890 /**********************************************************************
1891  *              DlgDirListComboBoxW (USER32.@)
1892  */
1893 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
1894                                     INT idStatic, UINT attrib )
1895 {
1896     return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1897 }