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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
37 #include "wine/unicode.h"
40 #include "user_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
46 /* Dialog control information */
83 /* Radio button group */
92 /*********************************************************************
93 * dialog class descriptor
95 const struct builtin_class_descr DIALOG_builtin_class
=
97 (LPCWSTR
)DIALOG_CLASS_ATOM
, /* name */
98 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
99 WINPROC_DIALOG
, /* proc */
100 DLGWINDOWEXTRA
, /* extra */
101 IDC_ARROW
, /* cursor */
106 /***********************************************************************
109 * Helper function for modal dialogs to enable again the
110 * owner of the dialog box.
112 static void DIALOG_EnableOwner( HWND hOwner
)
114 /* Owner must be a top-level window */
116 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
118 EnableWindow( hOwner
, TRUE
);
122 /***********************************************************************
123 * DIALOG_DisableOwner
125 * Helper function for modal dialogs to disable the
126 * owner of the dialog box. Returns TRUE if owner was enabled.
128 static BOOL
DIALOG_DisableOwner( HWND hOwner
)
130 /* Owner must be a top-level window */
132 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
133 if (!hOwner
) return FALSE
;
134 if (IsWindowEnabled( hOwner
))
136 EnableWindow( hOwner
, FALSE
);
143 /***********************************************************************
144 * DIALOG_GetControl32
146 * Return the class and text of the control pointed to by ptr,
147 * fill the header structure and return a pointer to the next control.
149 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
154 info
->helpId
= GET_DWORD(p
); p
+= 2;
155 info
->exStyle
= GET_DWORD(p
); p
+= 2;
156 info
->style
= GET_DWORD(p
); p
+= 2;
161 info
->style
= GET_DWORD(p
); p
+= 2;
162 info
->exStyle
= GET_DWORD(p
); p
+= 2;
164 info
->x
= GET_WORD(p
); p
++;
165 info
->y
= GET_WORD(p
); p
++;
166 info
->cx
= GET_WORD(p
); p
++;
167 info
->cy
= GET_WORD(p
); p
++;
171 /* id is a DWORD for DIALOGEX */
172 info
->id
= GET_DWORD(p
);
177 info
->id
= GET_WORD(p
);
181 if (GET_WORD(p
) == 0xffff)
183 static const WCHAR class_names
[6][10] =
185 { 'B','u','t','t','o','n', }, /* 0x80 */
186 { 'E','d','i','t', }, /* 0x81 */
187 { 'S','t','a','t','i','c', }, /* 0x82 */
188 { 'L','i','s','t','B','o','x', }, /* 0x83 */
189 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
190 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
192 WORD id
= GET_WORD(p
+1);
193 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
194 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
196 info
->className
= class_names
[id
];
199 info
->className
= NULL
;
200 ERR("Unknown built-in class id %04x\n", id
);
207 p
+= strlenW( info
->className
) + 1;
210 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
212 info
->windowName
= MAKEINTRESOURCEW(GET_WORD(p
+ 1));
217 info
->windowName
= p
;
218 p
+= strlenW( info
->windowName
) + 1;
221 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
222 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
223 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
224 info
->style
, info
->exStyle
, info
->helpId
);
228 if (TRACE_ON(dialog
))
230 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
233 for (i
= 0; i
< count
; i
++) TRACE( "%04x,", GET_WORD(p
+i
+1) );
238 p
+= GET_WORD(p
) / sizeof(WORD
);
240 else info
->data
= NULL
;
243 /* Next control is on dword boundary */
244 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
248 /***********************************************************************
249 * DIALOG_CreateControls32
251 * Create the control windows for a dialog.
253 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
254 HINSTANCE hInst
, BOOL unicode
)
256 DIALOGINFO
*dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
257 DLG_CONTROL_INFO info
;
258 HWND hwndCtrl
, hwndDefButton
= 0;
259 INT items
= dlgTemplate
->nbItems
;
264 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
265 dlgTemplate
->dialogEx
);
266 info
.style
&= ~WS_POPUP
;
267 info
.style
|= WS_CHILD
;
269 if (info
.style
& WS_BORDER
)
271 info
.style
&= ~WS_BORDER
;
272 info
.exStyle
|= WS_EX_CLIENTEDGE
;
276 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
277 info
.className
, info
.windowName
,
278 info
.style
| WS_CHILD
,
279 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
280 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
281 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
282 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
283 hwnd
, (HMENU
)info
.id
,
284 hInst
, (LPVOID
)info
.data
);
288 LPCSTR
class = (LPCSTR
)info
.className
;
289 LPCSTR caption
= (LPCSTR
)info
.windowName
;
290 LPSTR class_tmp
= NULL
;
291 LPSTR caption_tmp
= NULL
;
293 if (!IS_INTRESOURCE(class))
295 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
296 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
297 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class_tmp
, len
, NULL
, NULL
);
300 if (!IS_INTRESOURCE(caption
))
302 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
303 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
304 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption_tmp
, len
, NULL
, NULL
);
305 caption
= caption_tmp
;
307 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
308 class, caption
, info
.style
| WS_CHILD
,
309 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
310 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
311 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
312 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
313 hwnd
, (HMENU
)info
.id
,
314 hInst
, (LPVOID
)info
.data
);
315 HeapFree( GetProcessHeap(), 0, class_tmp
);
316 HeapFree( GetProcessHeap(), 0, caption_tmp
);
320 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
321 debugstr_w(info
.windowName
));
322 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
326 /* Send initialisation messages to the control */
327 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
328 (WPARAM
)dlgInfo
->hUserFont
, 0 );
329 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
331 /* If there's already a default push-button, set it back */
332 /* to normal and use this one instead. */
334 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
335 hwndDefButton
= hwndCtrl
;
336 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
344 /***********************************************************************
345 * DIALOG_ParseTemplate32
347 * Fill a DLG_TEMPLATE structure from the dialog template, and return
348 * a pointer to the first control.
350 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
352 const WORD
*p
= (const WORD
*)template;
356 dlgver
= GET_WORD(p
); p
++;
357 signature
= GET_WORD(p
); p
++;
359 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
361 result
->dialogEx
= TRUE
;
362 result
->helpId
= GET_DWORD(p
); p
+= 2;
363 result
->exStyle
= GET_DWORD(p
); p
+= 2;
364 result
->style
= GET_DWORD(p
); p
+= 2;
368 result
->style
= GET_DWORD(p
- 2);
369 result
->dialogEx
= FALSE
;
371 result
->exStyle
= GET_DWORD(p
); p
+= 2;
373 result
->nbItems
= GET_WORD(p
); p
++;
374 result
->x
= GET_WORD(p
); p
++;
375 result
->y
= GET_WORD(p
); p
++;
376 result
->cx
= GET_WORD(p
); p
++;
377 result
->cy
= GET_WORD(p
); p
++;
378 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
379 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
380 result
->cx
, result
->cy
, result
->helpId
);
381 TRACE(" STYLE 0x%08x\n", result
->style
);
382 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
384 /* Get the menu name */
389 result
->menuName
= NULL
;
393 result
->menuName
= MAKEINTRESOURCEW(GET_WORD( p
+ 1 ));
395 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
398 result
->menuName
= p
;
399 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
400 p
+= strlenW( result
->menuName
) + 1;
404 /* Get the class name */
409 result
->className
= (LPCWSTR
)DIALOG_CLASS_ATOM
;
413 result
->className
= MAKEINTRESOURCEW(GET_WORD( p
+ 1 ));
415 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
418 result
->className
= p
;
419 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
420 p
+= strlenW( result
->className
) + 1;
424 /* Get the window caption */
427 p
+= strlenW( result
->caption
) + 1;
428 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
430 /* Get the font name */
432 result
->pointSize
= 0;
433 result
->faceName
= NULL
;
434 result
->weight
= FW_DONTCARE
;
435 result
->italic
= FALSE
;
437 if (result
->style
& DS_SETFONT
)
439 result
->pointSize
= GET_WORD(p
);
442 /* If pointSize is 0x7fff, it means that we need to use the font
443 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
444 * italic, and facename from the dialog template.
446 if (result
->pointSize
== 0x7fff)
448 /* We could call SystemParametersInfo here, but then we'd have
449 * to convert from pixel size to point size (which can be
452 TRACE(" FONT: Using message box font\n");
456 if (result
->dialogEx
)
458 result
->weight
= GET_WORD(p
); p
++;
459 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
461 result
->faceName
= p
;
462 p
+= strlenW( result
->faceName
) + 1;
464 TRACE(" FONT %d, %s, %d, %s\n",
465 result
->pointSize
, debugstr_w( result
->faceName
),
466 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
470 /* First control is on dword boundary */
471 return (LPCSTR
)(((UINT_PTR
)p
+ 3) & ~3);
475 /***********************************************************************
476 * DIALOG_CreateIndirect
477 * Creates a dialog box window
479 * modal = TRUE if we are called from a modal dialog box.
480 * (it's more compatible to do it here, as under Windows the owner
481 * is never disabled if the dialog fails because of an invalid template)
483 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
484 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
485 BOOL unicode
, BOOL modal
)
491 DLG_TEMPLATE
template;
492 DIALOGINFO
* dlgInfo
= NULL
;
493 DWORD units
= GetDialogBaseUnits();
494 BOOL ownerEnabled
= TRUE
;
498 UINT xBaseUnit
= LOWORD(units
);
499 UINT yBaseUnit
= HIWORD(units
);
501 /* Parse dialog template */
503 if (!dlgTemplate
) return 0;
504 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
508 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
510 /* Create custom font if needed */
512 if (template.style
& DS_SETFONT
)
516 if (template.pointSize
== 0x7fff)
518 /* We get the message font from the non-client metrics */
519 NONCLIENTMETRICSW ncMetrics
;
521 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
522 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
523 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
525 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
530 /* We convert the size to pixels and then make it -ve. This works
531 * for both +ve and -ve template.pointSize */
532 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
533 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
534 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
535 PROOF_QUALITY
, FF_DONTCARE
,
542 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
543 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
546 xBaseUnit
= charSize
.cx
;
547 yBaseUnit
= charSize
.cy
;
549 SelectObject( dc
, hOldFont
);
552 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
555 /* Create dialog main window */
557 rect
.left
= rect
.top
= 0;
558 rect
.right
= MulDiv(template.cx
, xBaseUnit
, 4);
559 rect
.bottom
= MulDiv(template.cy
, yBaseUnit
, 8);
560 if (template.style
& WS_CHILD
)
561 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
562 if (template.style
& DS_MODALFRAME
)
563 template.exStyle
|= WS_EX_DLGMODALFRAME
;
564 if (template.style
& DS_CONTROL
)
565 template.exStyle
|= WS_EX_CONTROLPARENT
;
566 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
569 size
.cx
= rect
.right
- rect
.left
;
570 size
.cy
= rect
.bottom
- rect
.top
;
572 if (template.x
== (SHORT
)0x8000 /*CW_USEDEFAULT16*/)
574 pos
.x
= pos
.y
= CW_USEDEFAULT
;
578 HMONITOR monitor
= 0;
579 MONITORINFO mon_info
;
581 mon_info
.cbSize
= sizeof(mon_info
);
582 if (template.style
& DS_CENTER
)
584 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
585 GetMonitorInfoW( monitor
, &mon_info
);
586 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
587 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
589 else if (template.style
& DS_CENTERMOUSE
)
591 GetCursorPos( &pos
);
592 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
593 GetMonitorInfoW( monitor
, &mon_info
);
597 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
598 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
599 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
))) ClientToScreen( owner
, &pos
);
601 if ( !(template.style
& WS_CHILD
) )
605 /* try to fit it into the desktop */
609 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
610 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
611 GetMonitorInfoW( monitor
, &mon_info
);
613 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
615 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
617 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
618 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
624 ownerEnabled
= DIALOG_DisableOwner( owner
);
625 if (ownerEnabled
) flags
|= DF_OWNERENABLED
;
630 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
631 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
632 owner
, hMenu
, hInst
, NULL
);
636 LPCSTR
class = (LPCSTR
)template.className
;
637 LPCSTR caption
= (LPCSTR
)template.caption
;
638 LPSTR class_tmp
= NULL
;
639 LPSTR caption_tmp
= NULL
;
641 if (!IS_INTRESOURCE(class))
643 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
644 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
645 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
648 if (!IS_INTRESOURCE(caption
))
650 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
651 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
652 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
653 caption
= caption_tmp
;
655 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
656 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
657 owner
, hMenu
, hInst
, NULL
);
658 HeapFree( GetProcessHeap(), 0, class_tmp
);
659 HeapFree( GetProcessHeap(), 0, caption_tmp
);
664 if (hUserFont
) DeleteObject( hUserFont
);
665 if (hMenu
) DestroyMenu( hMenu
);
666 if (modal
&& (flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
670 /* moved this from the top of the method to here as DIALOGINFO structure
671 will be valid only after WM_CREATE message has been handled in DefDlgProc
672 All the members of the structure get filled here using temp variables */
673 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
674 dlgInfo
->hwndFocus
= 0;
675 dlgInfo
->hUserFont
= hUserFont
;
676 dlgInfo
->hMenu
= hMenu
;
677 dlgInfo
->xBaseUnit
= xBaseUnit
;
678 dlgInfo
->yBaseUnit
= yBaseUnit
;
679 dlgInfo
->flags
= flags
;
681 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
683 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
684 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
686 if (dlgProc
&& dlgInfo
->hUserFont
)
687 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
689 /* Create controls */
691 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
693 /* Send initialisation messages and set focus */
697 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
698 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
699 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
701 /* By returning TRUE, app has requested a default focus assignment.
702 * WM_INITDIALOG may have changed the tab order, so find the first
703 * tabstop control again. */
704 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
705 if( dlgInfo
->hwndFocus
)
706 SetFocus( dlgInfo
->hwndFocus
);
710 if (template.style
& WS_VISIBLE
&& !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
712 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
716 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
717 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
722 /***********************************************************************
723 * CreateDialogParamA (USER32.@)
725 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
, HWND owner
,
726 DLGPROC dlgProc
, LPARAM param
)
731 if (!(hrsrc
= FindResourceA( hInst
, name
, (LPSTR
)RT_DIALOG
))) return 0;
732 if (!(ptr
= LoadResource(hInst
, hrsrc
))) return 0;
733 return CreateDialogIndirectParamA( hInst
, ptr
, owner
, dlgProc
, param
);
737 /***********************************************************************
738 * CreateDialogParamW (USER32.@)
740 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
, HWND owner
,
741 DLGPROC dlgProc
, LPARAM param
)
746 if (!(hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
))) return 0;
747 if (!(ptr
= LoadResource(hInst
, hrsrc
))) return 0;
748 return CreateDialogIndirectParamW( hInst
, ptr
, owner
, dlgProc
, param
);
752 /***********************************************************************
753 * CreateDialogIndirectParamAorW (USER32.@)
755 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
, LPCVOID dlgTemplate
,
756 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
759 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, !flags
, FALSE
);
762 /***********************************************************************
763 * CreateDialogIndirectParamA (USER32.@)
765 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
, LPCDLGTEMPLATEA dlgTemplate
,
766 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
768 return CreateDialogIndirectParamAorW( hInst
, dlgTemplate
, owner
, dlgProc
, param
, 2 );
771 /***********************************************************************
772 * CreateDialogIndirectParamW (USER32.@)
774 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
, LPCDLGTEMPLATEW dlgTemplate
,
775 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
777 return CreateDialogIndirectParamAorW( hInst
, dlgTemplate
, owner
, dlgProc
, param
, 0 );
781 /***********************************************************************
784 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
786 DIALOGINFO
* dlgInfo
;
789 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
792 if (!(dlgInfo
= DIALOG_get_info( hwnd
, FALSE
))) return -1;
795 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
799 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
803 /* ShowWindow the first time the queue goes empty */
804 ShowWindow( hwnd
, SW_SHOWNORMAL
);
807 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
809 /* No message present -> send ENTERIDLE and wait */
810 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
812 GetMessageW( &msg
, 0, 0, 0 );
815 if (msg
.message
== WM_QUIT
)
817 PostQuitMessage( msg
.wParam
);
818 if (!IsWindow( hwnd
)) return 0;
821 if (!IsWindow( hwnd
)) return 0;
822 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
824 TranslateMessage( &msg
);
825 DispatchMessageW( &msg
);
827 if (!IsWindow( hwnd
)) return 0;
828 if (dlgInfo
->flags
& DF_END
) break;
830 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
832 ShowWindow( hwnd
, SW_SHOWNORMAL
);
837 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
838 retval
= dlgInfo
->idResult
;
839 DestroyWindow( hwnd
);
844 /***********************************************************************
845 * DialogBoxParamA (USER32.@)
847 INT_PTR WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
848 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
854 if (!(hrsrc
= FindResourceA( hInst
, name
, (LPSTR
)RT_DIALOG
))) return -1;
855 if (!(ptr
= LoadResource(hInst
, hrsrc
))) return -1;
856 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, dlgProc
, param
, FALSE
, TRUE
);
857 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
862 /***********************************************************************
863 * DialogBoxParamW (USER32.@)
865 INT_PTR WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
866 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
872 if (!(hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
))) return -1;
873 if (!(ptr
= LoadResource(hInst
, hrsrc
))) return -1;
874 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, dlgProc
, param
, TRUE
, TRUE
);
875 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
880 /***********************************************************************
881 * DialogBoxIndirectParamAorW (USER32.@)
883 INT_PTR WINAPI
DialogBoxIndirectParamAorW( HINSTANCE hInstance
, LPCVOID
template,
884 HWND owner
, DLGPROC dlgProc
,
885 LPARAM param
, DWORD flags
)
887 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
, dlgProc
, param
, !flags
, TRUE
);
888 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
892 /***********************************************************************
893 * DialogBoxIndirectParamA (USER32.@)
895 INT_PTR WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCDLGTEMPLATEA
template,
896 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
898 return DialogBoxIndirectParamAorW( hInstance
, template, owner
, dlgProc
, param
, 2 );
902 /***********************************************************************
903 * DialogBoxIndirectParamW (USER32.@)
905 INT_PTR WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCDLGTEMPLATEW
template,
906 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
908 return DialogBoxIndirectParamAorW( hInstance
, template, owner
, dlgProc
, param
, 0 );
911 /***********************************************************************
912 * EndDialog (USER32.@)
914 BOOL WINAPI
EndDialog( HWND hwnd
, INT_PTR retval
)
916 BOOL wasEnabled
= TRUE
;
917 DIALOGINFO
* dlgInfo
;
920 TRACE("%p %ld\n", hwnd
, retval
);
922 if (!(dlgInfo
= DIALOG_get_info( hwnd
, FALSE
)))
924 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
927 dlgInfo
->idResult
= retval
;
928 dlgInfo
->flags
|= DF_END
;
929 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
931 owner
= GetWindow( hwnd
, GW_OWNER
);
932 if (wasEnabled
&& owner
)
933 DIALOG_EnableOwner( owner
);
935 /* Windows sets the focus to the dialog itself in EndDialog */
937 if (IsChild(hwnd
, GetFocus()))
940 /* Don't have to send a ShowWindow(SW_HIDE), just do
941 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
943 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
944 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
946 if (hwnd
== GetActiveWindow())
948 /* If this dialog was given an owner then set the focus to that owner
949 even when the owner is disabled (normally when a window closes any
950 disabled windows cannot receive the focus). */
952 SetForegroundWindow( owner
);
954 WINPOS_ActivateOtherWindow( hwnd
);
957 /* unblock dialog loop */
958 PostMessageA(hwnd
, WM_NULL
, 0, 0);
963 /***********************************************************************
964 * DIALOG_IsAccelerator
966 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
968 HWND hwndControl
= hwnd
;
975 DWORD style
= GetWindowLongW( hwndControl
, GWL_STYLE
);
976 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
978 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
979 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
980 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
982 /* find the accelerator key */
983 LPWSTR p
= buffer
- 2;
987 p
= strchrW( p
+ 2, '&' );
989 while (p
!= NULL
&& p
[1] == '&');
991 /* and check if it's the one we're looking for */
992 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
994 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
996 /* set focus to the control */
997 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
998 /* and bump it on to next */
999 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
1001 else if (dlgCode
& DLGC_BUTTON
)
1003 /* send BM_CLICK message to the control */
1004 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
1009 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
1013 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1015 while (!hwndNext
&& hwndControl
)
1017 hwndControl
= GetParent( hwndControl
);
1018 if (hwndControl
== hwndDlg
)
1020 if(hwnd
==hwndDlg
) /* prevent endless loop */
1025 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
1028 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1030 hwndControl
= hwndNext
;
1032 while (hwndControl
&& (hwndControl
!= hwnd
));
1037 /***********************************************************************
1038 * DIALOG_FindMsgDestination
1040 * The messages that IsDialogMessage sends may not go to the dialog
1041 * calling IsDialogMessage if that dialog is a child, and it has the
1042 * DS_CONTROL style set.
1043 * We propagate up until we hit one that does not have DS_CONTROL, or
1044 * whose parent is not a dialog.
1046 * This is undocumented behaviour.
1048 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
1050 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
1053 HWND hParent
= GetParent(hwndDlg
);
1054 if (!hParent
) break;
1056 pParent
= WIN_GetPtr(hParent
);
1057 if (!pParent
|| pParent
== WND_OTHER_PROCESS
|| pParent
== WND_DESKTOP
) break;
1059 if (!pParent
->dlgInfo
)
1061 WIN_ReleasePtr(pParent
);
1064 WIN_ReleasePtr(pParent
);
1072 /***********************************************************************
1073 * DIALOG_FixOneChildOnChangeFocus
1075 * Callback helper for DIALOG_FixChildrenOnChangeFocus
1078 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
1081 /* If a default pushbutton then no longer default */
1082 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
1083 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1087 /***********************************************************************
1088 * DIALOG_FixChildrenOnChangeFocus
1090 * Following the change of focus that occurs for example after handling
1091 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
1092 * children may be required.
1094 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
1096 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
1097 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
1098 /* Windows does ask for this. I don't know why yet */
1100 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
1102 /* If the button that is getting the focus WAS flagged as the default
1103 * pushbutton then ask the dialog what it thinks the default is and
1104 * set that in the default style.
1106 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
1108 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
1109 if (HIWORD(def_id
) == DC_HASDEFID
)
1112 def_id
= LOWORD(def_id
);
1113 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
1116 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
1117 /* I know that if it is a button then it should already be a
1118 * UNDEFPUSHBUTTON, since we have just told the buttons to
1119 * change style. But maybe they ignored our request
1121 if ((dlgcode_def
& DLGC_BUTTON
) &&
1122 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
1124 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1129 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
1131 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1132 /* I wonder why it doesn't send a DM_SETDEFID */
1136 /***********************************************************************
1139 * A recursive version of GetDlgItem
1142 * The HWND for a Child ID.
1144 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
1147 HWND
*list
= WIN_ListChildren( hwndDlg
);
1150 if (!list
) return 0;
1152 for (i
= 0; list
[i
]; i
++)
1154 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
1160 /* Recurse into every child */
1161 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
1164 HeapFree( GetProcessHeap(), 0, list
);
1168 /***********************************************************************
1169 * IsDialogMessageW (USER32.@)
1171 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1175 if (CallMsgFilterW( msg
, MSGF_DIALOGBOX
)) return TRUE
;
1177 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1178 if (is_desktop_window(hwndDlg
)) return FALSE
;
1179 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
)) return FALSE
;
1181 hwndDlg
= DIALOG_FindMsgDestination(hwndDlg
);
1183 switch(msg
->message
)
1186 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1187 if (dlgCode
& (DLGC_WANTMESSAGE
)) break;
1192 if (!(dlgCode
& DLGC_WANTTAB
))
1194 BOOL fIsDialog
= TRUE
;
1195 WND
*pWnd
= WIN_GetPtr( hwndDlg
);
1197 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1199 fIsDialog
= (pWnd
->dlgInfo
!= NULL
);
1200 WIN_ReleasePtr(pWnd
);
1203 /* I am not sure under which circumstances the TAB is handled
1204 * each way. All I do know is that it does not always simply
1205 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
1206 * do so but I presume someone has)
1209 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1212 /* It would appear that GetNextDlgTabItem can handle being
1213 * passed hwndDlg rather than NULL but that is undocumented
1214 * so let's do it properly
1216 HWND hwndFocus
= GetFocus();
1217 HWND hwndNext
= GetNextDlgTabItem (hwndDlg
,
1218 hwndFocus
== hwndDlg
? NULL
: hwndFocus
,
1219 GetKeyState (VK_SHIFT
) & 0x8000);
1222 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
1223 msg
->wParam
, (LPARAM
)msg
);
1224 if (dlgCode
& DLGC_HASSETSEL
)
1226 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
1227 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
1231 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
1232 length
= strlenW (buffer
);
1233 HeapFree (GetProcessHeap(), 0, buffer
);
1234 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
1237 SetFocus (hwndNext
);
1238 DIALOG_FixChildrenOnChangeFocus (hwndDlg
, hwndNext
);
1251 if (!(dlgCode
& DLGC_WANTARROWS
))
1253 BOOL fPrevious
= (msg
->wParam
== VK_LEFT
|| msg
->wParam
== VK_UP
);
1254 HWND hwndNext
= GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1255 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
1262 SendMessageW( hwndDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1269 if ((GetFocus() == msg
->hwnd
) &&
1270 (SendMessageW (msg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1272 SendMessageW (hwndDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(msg
->hwnd
),BN_CLICKED
), (LPARAM
)msg
->hwnd
);
1274 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0)))
1276 HWND hwndDef
= DIALOG_IdToHwnd(hwndDlg
, LOWORD(dw
));
1277 if (hwndDef
? IsWindowEnabled(hwndDef
) : LOWORD(dw
)==IDOK
)
1278 SendMessageW( hwndDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
1282 SendMessageW( hwndDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1291 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
1292 * It does NOT get sent in the test program I have
1294 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1295 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
1296 if (msg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
1300 if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg
->hwnd
), hwndDlg
, msg
->wParam
))
1302 /* don't translate or dispatch */
1308 TranslateMessage( msg
);
1309 DispatchMessageW( msg
);
1314 /***********************************************************************
1315 * GetDlgCtrlID (USER32.@)
1317 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1319 return GetWindowLongPtrW( hwnd
, GWLP_ID
);
1323 /***********************************************************************
1324 * GetDlgItem (USER32.@)
1326 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1329 HWND
*list
= WIN_ListChildren( hwndDlg
);
1332 if (!list
) return 0;
1334 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
) break;
1336 HeapFree( GetProcessHeap(), 0, list
);
1341 /*******************************************************************
1342 * SendDlgItemMessageA (USER32.@)
1344 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1345 WPARAM wParam
, LPARAM lParam
)
1347 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1348 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1353 /*******************************************************************
1354 * SendDlgItemMessageW (USER32.@)
1356 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1357 WPARAM wParam
, LPARAM lParam
)
1359 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1360 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1365 /*******************************************************************
1366 * SetDlgItemTextA (USER32.@)
1368 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1370 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1374 /*******************************************************************
1375 * SetDlgItemTextW (USER32.@)
1377 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1379 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1383 /***********************************************************************
1384 * GetDlgItemTextA (USER32.@)
1386 UINT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, INT len
)
1388 if (str
&& (len
> 0)) str
[0] = '\0';
1389 return (UINT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1394 /***********************************************************************
1395 * GetDlgItemTextW (USER32.@)
1397 UINT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, INT len
)
1399 if (str
&& (len
> 0)) str
[0] = '\0';
1400 return (UINT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1405 /*******************************************************************
1406 * SetDlgItemInt (USER32.@)
1408 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1413 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1414 else sprintf( str
, "%u", value
);
1415 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1420 /***********************************************************************
1421 * GetDlgItemInt (USER32.@)
1423 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1428 LONG_PTR result
= 0;
1430 if (translated
) *translated
= FALSE
;
1431 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1435 result
= strtol( str
, &endptr
, 10 );
1436 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1438 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1443 result
= strtoul( str
, &endptr
, 10 );
1444 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1446 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1448 if (translated
) *translated
= TRUE
;
1449 return (UINT
)result
;
1453 /***********************************************************************
1454 * CheckDlgButton (USER32.@)
1456 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1458 SendDlgItemMessageW( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1463 /***********************************************************************
1464 * IsDlgButtonChecked (USER32.@)
1466 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, int id
)
1468 return (UINT
)SendDlgItemMessageW( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1472 /***********************************************************************
1475 * Callback function used to check/uncheck radio buttons that fall
1476 * within a specific range of IDs.
1478 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1480 LONG lChildID
= GetWindowLongPtrW(hwndChild
, GWLP_ID
);
1481 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1483 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1484 (lChildID
<= lpRadioGroup
->lastID
))
1486 if (lChildID
== lpRadioGroup
->checkID
)
1488 SendMessageW(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1492 SendMessageW(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1500 /***********************************************************************
1501 * CheckRadioButton (USER32.@)
1503 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, int firstID
,
1504 int lastID
, int checkID
)
1506 RADIOGROUP radioGroup
;
1508 radioGroup
.firstID
= firstID
;
1509 radioGroup
.lastID
= lastID
;
1510 radioGroup
.checkID
= checkID
;
1512 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1513 (LPARAM
)&radioGroup
);
1517 /***********************************************************************
1518 * GetDialogBaseUnits (USER.243)
1519 * GetDialogBaseUnits (USER32.@)
1521 DWORD WINAPI
GetDialogBaseUnits(void)
1530 if ((hdc
= GetDC(0)))
1532 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
1533 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
1534 ReleaseDC( 0, hdc
);
1536 TRACE("base units = %d,%d\n", LOWORD(units
), HIWORD(units
) );
1542 /***********************************************************************
1543 * MapDialogRect (USER32.@)
1545 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1547 DIALOGINFO
* dlgInfo
;
1548 if (!(dlgInfo
= DIALOG_get_info( hwnd
, FALSE
))) return FALSE
;
1549 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1550 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1551 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1552 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1557 /***********************************************************************
1558 * GetNextDlgGroupItem (USER32.@)
1560 * Corrections to MSDN documentation
1562 * (Under Windows 2000 at least, where hwndDlg is not actually a dialog)
1563 * 1. hwndCtrl can be hwndDlg in which case it behaves as for NULL
1564 * 2. Prev of NULL or hwndDlg fails
1566 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1568 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
1570 BOOL fSkipping
=FALSE
;
1572 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1573 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1575 if (hwndDlg
== hwndCtrl
) hwndCtrl
= NULL
;
1576 if (!hwndCtrl
&& fPrevious
) return 0;
1580 if (!IsChild (hwndDlg
, hwndCtrl
)) return 0;
1584 /* No ctrl specified -> start from the beginning */
1585 if (!(hwndCtrl
= GetWindow( hwndDlg
, GW_CHILD
))) return 0;
1586 /* MSDN is wrong. fPrevious does not result in the last child */
1588 /* Maybe that first one is valid. If so then we don't want to skip it*/
1589 if ((GetWindowLongW( hwndCtrl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
1595 /* Always go forward around the group and list of controls; for the
1596 * previous control keep track; for the next break when you find one
1598 retvalue
= hwndCtrl
;
1600 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
1605 /* Climb out until there is a next sibling of the ancestor or we
1606 * reach the top (in which case we loop back to the start)
1608 if (hwndDlg
== GetParent (hwnd
))
1610 /* Wrap around to the beginning of the list, within the same
1611 * group. (Once only)
1613 if (fLooped
) goto end
;
1615 hwndNext
= GetWindow (hwndDlg
, GW_CHILD
);
1619 hwnd
= GetParent (hwnd
);
1620 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
1625 /* Wander down the leading edge of controlparents */
1626 while ( (GetWindowLongW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
1627 ((GetWindowLongW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
1628 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
1630 /* Question. If the control is a control parent but either has no
1631 * children or is not visible/enabled then if it has a WS_GROUP does
1632 * it count? For that matter does it count anyway?
1633 * I believe it doesn't count.
1636 if ((GetWindowLongW (hwnd
, GWL_STYLE
) & WS_GROUP
))
1638 hwndLastGroup
= hwnd
;
1641 /* Look for the beginning of the group */
1646 if (hwnd
== hwndCtrl
)
1648 if (!fSkipping
) break;
1649 if (hwndLastGroup
== hwnd
) break;
1650 hwnd
= hwndLastGroup
;
1656 (GetWindowLongW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
1660 if (!fPrevious
) break;
1668 /***********************************************************************
1669 * DIALOG_GetNextTabItem
1671 * Recursive helper for GetNextDlgTabItem
1673 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1677 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1679 HWND hChildFirst
= 0;
1683 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1684 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1686 else if (IsChild( hwndMain
, hwndCtrl
))
1688 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1691 if(GetParent(hwndCtrl
) != hwndMain
)
1692 /* i.e. if we are not at the top level of the recursion */
1693 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1695 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1701 dsStyle
= GetWindowLongA(hChildFirst
,GWL_STYLE
);
1702 exStyle
= GetWindowLongA(hChildFirst
,GWL_EXSTYLE
);
1703 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1706 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1707 if (retWnd
) return (retWnd
);
1709 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1711 return (hChildFirst
);
1713 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1717 HWND hParent
= GetParent(hwndCtrl
);
1720 if(hParent
== hwndMain
) break;
1721 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1723 hParent
= GetParent(hParent
);
1726 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1728 return retWnd
? retWnd
: hwndCtrl
;
1731 /***********************************************************************
1732 * GetNextDlgTabItem (USER32.@)
1734 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1737 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1738 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1740 /* Undocumented but tested under Win2000 and WinME */
1741 if (hwndDlg
== hwndCtrl
) hwndCtrl
= NULL
;
1743 /* Contrary to MSDN documentation, tested under Win2000 and WinME
1744 * NB GetLastError returns whatever was set before the function was
1747 if (!hwndCtrl
&& fPrevious
) return 0;
1749 return DIALOG_GetNextTabItem(hwndDlg
,hwndDlg
,hwndCtrl
,fPrevious
);
1752 /**********************************************************************
1753 * DIALOG_DlgDirSelect
1755 * Helper function for DlgDirSelect*
1757 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1758 INT id
, BOOL unicode
, BOOL combo
)
1760 WCHAR
*buffer
, *ptr
;
1763 HWND listbox
= GetDlgItem( hwnd
, id
);
1765 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1766 if (!listbox
) return FALSE
;
1768 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1769 if (item
== LB_ERR
) return FALSE
;
1771 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1772 if (size
== LB_ERR
) return FALSE
;
1774 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1776 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1778 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1780 if (buffer
[1] == '-') /* drive */
1788 buffer
[strlenW(buffer
)-1] = '\\';
1794 /* Filenames without a dot extension must have one tacked at the end */
1795 if (strchrW(buffer
, '.') == NULL
)
1797 buffer
[strlenW(buffer
)+1] = '\0';
1798 buffer
[strlenW(buffer
)] = '.';
1805 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1806 ((LPSTR
)str
)[len
-1] = 0;
1808 else lstrcpynW( str
, ptr
, len
);
1809 HeapFree( GetProcessHeap(), 0, buffer
);
1810 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1815 /**********************************************************************
1816 * DIALOG_DlgDirListW
1818 * Helper function for DlgDirList*W
1820 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1821 INT idStatic
, UINT attrib
, BOOL combo
)
1824 LPWSTR orig_spec
= spec
;
1825 WCHAR any
[] = {'*','.','*',0};
1827 #define SENDMSG(msg,wparam,lparam) \
1828 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1829 : SendMessageW( hwnd, msg, wparam, lparam ))
1831 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1833 /* If the path exists and is a directory, chdir to it */
1834 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1839 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1840 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1841 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1846 if (!SetCurrentDirectoryW( spec
))
1848 *p
= sep
; /* Restore the original spec */
1855 TRACE( "mask=%s\n", debugstr_w(spec
) );
1857 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1859 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1861 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1862 if (attrib
& DDL_DIRECTORY
)
1864 if (!(attrib
& DDL_EXCLUSIVE
))
1866 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1867 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1870 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1871 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1876 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1880 /* Convert path specification to uppercase */
1881 if (spec
) CharUpperW(spec
);
1883 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1885 WCHAR temp
[MAX_PATH
];
1886 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1888 /* Can't use PostMessage() here, because the string is on the stack */
1889 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1892 if (orig_spec
&& (spec
!= orig_spec
))
1894 /* Update the original file spec */
1896 while ((*orig_spec
++ = *p
++));
1904 /**********************************************************************
1905 * DIALOG_DlgDirListA
1907 * Helper function for DlgDirList*A
1909 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1910 INT idStatic
, UINT attrib
, BOOL combo
)
1914 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1915 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1916 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1917 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1918 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1919 HeapFree( GetProcessHeap(), 0, specW
);
1922 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1926 /**********************************************************************
1927 * DlgDirSelectExA (USER32.@)
1929 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
1931 return DIALOG_DlgDirSelect( hwnd
, (LPWSTR
)str
, len
, id
, FALSE
, FALSE
);
1935 /**********************************************************************
1936 * DlgDirSelectExW (USER32.@)
1938 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
1940 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
);
1944 /**********************************************************************
1945 * DlgDirSelectComboBoxExA (USER32.@)
1947 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
1950 return DIALOG_DlgDirSelect( hwnd
, (LPWSTR
)str
, len
, id
, FALSE
, TRUE
);
1954 /**********************************************************************
1955 * DlgDirSelectComboBoxExW (USER32.@)
1957 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
1960 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, TRUE
);
1964 /**********************************************************************
1965 * DlgDirListA (USER32.@)
1967 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1968 INT idStatic
, UINT attrib
)
1970 return DIALOG_DlgDirListA( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1974 /**********************************************************************
1975 * DlgDirListW (USER32.@)
1977 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1978 INT idStatic
, UINT attrib
)
1980 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1984 /**********************************************************************
1985 * DlgDirListComboBoxA (USER32.@)
1987 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
1988 INT idStatic
, UINT attrib
)
1990 return DIALOG_DlgDirListA( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
1994 /**********************************************************************
1995 * DlgDirListComboBoxW (USER32.@)
1997 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
1998 INT idStatic
, UINT attrib
)
2000 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);