4 * Copyright 1993, 1994, 1996 Alexandre Julliard
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.
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.
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
22 #include "wine/port.h"
36 #include "wine/winuser16.h"
37 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
47 /* Dialog control information */
84 /* Radio button group */
92 /* Dialog base units */
93 static WORD xBaseUnit = 0, yBaseUnit = 0;
96 /*********************************************************************
97 * dialog class descriptor
99 const struct builtin_class_descr DIALOG_builtin_class =
101 DIALOG_CLASS_ATOMA, /* name */
102 CS_GLOBALCLASS | CS_SAVEBITS | CS_DBLCLKS, /* style */
103 DefDlgProcA, /* procA */
104 DefDlgProcW, /* procW */
105 DLGWINDOWEXTRA, /* extra */
106 IDC_ARROWA, /* cursor */
111 /***********************************************************************
114 * Helper function for modal dialogs to enable again the
115 * owner of the dialog box.
117 void DIALOG_EnableOwner( HWND hOwner )
119 /* Owner must be a top-level window */
121 hOwner = GetAncestor( hOwner, GA_ROOT );
123 EnableWindow( hOwner, TRUE );
127 /***********************************************************************
128 * DIALOG_DisableOwner
130 * Helper function for modal dialogs to disable the
131 * owner of the dialog box. Returns TRUE if owner was enabled.
133 BOOL DIALOG_DisableOwner( HWND hOwner )
135 /* Owner must be a top-level window */
137 hOwner = GetAncestor( hOwner, GA_ROOT );
138 if (!hOwner) return FALSE;
139 if (IsWindowEnabled( hOwner ))
141 EnableWindow( hOwner, FALSE );
148 /***********************************************************************
149 * DIALOG_GetCharSizeFromDC
151 * Despite most of MSDN insisting that the horizontal base unit is
152 * tmAveCharWidth it isn't. Knowledge base article Q145994
153 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
154 * says that we should take the average of the 52 English upper and lower
157 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
160 char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
164 pSize->cx = xBaseUnit;
165 pSize->cy = yBaseUnit;
167 if(!hDC) return FALSE;
169 if(hFont) hFontPrev = SelectObject(hDC, hFont);
170 if(!GetTextMetricsA(hDC, &tm)) return FALSE;
171 if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
173 pSize->cy = tm.tmHeight;
174 pSize->cx = (sz.cx / 26 + 1) / 2;
176 if (hFontPrev) SelectObject(hDC, hFontPrev);
178 TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy);
182 /***********************************************************************
185 * A convenient variant of DIALOG_GetCharSizeFromDC.
187 BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
190 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
195 /***********************************************************************
198 * Initialisation of the dialog manager.
200 BOOL DIALOG_Init(void)
205 /* Calculate the dialog base units */
207 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
209 ERR("Could not create Display DC\n");
213 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size ))
216 ERR("Could not initialize base dialog units\n");
224 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
229 /***********************************************************************
230 * DIALOG_GetControl32
232 * Return the class and text of the control pointed to by ptr,
233 * fill the header structure and return a pointer to the next control.
235 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
240 info->helpId = GET_DWORD(p); p += 2;
241 info->exStyle = GET_DWORD(p); p += 2;
242 info->style = GET_DWORD(p); p += 2;
247 info->style = GET_DWORD(p); p += 2;
248 info->exStyle = GET_DWORD(p); p += 2;
250 info->x = GET_WORD(p); p++;
251 info->y = GET_WORD(p); p++;
252 info->cx = GET_WORD(p); p++;
253 info->cy = GET_WORD(p); p++;
257 /* id is a DWORD for DIALOGEX */
258 info->id = GET_DWORD(p);
263 info->id = GET_WORD(p);
267 if (GET_WORD(p) == 0xffff)
269 static const WCHAR class_names[6][10] =
271 { 'B','u','t','t','o','n', }, /* 0x80 */
272 { 'E','d','i','t', }, /* 0x81 */
273 { 'S','t','a','t','i','c', }, /* 0x82 */
274 { 'L','i','s','t','B','o','x', }, /* 0x83 */
275 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
276 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
278 WORD id = GET_WORD(p+1);
279 if ((id >= 0x80) && (id <= 0x85))
280 info->className = class_names[id - 0x80];
283 info->className = NULL;
284 ERR("Unknown built-in class id %04x\n", id );
290 info->className = (LPCWSTR)p;
291 p += strlenW( info->className ) + 1;
294 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
296 info->windowName = (LPCWSTR)(UINT)GET_WORD(p + 1);
301 info->windowName = (LPCWSTR)p;
302 p += strlenW( info->windowName ) + 1;
305 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
306 debugstr_w( info->className ), debugstr_w( info->windowName ),
307 info->id, info->x, info->y, info->cx, info->cy,
308 info->style, info->exStyle, info->helpId );
312 if (TRACE_ON(dialog))
314 WORD i, count = GET_WORD(p) / sizeof(WORD);
317 for (i = 0; i < count; i++) TRACE( "%04x,", GET_WORD(p+i+1) );
322 p += GET_WORD(p) / sizeof(WORD);
324 else info->data = NULL;
327 /* Next control is on dword boundary */
328 return (const WORD *)((((int)p) + 3) & ~3);
332 /***********************************************************************
333 * DIALOG_CreateControls32
335 * Create the control windows for a dialog.
337 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
338 HINSTANCE hInst, BOOL unicode )
340 DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd );
341 DLG_CONTROL_INFO info;
342 HWND hwndCtrl, hwndDefButton = 0;
343 INT items = dlgTemplate->nbItems;
348 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
349 dlgTemplate->dialogEx );
351 if (info.style & WS_BORDER)
353 info.style &= ~WS_BORDER;
354 info.exStyle |= WS_EX_CLIENTEDGE;
358 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
359 info.className, info.windowName,
360 info.style | WS_CHILD,
361 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
362 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
363 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
364 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
365 hwnd, (HMENU)info.id,
366 hInst, (LPVOID)info.data );
370 LPSTR class = (LPSTR)info.className;
371 LPSTR caption = (LPSTR)info.windowName;
375 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
376 class = HeapAlloc( GetProcessHeap(), 0, len );
377 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
381 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
382 caption = HeapAlloc( GetProcessHeap(), 0, len );
383 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
385 hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
386 class, caption, info.style | WS_CHILD,
387 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
388 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
389 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
390 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
391 hwnd, (HMENU)info.id,
392 hInst, (LPVOID)info.data );
393 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
394 if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
398 if (dlgTemplate->style & DS_NOFAILCREATE) continue;
402 /* Send initialisation messages to the control */
403 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
404 (WPARAM)dlgInfo->hUserFont, 0 );
405 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
407 /* If there's already a default push-button, set it back */
408 /* to normal and use this one instead. */
410 SendMessageA( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
411 hwndDefButton = hwndCtrl;
412 dlgInfo->idResult = GetWindowLongA( hwndCtrl, GWL_ID );
420 /***********************************************************************
421 * DIALOG_ParseTemplate32
423 * Fill a DLG_TEMPLATE structure from the dialog template, and return
424 * a pointer to the first control.
426 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
428 const WORD *p = (const WORD *)template;
430 result->style = GET_DWORD(p); p += 2;
431 if (result->style == 0xffff0001) /* DIALOGEX resource */
433 result->dialogEx = TRUE;
434 result->helpId = GET_DWORD(p); p += 2;
435 result->exStyle = GET_DWORD(p); p += 2;
436 result->style = GET_DWORD(p); p += 2;
440 result->dialogEx = FALSE;
442 result->exStyle = GET_DWORD(p); p += 2;
444 result->nbItems = GET_WORD(p); p++;
445 result->x = GET_WORD(p); p++;
446 result->y = GET_WORD(p); p++;
447 result->cx = GET_WORD(p); p++;
448 result->cy = GET_WORD(p); p++;
449 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
450 result->dialogEx ? "EX" : "", result->x, result->y,
451 result->cx, result->cy, result->helpId );
452 TRACE(" STYLE 0x%08lx\n", result->style );
453 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
455 /* Get the menu name */
460 result->menuName = NULL;
464 result->menuName = (LPCWSTR)(UINT)GET_WORD( p + 1 );
466 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
469 result->menuName = (LPCWSTR)p;
470 TRACE(" MENU %s\n", debugstr_w(result->menuName) );
471 p += strlenW( result->menuName ) + 1;
475 /* Get the class name */
480 result->className = DIALOG_CLASS_ATOMW;
484 result->className = (LPCWSTR)(UINT)GET_WORD( p + 1 );
486 TRACE(" CLASS %04x\n", LOWORD(result->className) );
489 result->className = (LPCWSTR)p;
490 TRACE(" CLASS %s\n", debugstr_w( result->className ));
491 p += strlenW( result->className ) + 1;
495 /* Get the window caption */
497 result->caption = (LPCWSTR)p;
498 p += strlenW( result->caption ) + 1;
499 TRACE(" CAPTION %s\n", debugstr_w( result->caption ) );
501 /* Get the font name */
503 if (result->style & DS_SETFONT)
505 result->pointSize = GET_WORD(p);
507 if (result->dialogEx)
509 result->weight = GET_WORD(p); p++;
510 result->italic = LOBYTE(GET_WORD(p)); p++;
514 result->weight = FW_DONTCARE;
515 result->italic = FALSE;
517 result->faceName = (LPCWSTR)p;
518 p += strlenW( result->faceName ) + 1;
519 TRACE(" FONT %d, %s, %d, %s\n",
520 result->pointSize, debugstr_w( result->faceName ),
521 result->weight, result->italic ? "TRUE" : "FALSE" );
524 /* First control is on dword boundary */
525 return (LPCSTR)((((int)p) + 3) & ~3);
529 /***********************************************************************
530 * DIALOG_CreateIndirect
531 * Creates a dialog box window
533 * modal = TRUE if we are called from a modal dialog box.
534 * (it's more compatible to do it here, as under Windows the owner
535 * is never disabled if the dialog fails because of an invalid template)
537 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
538 HWND owner, DLGPROC dlgProc, LPARAM param,
539 BOOL unicode, BOOL modal )
544 DLG_TEMPLATE template;
545 DIALOGINFO * dlgInfo;
546 BOOL ownerEnabled = TRUE;
548 /* Parse dialog template */
550 if (!dlgTemplate) return 0;
551 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
553 /* Initialise dialog extra data */
555 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
556 dlgInfo->hwndFocus = 0;
557 dlgInfo->hUserFont = 0;
559 dlgInfo->xBaseUnit = xBaseUnit;
560 dlgInfo->yBaseUnit = yBaseUnit;
561 dlgInfo->idResult = 0;
563 dlgInfo->hDialogHeap = 0;
567 if (template.menuName) dlgInfo->hMenu = LoadMenuW( hInst, template.menuName );
569 /* Create custom font if needed */
571 if (template.style & DS_SETFONT)
573 /* We convert the size to pixels and then make it -ve. This works
574 * for both +ve and -ve template.pointSize */
578 pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
580 dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
581 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
582 PROOF_QUALITY, FF_DONTCARE,
584 if (dlgInfo->hUserFont)
587 if (DIALOG_GetCharSize( dlgInfo->hUserFont, &charSize ))
589 dlgInfo->xBaseUnit = charSize.cx;
590 dlgInfo->yBaseUnit = charSize.cy;
593 TRACE("units = %d,%d\n", dlgInfo->xBaseUnit, dlgInfo->yBaseUnit );
596 /* Create dialog main window */
598 rect.left = rect.top = 0;
599 rect.right = MulDiv(template.cx, dlgInfo->xBaseUnit, 4);
600 rect.bottom = MulDiv(template.cy, dlgInfo->yBaseUnit, 8);
601 if (template.style & DS_MODALFRAME)
602 template.exStyle |= WS_EX_DLGMODALFRAME;
603 AdjustWindowRectEx( &rect, template.style, (dlgInfo->hMenu != 0), template.exStyle );
604 rect.right -= rect.left;
605 rect.bottom -= rect.top;
607 if (template.x == CW_USEDEFAULT16)
609 rect.left = rect.top = CW_USEDEFAULT;
613 if (template.style & DS_CENTER)
615 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
616 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
620 rect.left += MulDiv(template.x, dlgInfo->xBaseUnit, 4);
621 rect.top += MulDiv(template.y, dlgInfo->yBaseUnit, 8);
623 if ( !(template.style & WS_CHILD) )
627 if( !(template.style & DS_ABSALIGN) )
628 ClientToScreen( owner, (POINT *)&rect );
630 /* try to fit it into the desktop */
632 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
633 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
634 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
635 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
636 if( rect.left < 0 ) rect.left = 0;
637 if( rect.top < 0 ) rect.top = 0;
643 ownerEnabled = DIALOG_DisableOwner( owner );
644 if (ownerEnabled) dlgInfo->flags |= DF_OWNERENABLED;
649 hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
650 template.style & ~WS_VISIBLE,
651 rect.left, rect.top, rect.right, rect.bottom,
652 owner, dlgInfo->hMenu, hInst, NULL );
656 LPSTR class = (LPSTR)template.className;
657 LPSTR caption = (LPSTR)template.caption;
661 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
662 class = HeapAlloc( GetProcessHeap(), 0, len );
663 WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
667 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
668 caption = HeapAlloc( GetProcessHeap(), 0, len );
669 WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
671 hwnd = CreateWindowExA(template.exStyle, class, caption,
672 template.style & ~WS_VISIBLE,
673 rect.left, rect.top, rect.right, rect.bottom,
674 owner, dlgInfo->hMenu, hInst, NULL );
675 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
676 if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
681 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
682 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
683 if (modal && (dlgInfo->flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
684 HeapFree( GetProcessHeap(), 0, dlgInfo );
687 wndPtr = WIN_GetPtr( hwnd );
688 wndPtr->flags |= WIN_ISDIALOG;
689 WIN_ReleasePtr( wndPtr );
691 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
692 SetWindowLongW( hwnd, DWL_WINE_DIALOGINFO, (LONG)dlgInfo );
694 if (unicode) SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc );
695 else SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc );
697 if (dlgInfo->hUserFont)
698 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
700 /* Create controls */
702 if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
704 HWND hwndPreInitFocus;
706 /* Send initialisation messages and set focus */
708 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
710 hwndPreInitFocus = GetFocus();
711 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
713 /* check where the focus is again,
714 * some controls status might have changed in WM_INITDIALOG */
715 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
716 if( dlgInfo->hwndFocus )
717 SetFocus( dlgInfo->hwndFocus );
721 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
722 but the focus has not changed, set the focus where we expect it. */
723 if ((GetFocus() == hwndPreInitFocus) &&
724 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
726 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
727 if( dlgInfo->hwndFocus )
728 SetFocus( dlgInfo->hwndFocus );
732 if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
734 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
738 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
739 if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
744 /***********************************************************************
745 * CreateDialogParamA (USER32.@)
747 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name, HWND owner,
748 DLGPROC dlgProc, LPARAM param )
753 if (!(hrsrc = FindResourceA( hInst, name, RT_DIALOGA ))) return 0;
754 if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
755 return CreateDialogIndirectParamA( hInst, ptr, owner, dlgProc, param );
759 /***********************************************************************
760 * CreateDialogParamW (USER32.@)
762 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name, HWND owner,
763 DLGPROC dlgProc, LPARAM param )
768 if (!(hrsrc = FindResourceW( hInst, name, RT_DIALOGW ))) return 0;
769 if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
770 return CreateDialogIndirectParamW( hInst, ptr, owner, dlgProc, param );
774 /***********************************************************************
775 * CreateDialogIndirectParamAorW (USER32.@)
777 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst, LPCVOID dlgTemplate,
778 HWND owner, DLGPROC dlgProc, LPARAM param,
781 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, !flags, FALSE );
784 /***********************************************************************
785 * CreateDialogIndirectParamA (USER32.@)
787 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst, LPCDLGTEMPLATEA dlgTemplate,
788 HWND owner, DLGPROC dlgProc, LPARAM param )
790 return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 2 );
793 /***********************************************************************
794 * CreateDialogIndirectParamW (USER32.@)
796 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst, LPCDLGTEMPLATEW dlgTemplate,
797 HWND owner, DLGPROC dlgProc, LPARAM param )
799 return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 0 );
803 /***********************************************************************
806 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
808 DIALOGINFO * dlgInfo;
811 HWND ownerMsg = GetAncestor( owner, GA_ROOT );
813 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return -1;
815 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
817 ShowWindow( hwnd, SW_SHOW );
820 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
822 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
824 /* No message present -> send ENTERIDLE and wait */
825 SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
826 if (!GetMessageW( &msg, 0, 0, 0 )) break;
829 else if (!GetMessageW( &msg, 0, 0, 0 )) break;
831 if (!IsWindow( hwnd )) return -1;
832 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
834 TranslateMessage( &msg );
835 DispatchMessageW( &msg );
837 if (dlgInfo->flags & DF_END) break;
840 if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
841 retval = dlgInfo->idResult;
842 DestroyWindow( hwnd );
847 /***********************************************************************
848 * DialogBoxParamA (USER32.@)
850 INT_PTR WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
851 HWND owner, DLGPROC dlgProc, LPARAM param )
857 if (!(hrsrc = FindResourceA( hInst, name, RT_DIALOGA ))) return 0;
858 if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
859 hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, FALSE, TRUE );
860 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
865 /***********************************************************************
866 * DialogBoxParamW (USER32.@)
868 INT_PTR WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
869 HWND owner, DLGPROC dlgProc, LPARAM param )
875 if (!(hrsrc = FindResourceW( hInst, name, RT_DIALOGW ))) return 0;
876 if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
877 hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, TRUE, TRUE );
878 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
883 /***********************************************************************
884 * DialogBoxIndirectParamAorW (USER32.@)
886 INT_PTR WINAPI DialogBoxIndirectParamAorW( HINSTANCE hInstance, LPCVOID template,
887 HWND owner, DLGPROC dlgProc,
888 LPARAM param, DWORD flags )
890 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, !flags, TRUE );
891 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
895 /***********************************************************************
896 * DialogBoxIndirectParamA (USER32.@)
898 INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCDLGTEMPLATEA template,
899 HWND owner, DLGPROC dlgProc, LPARAM param )
901 return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 2 );
905 /***********************************************************************
906 * DialogBoxIndirectParamW (USER32.@)
908 INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCDLGTEMPLATEW template,
909 HWND owner, DLGPROC dlgProc, LPARAM param )
911 return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 0 );
914 /***********************************************************************
915 * EndDialog (USER32.@)
917 BOOL WINAPI EndDialog( HWND hwnd, INT_PTR retval )
919 BOOL wasEnabled = TRUE;
920 DIALOGINFO * dlgInfo;
923 TRACE("%p %d\n", hwnd, retval );
925 if (!(dlgInfo = DIALOG_get_info( hwnd )))
927 ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
930 dlgInfo->idResult = retval;
931 dlgInfo->flags |= DF_END;
932 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
934 if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
935 DIALOG_EnableOwner( owner );
937 /* Windows sets the focus to the dialog itself in EndDialog */
939 if (IsChild(hwnd, GetFocus()))
942 /* Don't have to send a ShowWindow(SW_HIDE), just do
943 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
945 SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
946 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
948 /* unblock dialog loop */
949 PostMessageA(hwnd, WM_NULL, 0, 0);
954 /***********************************************************************
955 * DIALOG_IsAccelerator
957 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
959 HWND hwndControl = hwnd;
966 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
967 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
969 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
970 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
971 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
973 /* find the accelerator key */
974 LPWSTR p = buffer - 2;
978 p = strchrW( p + 2, '&' );
980 while (p != NULL && p[1] == '&');
982 /* and check if it's the one we're looking for */
983 if (p != NULL && toupperW( p[1] ) == toupperW( wParam ) )
985 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
987 /* set focus to the control */
988 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
989 /* and bump it on to next */
990 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
992 else if (dlgCode & DLGC_BUTTON)
994 /* send BM_CLICK message to the control */
995 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1000 hwndNext = GetWindow( hwndControl, GW_CHILD );
1004 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1006 while (!hwndNext && hwndControl)
1008 hwndControl = GetParent( hwndControl );
1009 if (hwndControl == hwndDlg)
1011 if(hwnd==hwndDlg) /* prevent endless loop */
1016 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1019 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1021 hwndControl = hwndNext;
1023 while (hwndControl && (hwndControl != hwnd));
1028 /***********************************************************************
1029 * DIALOG_FindMsgDestination
1031 * The messages that IsDialogMessage sends may not go to the dialog
1032 * calling IsDialogMessage if that dialog is a child, and it has the
1033 * DS_CONTROL style set.
1034 * We propagate up until we hit one that does not have DS_CONTROL, or
1035 * whose parent is not a dialog.
1037 * This is undocumented behaviour.
1039 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1041 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1044 HWND hParent = GetParent(hwndDlg);
1045 if (!hParent) break;
1047 pParent = WIN_FindWndPtr(hParent);
1048 if (!pParent) break;
1050 if (!(pParent->flags & WIN_ISDIALOG))
1052 WIN_ReleaseWndPtr(pParent);
1055 WIN_ReleaseWndPtr(pParent);
1063 /***********************************************************************
1064 * IsDialogMessageW (USER32.@)
1066 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1070 if (CallMsgFilterW( msg, MSGF_DIALOGBOX )) return TRUE;
1072 hwndDlg = WIN_GetFullHandle( hwndDlg );
1073 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
1075 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1077 switch(msg->message)
1080 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1081 if (dlgCode & DLGC_WANTMESSAGE) break;
1086 if (!(dlgCode & DLGC_WANTTAB))
1088 SendMessageW( hwndDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1097 if (!(dlgCode & DLGC_WANTARROWS))
1099 BOOL fPrevious = (msg->wParam == VK_LEFT || msg->wParam == VK_UP);
1100 HWND hwndNext = GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1101 SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1108 SendMessageW( hwndDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1114 DWORD dw = SendMessageW( hwndDlg, DM_GETDEFID, 0, 0 );
1115 if (HIWORD(dw) == DC_HASDEFID)
1117 SendMessageW( hwndDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1118 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1122 SendMessageW( hwndDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1131 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1132 if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
1133 if (msg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
1137 if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg->hwnd), hwndDlg, msg->wParam ))
1139 /* don't translate or dispatch */
1145 TranslateMessage( msg );
1146 DispatchMessageW( msg );
1151 /***********************************************************************
1152 * GetDlgCtrlID (USER32.@)
1154 INT WINAPI GetDlgCtrlID( HWND hwnd )
1156 return GetWindowLongW( hwnd, GWL_ID );
1160 /***********************************************************************
1161 * GetDlgItem (USER32.@)
1163 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1166 HWND *list = WIN_ListChildren( hwndDlg );
1169 if (!list) return 0;
1171 for (i = 0; list[i]; i++) if (GetWindowLongW( list[i], GWL_ID ) == id) break;
1173 HeapFree( GetProcessHeap(), 0, list );
1178 /*******************************************************************
1179 * SendDlgItemMessageA (USER32.@)
1181 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1182 WPARAM wParam, LPARAM lParam )
1184 HWND hwndCtrl = GetDlgItem( hwnd, id );
1185 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1190 /*******************************************************************
1191 * SendDlgItemMessageW (USER32.@)
1193 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1194 WPARAM wParam, LPARAM lParam )
1196 HWND hwndCtrl = GetDlgItem( hwnd, id );
1197 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1202 /*******************************************************************
1203 * SetDlgItemTextA (USER32.@)
1205 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1207 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1211 /*******************************************************************
1212 * SetDlgItemTextW (USER32.@)
1214 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1216 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1220 /***********************************************************************
1221 * GetDlgItemTextA (USER32.@)
1223 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1225 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1230 /***********************************************************************
1231 * GetDlgItemTextW (USER32.@)
1233 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1235 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1240 /*******************************************************************
1241 * SetDlgItemInt (USER32.@)
1243 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1248 if (fSigned) sprintf( str, "%d", (INT)value );
1249 else sprintf( str, "%u", value );
1250 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1255 /***********************************************************************
1256 * GetDlgItemInt (USER32.@)
1258 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1265 if (translated) *translated = FALSE;
1266 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1270 result = strtol( str, &endptr, 10 );
1271 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1273 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1278 result = strtoul( str, &endptr, 10 );
1279 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1281 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1283 if (translated) *translated = TRUE;
1284 return (UINT)result;
1288 /***********************************************************************
1289 * CheckDlgButton (USER32.@)
1291 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1293 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1298 /***********************************************************************
1299 * IsDlgButtonChecked (USER32.@)
1301 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1303 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1307 /***********************************************************************
1310 * Callback function used to check/uncheck radio buttons that fall
1311 * within a specific range of IDs.
1313 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1315 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1316 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1318 if ((lChildID >= lpRadioGroup->firstID) &&
1319 (lChildID <= lpRadioGroup->lastID))
1321 if (lChildID == lpRadioGroup->checkID)
1323 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1327 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1335 /***********************************************************************
1336 * CheckRadioButton (USER32.@)
1338 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1339 UINT lastID, UINT checkID )
1341 RADIOGROUP radioGroup;
1343 /* perform bounds checking for a radio button group */
1344 radioGroup.firstID = min(min(firstID, lastID), checkID);
1345 radioGroup.lastID = max(max(firstID, lastID), checkID);
1346 radioGroup.checkID = checkID;
1348 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1349 (LPARAM)&radioGroup);
1353 /***********************************************************************
1354 * GetDialogBaseUnits (USER.243)
1355 * GetDialogBaseUnits (USER32.@)
1357 DWORD WINAPI GetDialogBaseUnits(void)
1359 return MAKELONG( xBaseUnit, yBaseUnit );
1363 /***********************************************************************
1364 * MapDialogRect (USER32.@)
1366 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1368 DIALOGINFO * dlgInfo;
1369 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return FALSE;
1370 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1371 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1372 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1373 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1378 /***********************************************************************
1379 * GetNextDlgGroupItem (USER32.@)
1381 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1383 HWND hwnd, retvalue;
1385 hwndDlg = WIN_GetFullHandle( hwndDlg );
1386 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1390 /* if the hwndCtrl is the child of the control in the hwndDlg,
1391 * then the hwndDlg has to be the parent of the hwndCtrl */
1392 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1393 hwndDlg = GetParent(hwndCtrl);
1398 /* Make sure hwndCtrl is a top-level child */
1399 HWND parent = GetParent( hwndCtrl );
1400 while (parent && parent != hwndDlg) parent = GetParent(parent);
1401 if (parent != hwndDlg) return 0;
1405 /* No ctrl specified -> start from the beginning */
1406 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1407 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
1410 retvalue = hwndCtrl;
1411 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
1414 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
1416 /* Wrap-around to the beginning of the group */
1419 hwnd = GetWindow( hwndDlg, GW_CHILD );
1420 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
1422 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
1423 if (tmp == hwndCtrl) break;
1426 if (hwnd == hwndCtrl) break;
1427 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1430 if (!fPrevious) break;
1432 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
1438 /***********************************************************************
1439 * DIALOG_GetNextTabItem
1441 * Helper for GetNextDlgTabItem
1443 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1447 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1449 HWND hChildFirst = 0;
1453 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1454 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1456 else if (IsChild( hwndMain, hwndCtrl ))
1458 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1461 if(GetParent(hwndCtrl) != hwndMain)
1462 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1466 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1468 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1478 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1479 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1480 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1485 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1487 hChildFirst = GetWindow(hChildFirst,wndSearch);
1492 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1494 retWnd = hChildFirst;
1497 hChildFirst = GetWindow(hChildFirst,wndSearch);
1499 if(!retWnd && hwndCtrl)
1501 HWND hParent = GetParent(hwndCtrl);
1504 if(hParent == hwndMain) break;
1505 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1507 hParent = GetParent(hParent);
1510 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1515 /***********************************************************************
1516 * GetNextDlgTabItem (USER32.@)
1518 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1521 hwndDlg = WIN_GetFullHandle( hwndDlg );
1522 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1523 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1526 /**********************************************************************
1527 * DIALOG_DlgDirSelect
1529 * Helper function for DlgDirSelect*
1531 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
1532 INT id, BOOL unicode, BOOL combo )
1537 HWND listbox = GetDlgItem( hwnd, id );
1539 TRACE("%p '%s' %d\n", hwnd, str, id );
1540 if (!listbox) return FALSE;
1542 item = SendMessageA(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1543 if (item == LB_ERR) return FALSE;
1544 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1545 if (size == LB_ERR) return FALSE;
1547 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1549 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1551 if ((ret = (buffer[0] == '['))) /* drive or directory */
1553 if (buffer[1] == '-') /* drive */
1561 buffer[strlen(buffer)-1] = '\\';
1569 if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
1570 ((LPWSTR)str)[len-1] = 0;
1572 else lstrcpynA( str, ptr, len );
1573 HeapFree( GetProcessHeap(), 0, buffer );
1574 TRACE("Returning %d '%s'\n", ret, str );
1579 /**********************************************************************
1582 * Helper function for DlgDirList*
1584 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
1585 INT idStatic, UINT attrib, BOOL combo )
1588 LPSTR orig_spec = spec;
1590 #define SENDMSG(msg,wparam,lparam) \
1591 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1592 : SendMessageA( hwnd, msg, wparam, lparam ))
1594 TRACE("%p '%s' %d %d %04x\n",
1595 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
1597 /* If the path exists and is a directory, chdir to it */
1598 if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
1603 if ((p2 = strrchr( p, '\\' ))) p = p2;
1604 if ((p2 = strrchr( p, '/' ))) p = p2;
1609 if (!SetCurrentDirectoryA( spec ))
1611 *p = sep; /* Restore the original spec */
1618 TRACE( "mask=%s\n", spec );
1620 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1622 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1623 if (attrib & DDL_DIRECTORY)
1625 if (!(attrib & DDL_EXCLUSIVE))
1627 if (SENDMSG( combo ? CB_DIR : LB_DIR,
1628 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1629 (LPARAM)spec ) == LB_ERR)
1632 if (SENDMSG( combo ? CB_DIR : LB_DIR,
1633 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1634 (LPARAM)"*.*" ) == LB_ERR)
1639 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
1640 (LPARAM)spec ) == LB_ERR)
1645 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1647 char temp[MAX_PATH];
1648 GetCurrentDirectoryA( sizeof(temp), temp );
1650 /* Can't use PostMessage() here, because the string is on the stack */
1651 SetDlgItemTextA( hDlg, idStatic, temp );
1654 if (orig_spec && (spec != orig_spec))
1656 /* Update the original file spec */
1658 while ((*orig_spec++ = *p++));
1666 /**********************************************************************
1667 * DIALOG_DlgDirListW
1669 * Helper function for DlgDirList*W
1671 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1672 INT idStatic, UINT attrib, BOOL combo )
1676 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
1677 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
1679 MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
1680 HeapFree( GetProcessHeap(), 0, specA );
1683 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
1687 /**********************************************************************
1688 * DlgDirSelectExA (USER32.@)
1690 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
1692 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE );
1696 /**********************************************************************
1697 * DlgDirSelectExW (USER32.@)
1699 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
1701 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, FALSE );
1705 /**********************************************************************
1706 * DlgDirSelectComboBoxExA (USER32.@)
1708 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
1711 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, TRUE );
1715 /**********************************************************************
1716 * DlgDirSelectComboBoxExW (USER32.@)
1718 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
1721 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE );
1725 /**********************************************************************
1726 * DlgDirListA (USER32.@)
1728 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1729 INT idStatic, UINT attrib )
1731 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1735 /**********************************************************************
1736 * DlgDirListW (USER32.@)
1738 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1739 INT idStatic, UINT attrib )
1741 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1745 /**********************************************************************
1746 * DlgDirListComboBoxA (USER32.@)
1748 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
1749 INT idStatic, UINT attrib )
1751 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1755 /**********************************************************************
1756 * DlgDirListComboBoxW (USER32.@)
1758 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
1759 INT idStatic, UINT attrib )
1761 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );