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"
37 #include "wine/winuser16.h"
38 #include "wine/winbase16.h"
40 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
50 /* Dialog control information */
87 /* Radio button group */
95 /* Dialog base units */
96 static WORD xBaseUnit
= 0, yBaseUnit
= 0;
99 /*********************************************************************
100 * dialog class descriptor
102 const struct builtin_class_descr DIALOG_builtin_class
=
104 DIALOG_CLASS_ATOM
, /* name */
105 CS_GLOBALCLASS
| CS_SAVEBITS
, /* style */
106 DefDlgProcA
, /* procA */
107 DefDlgProcW
, /* procW */
108 DLGWINDOWEXTRA
, /* extra */
109 IDC_ARROWA
, /* cursor */
114 /***********************************************************************
117 * Helper function for modal dialogs to enable again the
118 * owner of the dialog box.
120 void DIALOG_EnableOwner( HWND hOwner
)
122 /* Owner must be a top-level window */
124 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
126 EnableWindow( hOwner
, TRUE
);
130 /***********************************************************************
131 * DIALOG_DisableOwner
133 * Helper function for modal dialogs to disable the
134 * owner of the dialog box. Returns TRUE if owner was enabled.
136 BOOL
DIALOG_DisableOwner( HWND hOwner
)
138 /* Owner must be a top-level window */
140 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
141 if (!hOwner
) return FALSE
;
142 if (IsWindowEnabled( hOwner
))
144 EnableWindow( hOwner
, FALSE
);
151 /***********************************************************************
152 * DIALOG_GetCharSizeFromDC
154 * Despite most of MSDN insisting that the horizontal base unit is
155 * tmAveCharWidth it isn't. Knowledge base article Q145994
156 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
157 * says that we should take the average of the 52 English upper and lower
160 static BOOL
DIALOG_GetCharSizeFromDC( HDC hDC
, HFONT hFont
, SIZE
* pSize
)
163 char *alphabet
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
167 pSize
->cx
= xBaseUnit
;
168 pSize
->cy
= yBaseUnit
;
170 if(!hDC
) return FALSE
;
172 if(hFont
) hFontPrev
= SelectFont(hDC
, hFont
);
173 if(!GetTextMetricsA(hDC
, &tm
)) return FALSE
;
174 if(!GetTextExtentPointA(hDC
, alphabet
, 52, &sz
)) return FALSE
;
176 pSize
->cy
= tm
.tmHeight
;
177 pSize
->cx
= (sz
.cx
/ 26 + 1) / 2;
179 if (hFontPrev
) SelectFont(hDC
, hFontPrev
);
181 TRACE("dlg base units: %ld x %ld\n", pSize
->cx
, pSize
->cy
);
185 /***********************************************************************
188 * A convenient variant of DIALOG_GetCharSizeFromDC.
190 static BOOL
DIALOG_GetCharSize( HFONT hFont
, SIZE
* pSize
)
193 BOOL Success
= DIALOG_GetCharSizeFromDC( hDC
, hFont
, pSize
);
198 /***********************************************************************
201 * Initialisation of the dialog manager.
203 BOOL
DIALOG_Init(void)
208 /* Calculate the dialog base units */
210 if (!(hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
)))
212 ERR("Could not create Display DC\n");
216 if (!DIALOG_GetCharSizeFromDC( hdc
, 0, &size
))
219 ERR("Could not initialize base dialog units\n");
227 TRACE("base units = %d,%d\n", xBaseUnit
, yBaseUnit
);
232 /***********************************************************************
233 * DIALOG_GetControl16
235 * Return the class and text of the control pointed to by ptr,
236 * fill the header structure and return a pointer to the next control.
238 static LPCSTR
DIALOG_GetControl16( LPCSTR p
, DLG_CONTROL_INFO
*info
)
240 static char buffer
[10];
243 info
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
244 info
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
245 info
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
246 info
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
247 info
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
248 info
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
255 case 0x80: strcpy( buffer
, "BUTTON" ); break;
256 case 0x81: strcpy( buffer
, "EDIT" ); break;
257 case 0x82: strcpy( buffer
, "STATIC" ); break;
258 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
259 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
260 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
261 default: buffer
[0] = '\0'; break;
263 info
->className
= buffer
;
272 int_id
= ((BYTE
)*p
== 0xff);
275 /* Integer id, not documented (?). Only works for SS_ICON controls */
276 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+1);
281 info
->windowName
= p
;
285 if (*p
) info
->data
= p
+ 1;
286 else info
->data
= NULL
;
291 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %p\n",
292 info
->className
, LOWORD(info
->windowName
),
293 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
294 info
->style
, info
->data
);
296 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %p\n",
297 info
->className
, info
->windowName
,
298 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
299 info
->style
, info
->data
);
305 /***********************************************************************
306 * DIALOG_GetControl32
308 * Return the class and text of the control pointed to by ptr,
309 * fill the header structure and return a pointer to the next control.
311 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
316 info
->helpId
= GET_DWORD(p
); p
+= 2;
317 info
->exStyle
= GET_DWORD(p
); p
+= 2;
318 info
->style
= GET_DWORD(p
); p
+= 2;
323 info
->style
= GET_DWORD(p
); p
+= 2;
324 info
->exStyle
= GET_DWORD(p
); p
+= 2;
326 info
->x
= GET_WORD(p
); p
++;
327 info
->y
= GET_WORD(p
); p
++;
328 info
->cx
= GET_WORD(p
); p
++;
329 info
->cy
= GET_WORD(p
); p
++;
333 /* id is a DWORD for DIALOGEX */
334 info
->id
= GET_DWORD(p
);
339 info
->id
= GET_WORD(p
);
343 if (GET_WORD(p
) == 0xffff)
345 static const WCHAR class_names
[6][10] =
347 { 'B','u','t','t','o','n', }, /* 0x80 */
348 { 'E','d','i','t', }, /* 0x81 */
349 { 'S','t','a','t','i','c', }, /* 0x82 */
350 { 'L','i','s','t','B','o','x', }, /* 0x83 */
351 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
352 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
354 WORD id
= GET_WORD(p
+1);
355 if ((id
>= 0x80) && (id
<= 0x85))
356 info
->className
= (LPCSTR
)class_names
[id
- 0x80];
359 info
->className
= NULL
;
360 ERR("Unknown built-in class id %04x\n", id
);
366 info
->className
= (LPCSTR
)p
;
367 p
+= strlenW( (LPCWSTR
)p
) + 1;
370 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
372 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+ 1);
377 info
->windowName
= (LPCSTR
)p
;
378 p
+= strlenW( (LPCWSTR
)p
) + 1;
381 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
382 debugstr_w( (LPCWSTR
)info
->className
),
383 debugstr_w( (LPCWSTR
)info
->windowName
),
384 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
385 info
->style
, info
->exStyle
, info
->helpId
);
389 if (TRACE_ON(dialog
))
391 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
394 for (i
= 0; i
< count
; i
++) DPRINTF( "%04x,", GET_WORD(p
+i
+1) );
399 p
+= GET_WORD(p
) / sizeof(WORD
);
401 else info
->data
= NULL
;
404 /* Next control is on dword boundary */
405 return (const WORD
*)((((int)p
) + 3) & ~3);
409 /***********************************************************************
410 * DIALOG_CreateControls
412 * Create the control windows for a dialog.
414 static BOOL
DIALOG_CreateControls( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
415 HINSTANCE hInst
, BOOL win32
)
417 DIALOGINFO
*dlgInfo
= DIALOG_get_info( hwnd
);
418 DLG_CONTROL_INFO info
;
419 HWND hwndCtrl
, hwndDefButton
= 0;
420 INT items
= dlgTemplate
->nbItems
;
427 HINSTANCE16 instance
;
430 template = DIALOG_GetControl16( template, &info
);
431 if (HIWORD(info
.className
) && !strcmp( info
.className
, "EDIT") &&
432 !(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_LOCALEDIT
))
434 if (!dlgInfo
->hDialogHeap
)
436 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
437 if (!dlgInfo
->hDialogHeap
)
439 ERR("Insufficient memory to create heap for edit control\n" );
442 LocalInit16(dlgInfo
->hDialogHeap
, 0, 0xffff);
444 instance
= dlgInfo
->hDialogHeap
;
446 else instance
= (HINSTANCE16
)hInst
;
448 segptr
= MapLS( info
.data
);
449 hwndCtrl
= WIN_Handle32( CreateWindowEx16( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
450 info
.className
, info
.windowName
,
451 info
.style
| WS_CHILD
,
452 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
453 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
454 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
455 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
456 HWND_16(hwnd
), (HMENU16
)info
.id
,
457 instance
, (LPVOID
)segptr
));
462 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
463 dlgTemplate
->dialogEx
);
465 if (info
.style
& WS_BORDER
)
467 info
.style
&= ~WS_BORDER
;
468 info
.exStyle
|= WS_EX_CLIENTEDGE
;
470 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
471 (LPCWSTR
)info
.className
,
472 (LPCWSTR
)info
.windowName
,
473 info
.style
| WS_CHILD
,
474 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
475 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
476 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
477 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
478 hwnd
, (HMENU
)info
.id
,
479 hInst
, (LPVOID
)info
.data
);
481 if (!hwndCtrl
) return FALSE
;
483 /* Send initialisation messages to the control */
484 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
485 (WPARAM
)dlgInfo
->hUserFont
, 0 );
486 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
488 /* If there's already a default push-button, set it back */
489 /* to normal and use this one instead. */
491 SendMessageA( hwndDefButton
, BM_SETSTYLE
,
492 BS_PUSHBUTTON
,FALSE
);
493 hwndDefButton
= hwndCtrl
;
494 dlgInfo
->idResult
= GetWindowLongA( hwndCtrl
, GWL_ID
);
502 /***********************************************************************
503 * DIALOG_ParseTemplate16
505 * Fill a DLG_TEMPLATE structure from the dialog template, and return
506 * a pointer to the first control.
508 static LPCSTR
DIALOG_ParseTemplate16( LPCSTR p
, DLG_TEMPLATE
* result
)
510 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
512 result
->nbItems
= (unsigned char) *p
++;
513 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
514 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
515 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
516 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
517 TRACE("DIALOG %d, %d, %d, %d\n",
518 result
->x
, result
->y
, result
->cx
, result
->cy
);
519 TRACE(" STYLE %08lx\n", result
->style
);
521 /* Get the menu name */
526 result
->menuName
= 0;
530 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
532 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
535 result
->menuName
= p
;
536 TRACE(" MENU '%s'\n", p
);
541 /* Get the class name */
545 result
->className
= p
;
546 TRACE(" CLASS '%s'\n", result
->className
);
548 else result
->className
= DIALOG_CLASS_ATOM
;
551 /* Get the window caption */
555 TRACE(" CAPTION '%s'\n", result
->caption
);
557 /* Get the font name */
559 if (result
->style
& DS_SETFONT
)
561 result
->pointSize
= GET_WORD(p
);
563 result
->faceName
= p
;
565 TRACE(" FONT %d,'%s'\n",
566 result
->pointSize
, result
->faceName
);
572 /***********************************************************************
573 * DIALOG_ParseTemplate32
575 * Fill a DLG_TEMPLATE structure from the dialog template, and return
576 * a pointer to the first control.
578 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
580 const WORD
*p
= (const WORD
*)template;
582 result
->style
= GET_DWORD(p
); p
+= 2;
583 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
585 result
->dialogEx
= TRUE
;
586 result
->helpId
= GET_DWORD(p
); p
+= 2;
587 result
->exStyle
= GET_DWORD(p
); p
+= 2;
588 result
->style
= GET_DWORD(p
); p
+= 2;
592 result
->dialogEx
= FALSE
;
594 result
->exStyle
= GET_DWORD(p
); p
+= 2;
596 result
->nbItems
= GET_WORD(p
); p
++;
597 result
->x
= GET_WORD(p
); p
++;
598 result
->y
= GET_WORD(p
); p
++;
599 result
->cx
= GET_WORD(p
); p
++;
600 result
->cy
= GET_WORD(p
); p
++;
601 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
602 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
603 result
->cx
, result
->cy
, result
->helpId
);
604 TRACE(" STYLE 0x%08lx\n", result
->style
);
605 TRACE(" EXSTYLE 0x%08lx\n", result
->exStyle
);
607 /* Get the menu name */
612 result
->menuName
= NULL
;
616 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
618 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
621 result
->menuName
= (LPCSTR
)p
;
622 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR
)p
));
623 p
+= strlenW( (LPCWSTR
)p
) + 1;
627 /* Get the class name */
632 result
->className
= DIALOG_CLASS_ATOM
;
636 result
->className
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
638 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
641 result
->className
= (LPCSTR
)p
;
642 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR
)p
));
643 p
+= strlenW( (LPCWSTR
)p
) + 1;
647 /* Get the window caption */
649 result
->caption
= (LPCSTR
)p
;
650 p
+= strlenW( (LPCWSTR
)p
) + 1;
651 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR
)result
->caption
) );
653 /* Get the font name */
655 if (result
->style
& DS_SETFONT
)
657 result
->pointSize
= GET_WORD(p
);
659 if (result
->dialogEx
)
661 result
->weight
= GET_WORD(p
); p
++;
662 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
666 result
->weight
= FW_DONTCARE
;
667 result
->italic
= FALSE
;
669 result
->faceName
= (LPCSTR
)p
;
670 p
+= strlenW( (LPCWSTR
)p
) + 1;
671 TRACE(" FONT %d, %s, %d, %s\n",
672 result
->pointSize
, debugstr_w( (LPCWSTR
)result
->faceName
),
673 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
676 /* First control is on dword boundary */
677 return (LPCSTR
)((((int)p
) + 3) & ~3);
681 /***********************************************************************
682 * DIALOG_CreateIndirect
683 * Creates a dialog box window
685 * modal = TRUE if we are called from a modal dialog box.
686 * (it's more compatible to do it here, as under Windows the owner
687 * is never disabled if the dialog fails because of an invalid template)
689 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCSTR dlgTemplate
,
690 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
691 WINDOWPROCTYPE procType
, BOOL modal
)
696 DLG_TEMPLATE
template;
697 DIALOGINFO
* dlgInfo
;
698 BOOL ownerEnabled
= TRUE
;
699 BOOL win32Template
= (procType
!= WIN_PROC_16
);
701 /* Parse dialog template */
703 if (!dlgTemplate
) return 0;
705 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
707 dlgTemplate
= DIALOG_ParseTemplate16( dlgTemplate
, &template );
709 /* Initialise dialog extra data */
711 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo
) ))) return 0;
712 dlgInfo
->hwndFocus
= 0;
713 dlgInfo
->hUserFont
= 0;
715 dlgInfo
->xBaseUnit
= xBaseUnit
;
716 dlgInfo
->yBaseUnit
= yBaseUnit
;
717 dlgInfo
->idResult
= 0;
719 dlgInfo
->hDialogHeap
= 0;
723 if (template.menuName
)
725 if (!win32Template
) dlgInfo
->hMenu
= LoadMenu16( hInst
, template.menuName
);
726 else dlgInfo
->hMenu
= LoadMenuW( hInst
, (LPCWSTR
)template.menuName
);
729 /* Create custom font if needed */
731 if (template.style
& DS_SETFONT
)
733 /* We convert the size to pixels and then make it -ve. This works
734 * for both +ve and -ve template.pointSize */
738 pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
741 dlgInfo
->hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
742 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
743 PROOF_QUALITY
, FF_DONTCARE
,
744 (LPCWSTR
)template.faceName
);
746 dlgInfo
->hUserFont
= CreateFontA( -pixels
, 0, 0, 0, FW_DONTCARE
,
747 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
748 PROOF_QUALITY
, FF_DONTCARE
, template.faceName
);
749 if (dlgInfo
->hUserFont
)
752 if (DIALOG_GetCharSize( dlgInfo
->hUserFont
, &charSize
))
754 dlgInfo
->xBaseUnit
= charSize
.cx
;
755 dlgInfo
->yBaseUnit
= charSize
.cy
;
758 TRACE("units = %d,%d\n", dlgInfo
->xBaseUnit
, dlgInfo
->yBaseUnit
);
761 /* Create dialog main window */
763 rect
.left
= rect
.top
= 0;
764 rect
.right
= MulDiv(template.cx
, dlgInfo
->xBaseUnit
, 4);
765 rect
.bottom
= MulDiv(template.cy
, dlgInfo
->yBaseUnit
, 8);
766 if (template.style
& DS_MODALFRAME
)
767 template.exStyle
|= WS_EX_DLGMODALFRAME
;
768 AdjustWindowRectEx( &rect
, template.style
, (dlgInfo
->hMenu
!= 0), template.exStyle
);
769 rect
.right
-= rect
.left
;
770 rect
.bottom
-= rect
.top
;
772 if ((INT16
)template.x
== CW_USEDEFAULT16
)
774 rect
.left
= rect
.top
= win32Template
? CW_USEDEFAULT
: CW_USEDEFAULT16
;
778 if (template.style
& DS_CENTER
)
780 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
781 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
785 rect
.left
+= MulDiv(template.x
, dlgInfo
->xBaseUnit
, 4);
786 rect
.top
+= MulDiv(template.y
, dlgInfo
->yBaseUnit
, 8);
788 if ( !(template.style
& WS_CHILD
) )
792 if( !(template.style
& DS_ABSALIGN
) )
793 ClientToScreen( owner
, (POINT
*)&rect
);
795 /* try to fit it into the desktop */
797 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
798 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
799 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
800 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
801 if( rect
.left
< 0 ) rect
.left
= 0;
802 if( rect
.top
< 0 ) rect
.top
= 0;
808 ownerEnabled
= DIALOG_DisableOwner( owner
);
809 if (ownerEnabled
) dlgInfo
->flags
|= DF_OWNERENABLED
;
813 hwnd
= WIN_Handle32( CreateWindowEx16(template.exStyle
, template.className
,
814 template.caption
, template.style
& ~WS_VISIBLE
,
815 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
816 HWND_16(owner
), dlgInfo
->hMenu
, hInst
, NULL
));
818 hwnd
= CreateWindowExW(template.exStyle
, (LPCWSTR
)template.className
,
819 (LPCWSTR
)template.caption
,
820 template.style
& ~WS_VISIBLE
,
821 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
822 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
826 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
827 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
828 if (modal
&& (dlgInfo
->flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
829 HeapFree( GetProcessHeap(), 0, dlgInfo
);
832 wndPtr
= WIN_GetPtr( hwnd
);
833 wndPtr
->flags
|= WIN_ISDIALOG
;
834 WIN_ReleasePtr( wndPtr
);
836 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
837 SetWindowLongW( hwnd
, DWL_WINE_DIALOGINFO
, (LONG
)dlgInfo
);
840 case WIN_PROC_16
: SetWindowLong16( HWND_16(hwnd
), DWL_DLGPROC
, (LONG
)dlgProc
); break;
841 case WIN_PROC_32A
: SetWindowLongA( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
); break;
842 case WIN_PROC_32W
: SetWindowLongW( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
); break;
846 if (dlgInfo
->hUserFont
)
847 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
849 /* Create controls */
851 if (DIALOG_CreateControls( hwnd
, dlgTemplate
, &template,
852 hInst
, win32Template
))
854 HWND hwndPreInitFocus
;
856 /* Send initialisation messages and set focus */
858 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
860 hwndPreInitFocus
= GetFocus();
861 if (SendMessageA( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
863 /* check where the focus is again,
864 * some controls status might have changed in WM_INITDIALOG */
865 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
866 if( dlgInfo
->hwndFocus
)
867 SetFocus( dlgInfo
->hwndFocus
);
871 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
872 but the focus has not changed, set the focus where we expect it. */
873 if ((GetFocus() == hwndPreInitFocus
) &&
874 (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
876 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
877 if( dlgInfo
->hwndFocus
)
878 SetFocus( dlgInfo
->hwndFocus
);
882 if (template.style
& WS_VISIBLE
&& !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
884 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
888 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
889 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
894 /***********************************************************************
895 * CreateDialog (USER.89)
897 HWND16 WINAPI
CreateDialog16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
898 HWND16 owner
, DLGPROC16 dlgProc
)
900 return CreateDialogParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
904 /***********************************************************************
905 * CreateDialogParam (USER.241)
907 HWND16 WINAPI
CreateDialogParam16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
908 HWND16 owner
, DLGPROC16 dlgProc
,
916 TRACE("%04x,%s,%04x,%08lx,%ld\n",
917 hInst
, debugstr_a(dlgTemplate
), owner
, (DWORD
)dlgProc
, param
);
919 if (!(hRsrc
= FindResource16( hInst
, dlgTemplate
, RT_DIALOGA
))) return 0;
920 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
921 if (!(data
= LockResource16( hmem
))) hwnd
= 0;
922 else hwnd
= CreateDialogIndirectParam16( hInst
, data
, owner
,
924 FreeResource16( hmem
);
928 /***********************************************************************
929 * CreateDialogParamA (USER32.@)
931 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
,
932 HWND owner
, DLGPROC dlgProc
,
935 HRSRC hrsrc
= FindResourceA( hInst
, name
, RT_DIALOGA
);
936 if (!hrsrc
) return 0;
937 return CreateDialogIndirectParamA( hInst
,
938 (LPVOID
)LoadResource(hInst
, hrsrc
),
939 owner
, dlgProc
, param
);
943 /***********************************************************************
944 * CreateDialogParamW (USER32.@)
946 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
,
947 HWND owner
, DLGPROC dlgProc
,
950 HRSRC hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
951 if (!hrsrc
) return 0;
952 return CreateDialogIndirectParamW( hInst
,
953 (LPVOID
)LoadResource(hInst
, hrsrc
),
954 owner
, dlgProc
, param
);
958 /***********************************************************************
959 * CreateDialogIndirect (USER.219)
961 HWND16 WINAPI
CreateDialogIndirect16( HINSTANCE16 hInst
, LPCVOID dlgTemplate
,
962 HWND16 owner
, DLGPROC16 dlgProc
)
964 return CreateDialogIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0);
968 /***********************************************************************
969 * CreateDialogIndirectParam (USER.242)
971 HWND16 WINAPI
CreateDialogIndirectParam16( HINSTANCE16 hInst
,
973 HWND16 owner
, DLGPROC16 dlgProc
,
976 return HWND_16( DIALOG_CreateIndirect( hInst
, dlgTemplate
, WIN_Handle32(owner
),
977 (DLGPROC
)dlgProc
, param
, WIN_PROC_16
, FALSE
));
981 /***********************************************************************
982 * CreateDialogIndirectParamA (USER32.@)
984 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
,
986 HWND owner
, DLGPROC dlgProc
,
989 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32A
, FALSE
);
992 /***********************************************************************
993 * CreateDialogIndirectParamAorW (USER32.@)
995 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
,
997 HWND owner
, DLGPROC dlgProc
,
999 { FIXME("assume WIN_PROC_32W\n");
1000 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32W
, FALSE
);
1003 /***********************************************************************
1004 * CreateDialogIndirectParamW (USER32.@)
1006 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
,
1007 LPCVOID dlgTemplate
,
1008 HWND owner
, DLGPROC dlgProc
,
1011 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32W
, FALSE
);
1015 /***********************************************************************
1016 * DIALOG_DoDialogBox
1018 static INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
1020 DIALOGINFO
* dlgInfo
;
1023 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
1025 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return -1;
1027 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
1029 ShowWindow( hwnd
, SW_SHOW
);
1032 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
1034 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
1036 /* No message present -> send ENTERIDLE and wait */
1037 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
1038 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1041 else if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1043 if (!IsWindow( hwnd
)) return -1;
1044 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
1046 TranslateMessage( &msg
);
1047 DispatchMessageW( &msg
);
1049 if (dlgInfo
->flags
& DF_END
) break;
1052 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
1053 retval
= dlgInfo
->idResult
;
1054 DestroyWindow( hwnd
);
1059 /***********************************************************************
1060 * DialogBox (USER.87)
1062 INT16 WINAPI
DialogBox16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
1063 HWND16 owner
, DLGPROC16 dlgProc
)
1065 return DialogBoxParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1069 /***********************************************************************
1070 * DialogBoxParam (USER.239)
1072 INT16 WINAPI
DialogBoxParam16( HINSTANCE16 hInst
, LPCSTR
template,
1073 HWND16 owner16
, DLGPROC16 dlgProc
, LPARAM param
)
1081 if (!(hRsrc
= FindResource16( hInst
, template, RT_DIALOGA
))) return 0;
1082 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
1083 if ((data
= LockResource16( hmem
)))
1085 HWND owner
= WIN_Handle32(owner16
);
1086 hwnd
= DIALOG_CreateIndirect( hInst
, data
, owner
,
1087 (DLGPROC
)dlgProc
, param
, WIN_PROC_16
, TRUE
);
1088 if (hwnd
) ret
= DIALOG_DoDialogBox( hwnd
, owner
);
1089 GlobalUnlock16( hmem
);
1091 FreeResource16( hmem
);
1096 /***********************************************************************
1097 * DialogBoxParamA (USER32.@)
1099 INT WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
1100 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
1103 HRSRC hrsrc
= FindResourceA( hInst
, name
, RT_DIALOGA
);
1104 if (!hrsrc
) return 0;
1105 hwnd
= DIALOG_CreateIndirect( hInst
, (LPVOID
)LoadResource(hInst
, hrsrc
),
1106 owner
, dlgProc
, param
, WIN_PROC_32A
, TRUE
);
1107 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1112 /***********************************************************************
1113 * DialogBoxParamW (USER32.@)
1115 INT WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
1116 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
1119 HRSRC hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
1120 if (!hrsrc
) return 0;
1121 hwnd
= DIALOG_CreateIndirect( hInst
, (LPVOID
)LoadResource(hInst
, hrsrc
),
1122 owner
, dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1123 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1128 /***********************************************************************
1129 * DialogBoxIndirect (USER.218)
1131 INT16 WINAPI
DialogBoxIndirect16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1132 HWND16 owner
, DLGPROC16 dlgProc
)
1134 return DialogBoxIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1138 /***********************************************************************
1139 * DialogBoxIndirectParam (USER.240)
1141 INT16 WINAPI
DialogBoxIndirectParam16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1142 HWND16 owner16
, DLGPROC16 dlgProc
,
1145 HWND hwnd
, owner
= WIN_Handle32( owner16
);
1148 if (!(ptr
= GlobalLock16( dlgTemplate
))) return -1;
1149 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, (DLGPROC
)dlgProc
,
1150 param
, WIN_PROC_16
, TRUE
);
1151 GlobalUnlock16( dlgTemplate
);
1152 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1157 /***********************************************************************
1158 * DialogBoxIndirectParamA (USER32.@)
1160 INT WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCVOID
template,
1161 HWND owner
, DLGPROC dlgProc
,
1164 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
,
1165 dlgProc
, param
, WIN_PROC_32A
, TRUE
);
1166 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1171 /***********************************************************************
1172 * DialogBoxIndirectParamW (USER32.@)
1174 INT WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCVOID
template,
1175 HWND owner
, DLGPROC dlgProc
,
1178 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
,
1179 dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1180 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1184 /***********************************************************************
1185 * DialogBoxIndirectParamAorW (USER32.@)
1187 INT WINAPI
DialogBoxIndirectParamAorW(HINSTANCE hInstance
, LPCVOID
template,
1188 HWND owner
, DLGPROC dlgProc
,
1189 LPARAM param
, DWORD x
)
1192 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1193 hInstance
, template, owner
, dlgProc
, param
, x
);
1194 hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
, dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1195 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1199 /***********************************************************************
1200 * EndDialog (USER32.@)
1202 BOOL WINAPI
EndDialog( HWND hwnd
, INT retval
)
1204 BOOL wasEnabled
= TRUE
;
1205 DIALOGINFO
* dlgInfo
;
1208 TRACE("%04x %d\n", hwnd
, retval
);
1210 if (!(dlgInfo
= DIALOG_get_info( hwnd
)))
1212 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd
);
1215 dlgInfo
->idResult
= retval
;
1216 dlgInfo
->flags
|= DF_END
;
1217 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
1219 if (wasEnabled
&& (owner
= GetWindow( hwnd
, GW_OWNER
)))
1220 DIALOG_EnableOwner( owner
);
1222 /* Windows sets the focus to the dialog itself in EndDialog */
1224 if (IsChild(hwnd
, GetFocus()))
1227 /* Don't have to send a ShowWindow(SW_HIDE), just do
1228 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1230 SetWindowPos(hwnd
, (HWND
)0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
1231 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1233 /* unblock dialog loop */
1234 PostMessageA(hwnd
, WM_NULL
, 0, 0);
1239 /***********************************************************************
1240 * DIALOG_IsAccelerator
1242 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
1244 HWND hwndControl
= hwnd
;
1251 DWORD style
= GetWindowLongW( hwndControl
, GWL_STYLE
);
1252 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
1254 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1255 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
1256 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1258 /* find the accelerator key */
1259 LPWSTR p
= buffer
- 2;
1263 p
= strchrW( p
+ 2, '&' );
1265 while (p
!= NULL
&& p
[1] == '&');
1267 /* and check if it's the one we're looking for */
1268 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
1270 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
1272 /* set focus to the control */
1273 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
1274 /* and bump it on to next */
1275 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
1277 else if (dlgCode
& DLGC_BUTTON
)
1279 /* send BM_CLICK message to the control */
1280 SendMessageA( hwndControl
, BM_CLICK
, 0, 0 );
1285 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
1289 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1291 while (!hwndNext
&& hwndControl
)
1293 hwndControl
= GetParent( hwndControl
);
1294 if (hwndControl
== hwndDlg
)
1296 if(hwnd
==hwndDlg
) /* prevent endless loop */
1301 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
1304 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1306 hwndControl
= hwndNext
;
1308 while (hwndControl
&& (hwndControl
!= hwnd
));
1313 /***********************************************************************
1314 * DIALOG_FindMsgDestination
1316 * The messages that IsDialogMessage sends may not go to the dialog
1317 * calling IsDialogMessage if that dialog is a child, and it has the
1318 * DS_CONTROL style set.
1319 * We propagate up until we hit one that does not have DS_CONTROL, or
1320 * whose parent is not a dialog.
1322 * This is undocumented behaviour.
1324 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
1326 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
1329 HWND hParent
= GetParent(hwndDlg
);
1330 if (!hParent
) break;
1332 pParent
= WIN_FindWndPtr(hParent
);
1333 if (!pParent
) break;
1335 if (!(pParent
->flags
& WIN_ISDIALOG
))
1337 WIN_ReleaseWndPtr(pParent
);
1340 WIN_ReleaseWndPtr(pParent
);
1348 /***********************************************************************
1349 * IsDialogMessageW (USER32.@)
1351 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1355 if (CallMsgFilterW( msg
, MSGF_DIALOGBOX
)) return TRUE
;
1357 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1358 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
)) return FALSE
;
1360 hwndDlg
= DIALOG_FindMsgDestination(hwndDlg
);
1362 switch(msg
->message
)
1365 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1366 if (dlgCode
& DLGC_WANTMESSAGE
) break;
1371 if (!(dlgCode
& DLGC_WANTTAB
))
1373 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1382 if (!(dlgCode
& DLGC_WANTARROWS
))
1384 BOOL fPrevious
= (msg
->wParam
== VK_LEFT
|| msg
->wParam
== VK_UP
);
1385 HWND hwndNext
= GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1386 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
1393 SendMessageW( hwndDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1399 DWORD dw
= SendMessageW( hwndDlg
, DM_GETDEFID
, 0, 0 );
1400 if (HIWORD(dw
) == DC_HASDEFID
)
1402 SendMessageW( hwndDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1403 (LPARAM
)GetDlgItem(hwndDlg
, LOWORD(dw
)));
1407 SendMessageW( hwndDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1416 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1417 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
1418 if (msg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
1422 if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg
->hwnd
), hwndDlg
, msg
->wParam
))
1424 /* don't translate or dispatch */
1430 TranslateMessage( msg
);
1431 DispatchMessageW( msg
);
1436 /***********************************************************************
1437 * GetDlgCtrlID (USER32.@)
1439 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1441 return GetWindowLongW( hwnd
, GWL_ID
);
1445 /***********************************************************************
1446 * GetDlgItem (USER32.@)
1448 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1451 HWND
*list
= WIN_ListChildren( hwndDlg
);
1454 if (!list
) return 0;
1456 for (i
= 0; list
[i
]; i
++) if (GetWindowLongW( list
[i
], GWL_ID
) == id
) break;
1458 HeapFree( GetProcessHeap(), 0, list
);
1463 /*******************************************************************
1464 * SendDlgItemMessageA (USER32.@)
1466 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1467 WPARAM wParam
, LPARAM lParam
)
1469 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1470 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1475 /*******************************************************************
1476 * SendDlgItemMessageW (USER32.@)
1478 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1479 WPARAM wParam
, LPARAM lParam
)
1481 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1482 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1487 /*******************************************************************
1488 * SetDlgItemTextA (USER32.@)
1490 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1492 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1496 /*******************************************************************
1497 * SetDlgItemTextW (USER32.@)
1499 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1501 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1505 /***********************************************************************
1506 * GetDlgItemTextA (USER32.@)
1508 INT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, UINT len
)
1510 return (INT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1515 /***********************************************************************
1516 * GetDlgItemTextW (USER32.@)
1518 INT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, UINT len
)
1520 return (INT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1525 /*******************************************************************
1526 * SetDlgItemInt (USER32.@)
1528 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1533 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1534 else sprintf( str
, "%u", value
);
1535 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1540 /***********************************************************************
1541 * GetDlgItemInt (USER32.@)
1543 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1550 if (translated
) *translated
= FALSE
;
1551 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1555 result
= strtol( str
, &endptr
, 10 );
1556 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1558 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1563 result
= strtoul( str
, &endptr
, 10 );
1564 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1566 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1568 if (translated
) *translated
= TRUE
;
1569 return (UINT
)result
;
1573 /***********************************************************************
1574 * CheckDlgButton (USER32.@)
1576 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1578 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1583 /***********************************************************************
1584 * IsDlgButtonChecked (USER32.@)
1586 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, UINT id
)
1588 return (UINT
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1592 /***********************************************************************
1595 * Callback function used to check/uncheck radio buttons that fall
1596 * within a specific range of IDs.
1598 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1600 LONG lChildID
= GetWindowLongA(hwndChild
, GWL_ID
);
1601 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1603 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1604 (lChildID
<= lpRadioGroup
->lastID
))
1606 if (lChildID
== lpRadioGroup
->checkID
)
1608 SendMessageA(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1612 SendMessageA(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1620 /***********************************************************************
1621 * CheckRadioButton (USER32.@)
1623 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, UINT firstID
,
1624 UINT lastID
, UINT checkID
)
1626 RADIOGROUP radioGroup
;
1628 /* perform bounds checking for a radio button group */
1629 radioGroup
.firstID
= min(min(firstID
, lastID
), checkID
);
1630 radioGroup
.lastID
= max(max(firstID
, lastID
), checkID
);
1631 radioGroup
.checkID
= checkID
;
1633 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1634 (LPARAM
)&radioGroup
);
1638 /***********************************************************************
1639 * GetDialogBaseUnits (USER.243)
1640 * GetDialogBaseUnits (USER32.@)
1642 DWORD WINAPI
GetDialogBaseUnits(void)
1644 return MAKELONG( xBaseUnit
, yBaseUnit
);
1648 /***********************************************************************
1649 * MapDialogRect (USER32.@)
1651 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1653 DIALOGINFO
* dlgInfo
;
1654 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return FALSE
;
1655 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1656 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1657 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1658 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1663 /***********************************************************************
1664 * GetNextDlgGroupItem (USER32.@)
1666 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1668 HWND hwnd
, retvalue
;
1670 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1671 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1675 /* if the hwndCtrl is the child of the control in the hwndDlg,
1676 * then the hwndDlg has to be the parent of the hwndCtrl */
1677 if(GetParent(hwndCtrl
) != hwndDlg
&& GetParent(GetParent(hwndCtrl
)) == hwndDlg
)
1678 hwndDlg
= GetParent(hwndCtrl
);
1683 /* Make sure hwndCtrl is a top-level child */
1684 HWND parent
= GetParent( hwndCtrl
);
1685 while (parent
&& parent
!= hwndDlg
) parent
= GetParent(parent
);
1686 if (parent
!= hwndDlg
) return 0;
1690 /* No ctrl specified -> start from the beginning */
1691 if (!(hwndCtrl
= GetWindow( hwndDlg
, GW_CHILD
))) return 0;
1692 if (fPrevious
) hwndCtrl
= GetWindow( hwndCtrl
, GW_HWNDLAST
);
1695 retvalue
= hwndCtrl
;
1696 hwnd
= GetWindow( hwndCtrl
, GW_HWNDNEXT
);
1699 if (!hwnd
|| (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_GROUP
))
1701 /* Wrap-around to the beginning of the group */
1704 hwnd
= GetWindow( hwndDlg
, GW_CHILD
);
1705 for (tmp
= hwnd
; tmp
; tmp
= GetWindow( tmp
, GW_HWNDNEXT
) )
1707 if (GetWindowLongW( tmp
, GWL_STYLE
) & WS_GROUP
) hwnd
= tmp
;
1708 if (tmp
== hwndCtrl
) break;
1711 if (hwnd
== hwndCtrl
) break;
1712 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
1715 if (!fPrevious
) break;
1717 hwnd
= GetWindow( hwnd
, GW_HWNDNEXT
);
1723 /***********************************************************************
1724 * DIALOG_GetNextTabItem
1726 * Helper for GetNextDlgTabItem
1728 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1732 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1734 HWND hChildFirst
= 0;
1738 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1739 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1741 else if (IsChild( hwndMain
, hwndCtrl
))
1743 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1746 if(GetParent(hwndCtrl
) != hwndMain
)
1747 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1751 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDLAST
);
1753 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDFIRST
);
1763 dsStyle
= GetWindowLongA(hChildFirst
,GWL_STYLE
);
1764 exStyle
= GetWindowLongA(hChildFirst
,GWL_EXSTYLE
);
1765 if( (dsStyle
& DS_CONTROL
|| exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1770 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1772 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1777 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,(HWND
)NULL
,fPrevious
);
1779 retWnd
= hChildFirst
;
1782 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1784 if(!retWnd
&& hwndCtrl
)
1786 HWND hParent
= GetParent(hwndCtrl
);
1789 if(hParent
== hwndMain
) break;
1790 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1792 hParent
= GetParent(hParent
);
1795 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,(HWND
)NULL
,fPrevious
);
1800 /***********************************************************************
1801 * GetNextDlgTabItem (USER32.@)
1803 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1806 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1807 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1808 return DIALOG_GetNextTabItem(hwndDlg
,hwndDlg
,hwndCtrl
,fPrevious
);
1811 /**********************************************************************
1812 * DIALOG_DlgDirSelect
1814 * Helper function for DlgDirSelect*
1816 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1817 INT id
, BOOL unicode
, BOOL combo
)
1822 HWND listbox
= GetDlgItem( hwnd
, id
);
1824 TRACE("%04x '%s' %d\n", hwnd
, str
, id
);
1825 if (!listbox
) return FALSE
;
1827 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1828 if (item
== LB_ERR
) return FALSE
;
1829 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, 0, 0 );
1830 if (size
== LB_ERR
) return FALSE
;
1832 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
+1 ))) return FALSE
;
1834 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1836 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1838 if (buffer
[1] == '-') /* drive */
1846 buffer
[strlen(buffer
)-1] = '\\';
1854 if (len
> 0 && !MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, (LPWSTR
)str
, len
))
1855 ((LPWSTR
)str
)[len
-1] = 0;
1857 else lstrcpynA( str
, ptr
, len
);
1858 HeapFree( GetProcessHeap(), 0, buffer
);
1859 TRACE("Returning %d '%s'\n", ret
, str
);
1864 /**********************************************************************
1867 * Helper function for DlgDirList*
1869 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
1870 INT idStatic
, UINT attrib
, BOOL combo
)
1873 LPSTR orig_spec
= spec
;
1875 #define SENDMSG(msg,wparam,lparam) \
1876 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1877 : SendMessageA( hwnd, msg, wparam, lparam ))
1879 TRACE("%04x '%s' %d %d %04x\n",
1880 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
1882 /* If the path exists and is a directory, chdir to it */
1883 if (!spec
|| !spec
[0] || SetCurrentDirectoryA( spec
)) spec
= "*.*";
1888 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
1889 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
1894 if (!SetCurrentDirectoryA( spec
))
1896 *p
= sep
; /* Restore the original spec */
1903 TRACE( "mask=%s\n", spec
);
1905 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1907 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1908 if (attrib
& DDL_DIRECTORY
)
1910 if (!(attrib
& DDL_EXCLUSIVE
))
1912 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1913 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1914 (LPARAM
)spec
) == LB_ERR
)
1917 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1918 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1919 (LPARAM
)"*.*" ) == LB_ERR
)
1924 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
1925 (LPARAM
)spec
) == LB_ERR
)
1930 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1932 char temp
[MAX_PATH
];
1933 GetCurrentDirectoryA( sizeof(temp
), temp
);
1935 /* Can't use PostMessage() here, because the string is on the stack */
1936 SetDlgItemTextA( hDlg
, idStatic
, temp
);
1939 if (orig_spec
&& (spec
!= orig_spec
))
1941 /* Update the original file spec */
1943 while ((*orig_spec
++ = *p
++));
1951 /**********************************************************************
1952 * DIALOG_DlgDirListW
1954 * Helper function for DlgDirList*W
1956 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1957 INT idStatic
, UINT attrib
, BOOL combo
)
1961 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
1962 INT ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
1964 MultiByteToWideChar( CP_ACP
, 0, specA
, -1, spec
, 0x7fffffff );
1965 HeapFree( GetProcessHeap(), 0, specA
);
1968 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1972 /**********************************************************************
1973 * DlgDirSelectExA (USER32.@)
1975 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
1977 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
);
1981 /**********************************************************************
1982 * DlgDirSelectExW (USER32.@)
1984 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
1986 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, FALSE
);
1990 /**********************************************************************
1991 * DlgDirSelectComboBoxExA (USER32.@)
1993 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
1996 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, TRUE
);
2000 /**********************************************************************
2001 * DlgDirSelectComboBoxExW (USER32.@)
2003 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
2006 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
);
2010 /**********************************************************************
2011 * DlgDirListA (USER32.@)
2013 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
2014 INT idStatic
, UINT attrib
)
2016 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2020 /**********************************************************************
2021 * DlgDirListW (USER32.@)
2023 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2024 INT idStatic
, UINT attrib
)
2026 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2030 /**********************************************************************
2031 * DlgDirListComboBoxA (USER32.@)
2033 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
2034 INT idStatic
, UINT attrib
)
2036 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2040 /**********************************************************************
2041 * DlgDirListComboBoxW (USER32.@)
2043 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
2044 INT idStatic
, UINT attrib
)
2046 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);