3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/dialog.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
26 * Steven Edwards (Steven_Ed4153@yahoo.com)
28 * 07-26-2003 Code ported from wine
29 * 09-05-2001 CSH Created
32 /* INCLUDES ******************************************************************/
38 /* MACROS/DEFINITIONS ********************************************************/
41 #define DF_OWNERENABLED 0x0002
42 #define CW_USEDEFAULT16 ((short)0x8000)
44 #define GETDLGINFO(hwnd) (DIALOGINFO*)GetWindowLongW((hwnd), DWL_INIT)
45 #define SETDLGINFO(hwnd, info) SetWindowLongW((hwnd), DWL_INIT, (LONG)(info))
46 #define GET_WORD(ptr) (*(WORD *)(ptr))
47 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
48 #define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom))))
49 #define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom))))
50 #define DIALOG_CLASS_ATOMA MAKEINTATOMA(32770) /* Dialog */
51 #define DIALOG_CLASS_ATOMW MAKEINTATOMW(32770) /* Dialog */
53 /* INTERNAL STRUCTS **********************************************************/
55 /* Dialog info structure */
58 HWND hwndFocus
; /* Current control with focus */
59 HFONT hUserFont
; /* Dialog font */
60 HMENU hMenu
; /* Dialog menu */
61 UINT xBaseUnit
; /* Dialog units (depends on the font) */
63 INT idResult
; /* EndDialog() result / default pushbutton ID */
64 UINT flags
; /* EndDialog() called for this dialog */
67 /* Dialog control information */
105 /* GetDlgItem structure */
112 /* CheckRadioButton structure */
121 /*********************************************************************
122 * dialog class descriptor
124 const struct builtin_class_descr DIALOG_builtin_class
=
126 DIALOG_CLASS_ATOMW
, /* name */
127 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
128 (WNDPROC
) DefDlgProcW
, /* procW */
129 (WNDPROC
) DefDlgProcA
, /* procA */
130 DWL_INIT
+ sizeof(LONG
), /* extra */
131 (LPCWSTR
) IDC_ARROW
, /* cursor */
136 /* INTERNAL FUNCTIONS ********************************************************/
138 /***********************************************************************
141 * Despite most of MSDN insisting that the horizontal base unit is
142 * tmAveCharWidth it isn't. Knowledge base article Q145994
143 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
144 * says that we should take the average of the 52 English upper and lower
147 BOOL
DIALOG_GetCharSize( HDC hDC
, HFONT hFont
, SIZE
* pSize
)
150 char *alphabet
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
154 if(!hDC
) return FALSE
;
156 if(hFont
) hFontPrev
= SelectObject(hDC
, hFont
);
157 if(!GetTextMetricsA(hDC
, &tm
)) return FALSE
;
158 if(!GetTextExtentPointA(hDC
, alphabet
, 52, &sz
)) return FALSE
;
160 pSize
->cy
= tm
.tmHeight
;
161 pSize
->cx
= (sz
.cx
/ 26 + 1) / 2;
163 if (hFontPrev
) SelectObject(hDC
, hFontPrev
);
168 /***********************************************************************
171 * Helper function for modal dialogs to enable again the
172 * owner of the dialog box.
174 void DIALOG_EnableOwner( HWND hOwner
)
176 /* Owner must be a top-level window */
178 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
180 EnableWindow( hOwner
, TRUE
);
183 /***********************************************************************
184 * DIALOG_DisableOwner
186 * Helper function for modal dialogs to disable the
187 * owner of the dialog box. Returns TRUE if owner was enabled.
189 BOOL
DIALOG_DisableOwner( HWND hOwner
)
191 /* Owner must be a top-level window */
193 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
194 if (!hOwner
) return FALSE
;
195 if (IsWindowEnabled( hOwner
))
197 EnableWindow( hOwner
, FALSE
);
204 /***********************************************************************
205 * DIALOG_GetControl32
207 * Return the class and text of the control pointed to by ptr,
208 * fill the header structure and return a pointer to the next control.
210 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
215 info
->helpId
= GET_DWORD(p
); p
+= 2;
216 info
->exStyle
= GET_DWORD(p
); p
+= 2;
217 info
->style
= GET_DWORD(p
); p
+= 2;
222 info
->style
= GET_DWORD(p
); p
+= 2;
223 info
->exStyle
= GET_DWORD(p
); p
+= 2;
225 info
->x
= GET_WORD(p
); p
++;
226 info
->y
= GET_WORD(p
); p
++;
227 info
->cx
= GET_WORD(p
); p
++;
228 info
->cy
= GET_WORD(p
); p
++;
232 /* id is a DWORD for DIALOGEX */
233 info
->id
= GET_DWORD(p
);
238 info
->id
= GET_WORD(p
);
242 if (GET_WORD(p
) == 0xffff)
244 static const WCHAR class_names
[6][10] =
246 { 'B','u','t','t','o','n', }, /* 0x80 */
247 { 'E','d','i','t', }, /* 0x81 */
248 { 'S','t','a','t','i','c', }, /* 0x82 */
249 { 'L','i','s','t','B','o','x', }, /* 0x83 */
250 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
251 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
253 WORD id
= GET_WORD(p
+1);
254 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
255 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
257 info
->className
= class_names
[id
];
260 info
->className
= NULL
;
261 /* FIXME: load other classes here? */
267 info
->className
= (LPCWSTR
)p
;
268 p
+= wcslen( info
->className
) + 1;
271 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
273 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, 10 );
274 swprintf((LPWSTR
)info
->windowName
, L
"#%d", GET_WORD(p
+ 1));
275 info
->windowNameFree
= TRUE
;
280 info
->windowName
= (LPCWSTR
)p
;
281 info
->windowNameFree
= FALSE
;
282 p
+= wcslen( info
->windowName
) + 1;
288 p
+= GET_WORD(p
) / sizeof(WORD
);
290 else info
->data
= NULL
;
293 /* Next control is on dword boundary */
294 return (const WORD
*)((((int)p
) + 3) & ~3);
297 /***********************************************************************
298 * DIALOG_CreateControls32
300 * Create the control windows for a dialog.
302 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
303 HINSTANCE hInst
, BOOL unicode
)
305 DIALOGINFO
* dlgInfo
;
306 DLG_CONTROL_INFO info
;
307 HWND hwndCtrl
, hwndDefButton
= 0;
308 INT items
= dlgTemplate
->nbItems
;
310 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
314 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
315 dlgTemplate
->dialogEx
);
317 if (info
.style
& WS_BORDER
)
319 info
.style
&= ~WS_BORDER
;
320 info
.exStyle
|= WS_EX_CLIENTEDGE
;
324 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
325 info
.className
, info
.windowName
,
326 info
.style
| WS_CHILD
,
327 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
328 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
329 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
330 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
331 hwnd
, (HMENU
)info
.id
,
332 hInst
, (LPVOID
)info
.data
);
336 LPSTR
class = (LPSTR
)info
.className
;
337 LPSTR caption
= (LPSTR
)info
.windowName
;
341 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
342 class = HeapAlloc( GetProcessHeap(), 0, len
);
343 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
347 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
348 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
349 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
351 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
352 class, caption
, info
.style
| WS_CHILD
,
353 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
354 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
355 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
356 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
357 hwnd
, (HMENU
)info
.id
,
358 hInst
, (LPVOID
)info
.data
);
359 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
360 if (HIWORD(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
363 if (info
.windowNameFree
)
365 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
370 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
374 /* Send initialisation messages to the control */
375 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
376 (WPARAM
)dlgInfo
->hUserFont
, 0 );
377 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
379 /* If there's already a default push-button, set it back */
380 /* to normal and use this one instead. */
382 SendMessageA( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
383 hwndDefButton
= hwndCtrl
;
384 dlgInfo
->idResult
= GetWindowLongA( hwndCtrl
, GWL_ID
);
390 /***********************************************************************
391 * DIALOG_FindMsgDestination
393 * The messages that IsDialogMessage sends may not go to the dialog
394 * calling IsDialogMessage if that dialog is a child, and it has the
395 * DS_CONTROL style set.
396 * We propagate up until we hit one that does not have DS_CONTROL, or
397 * whose parent is not a dialog.
399 * This is undocumented behaviour.
401 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
403 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
405 HWND hParent
= GetParent(hwndDlg
);
408 if (!IsWindow(hParent
)) break;
410 if (!GETDLGINFO(hParent
)) /* TODO: Correct? */
421 /***********************************************************************
422 * DIALOG_IsAccelerator
424 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
426 HWND hwndControl
= hwnd
;
433 DWORD style
= GetWindowLongW( hwndControl
, GWL_STYLE
);
434 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
436 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
437 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
438 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
440 /* find the accelerator key */
441 LPWSTR p
= buffer
- 2;
445 p
= wcschr( p
+ 2, '&' );
447 while (p
!= NULL
&& p
[1] == '&');
449 /* and check if it's the one we're looking for */
450 /* FIXME: usage of towupper correct? */
451 if (p
!= NULL
&& towupper( p
[1] ) == towupper( wParam
) )
453 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
455 /* set focus to the control */
456 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
457 /* and bump it on to next */
458 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
460 else if (dlgCode
& DLGC_BUTTON
)
462 /* send BM_CLICK message to the control */
463 SendMessageA( hwndControl
, BM_CLICK
, 0, 0 );
468 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
472 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
474 while (!hwndNext
&& hwndControl
)
476 hwndControl
= GetParent( hwndControl
);
477 if (hwndControl
== hwndDlg
)
479 if(hwnd
==hwndDlg
) /* prevent endless loop */
484 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
487 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
489 hwndControl
= hwndNext
;
491 while (hwndControl
&& (hwndControl
!= hwnd
));
496 /***********************************************************************
499 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
501 DIALOGINFO
* dlgInfo
;
504 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
505 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
507 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
509 ShowWindow( hwnd
, SW_SHOW
);
512 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
514 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
516 /* No message present -> send ENTERIDLE and wait */
517 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
518 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
521 else if (!GetMessageW( &msg
, 0, 0, 0 )) break;
523 if (!IsWindow( hwnd
)) return -1;
524 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
526 TranslateMessage( &msg
);
527 DispatchMessageW( &msg
);
529 if (dlgInfo
->flags
& DF_END
) break;
532 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
533 retval
= dlgInfo
->idResult
;
534 DestroyWindow( hwnd
);
538 /***********************************************************************
539 * DIALOG_ParseTemplate32
541 * Fill a DLG_TEMPLATE structure from the dialog template, and return
542 * a pointer to the first control.
544 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
546 const WORD
*p
= (const WORD
*)template;
548 result
->style
= GET_DWORD(p
); p
+= 2;
549 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
551 result
->dialogEx
= TRUE
;
552 result
->helpId
= GET_DWORD(p
); p
+= 2;
553 result
->exStyle
= GET_DWORD(p
); p
+= 2;
554 result
->style
= GET_DWORD(p
); p
+= 2;
558 result
->dialogEx
= FALSE
;
560 result
->exStyle
= GET_DWORD(p
); p
+= 2;
562 result
->nbItems
= GET_WORD(p
); p
++;
563 result
->x
= GET_WORD(p
); p
++;
564 result
->y
= GET_WORD(p
); p
++;
565 result
->cx
= GET_WORD(p
); p
++;
566 result
->cy
= GET_WORD(p
); p
++;
568 /* Get the menu name */
573 result
->menuName
= NULL
;
577 result
->menuName
= (LPCWSTR
)(UINT
)GET_WORD( p
+ 1 );
581 result
->menuName
= (LPCWSTR
)p
;
582 p
+= wcslen( result
->menuName
) + 1;
586 /* Get the class name */
591 result
->className
= DIALOG_CLASS_ATOMW
;
595 result
->className
= (LPCWSTR
)(UINT
)GET_WORD( p
+ 1 );
599 result
->className
= (LPCWSTR
)p
;
600 p
+= wcslen( result
->className
) + 1;
604 /* Get the window caption */
606 result
->caption
= (LPCWSTR
)p
;
607 p
+= wcslen( result
->caption
) + 1;
609 /* Get the font name */
611 if (result
->style
& DS_SETFONT
)
613 result
->pointSize
= GET_WORD(p
);
615 if (result
->dialogEx
)
617 result
->weight
= GET_WORD(p
); p
++;
618 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
622 result
->weight
= FW_DONTCARE
;
623 result
->italic
= FALSE
;
625 result
->faceName
= (LPCWSTR
)p
;
626 p
+= wcslen( result
->faceName
) + 1;
630 result
->pointSize
= 0;
631 result
->weight
= FW_DONTCARE
;
632 result
->italic
= FALSE
;
633 result
->faceName
= NULL
;
636 /* First control is on dword boundary */
637 return (LPCSTR
)((((int)p
) + 3) & ~3);
640 /***********************************************************************
641 * DIALOG_CreateIndirect
642 * Creates a dialog box window
644 * modal = TRUE if we are called from a modal dialog box.
645 * (it's more compatible to do it here, as under Windows the owner
646 * is never disabled if the dialog fails because of an invalid template)
648 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
649 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
650 BOOL unicode
, BOOL modal
)
654 DLG_TEMPLATE
template;
655 DIALOGINFO
* dlgInfo
;
656 DWORD units
= GetDialogBaseUnits();
657 BOOL ownerEnabled
= TRUE
;
659 /* Parse dialog template */
661 if (!dlgTemplate
) return 0;
662 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
664 /* Initialise dialog extra data */
666 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo
) ))) return 0;
667 dlgInfo
->hwndFocus
= 0;
668 dlgInfo
->hUserFont
= 0;
670 dlgInfo
->xBaseUnit
= LOWORD(units
);
671 dlgInfo
->yBaseUnit
= HIWORD(units
);
672 dlgInfo
->idResult
= 0;
674 //dlgInfo->hDialogHeap = 0;
678 if (template.menuName
) dlgInfo
->hMenu
= LoadMenuW( hInst
, template.menuName
);
680 /* Create custom font if needed */
682 if (template.style
& DS_SETFONT
)
684 /* We convert the size to pixels and then make it -ve. This works
685 * for both +ve and -ve template.pointSize */
689 pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
690 dlgInfo
->hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
691 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
692 PROOF_QUALITY
, FF_DONTCARE
,
694 if (dlgInfo
->hUserFont
)
697 HFONT hOldFont
= SelectObject( dc
, dlgInfo
->hUserFont
);
698 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
701 dlgInfo
->xBaseUnit
= charSize
.cx
;
702 dlgInfo
->yBaseUnit
= charSize
.cy
;
704 SelectObject( dc
, hOldFont
);
709 /* Create dialog main window */
711 rect
.left
= rect
.top
= 0;
712 rect
.right
= MulDiv(template.cx
, dlgInfo
->xBaseUnit
, 4);
713 rect
.bottom
= MulDiv(template.cy
, dlgInfo
->yBaseUnit
, 8);
714 if (template.style
& WS_CHILD
)
715 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
716 if (template.style
& DS_MODALFRAME
)
717 template.exStyle
|= WS_EX_DLGMODALFRAME
;
718 if (template.style
& DS_CONTROL
)
719 template.exStyle
|= WS_EX_CONTROLPARENT
;
720 AdjustWindowRectEx( &rect
, template.style
, (dlgInfo
->hMenu
!= 0), template.exStyle
);
721 rect
.right
-= rect
.left
;
722 rect
.bottom
-= rect
.top
;
724 if (template.x
== CW_USEDEFAULT16
)
726 rect
.left
= rect
.top
= CW_USEDEFAULT
;
730 if (template.style
& DS_CENTER
)
732 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
733 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
737 rect
.left
+= MulDiv(template.x
, dlgInfo
->xBaseUnit
, 4);
738 rect
.top
+= MulDiv(template.y
, dlgInfo
->yBaseUnit
, 8);
740 if ( !(template.style
& WS_CHILD
) )
744 if( !(template.style
& DS_ABSALIGN
) )
745 ClientToScreen( owner
, (POINT
*)&rect
);
747 /* try to fit it into the desktop */
749 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
750 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
751 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
752 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
753 if( rect
.left
< 0 ) rect
.left
= 0;
754 if( rect
.top
< 0 ) rect
.top
= 0;
760 ownerEnabled
= DIALOG_DisableOwner( owner
);
761 if (ownerEnabled
) dlgInfo
->flags
|= DF_OWNERENABLED
;
766 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
767 template.style
& ~WS_VISIBLE
,
768 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
769 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
773 LPSTR
class = (LPSTR
)template.className
;
774 LPSTR caption
= (LPSTR
)template.caption
;
778 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
779 class = HeapAlloc( GetProcessHeap(), 0, len
);
780 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class, len
, NULL
, NULL
);
784 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
785 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
786 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption
, len
, NULL
, NULL
);
788 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
789 template.style
& ~WS_VISIBLE
,
790 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
791 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
792 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
793 if (HIWORD(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
798 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
799 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
800 if (modal
&& (dlgInfo
->flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
801 HeapFree( GetProcessHeap(), 0, dlgInfo
);
806 SetWindowContextHelpId( hwnd
, template.helpId
);
810 SETDLGINFO(hwnd
, dlgInfo
); /* maybe SetPropW? */
811 SetWindowLongW( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
);
815 SETDLGINFO(hwnd
, dlgInfo
);
816 SetWindowLongA( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
);
819 if (dlgInfo
->hUserFont
)
820 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
822 /* Create controls */
824 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
826 /* Send initialisation messages and set focus */
828 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
830 /* By returning TRUE, app has requested a default focus assignment */
831 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
832 if( dlgInfo
->hwndFocus
)
833 SetFocus( dlgInfo
->hwndFocus
);
836 if (template.style
& WS_VISIBLE
&& !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
838 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
843 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
844 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
848 /***********************************************************************
851 * Set the focus to a control of the dialog, selecting the text if
852 * the control is an edit dialog.
854 static void DEFDLG_SetFocus( HWND hwndDlg
, HWND hwndCtrl
)
856 HWND hwndPrev
= GetFocus();
858 if (IsChild( hwndDlg
, hwndPrev
))
860 if (SendMessageW( hwndPrev
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
861 SendMessageW( hwndPrev
, EM_SETSEL
, -1, 0 );
863 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
864 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
865 SetFocus( hwndCtrl
);
868 /***********************************************************************
871 static void DEFDLG_SaveFocus( HWND hwnd
)
874 HWND hwndFocus
= GetFocus();
876 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
877 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
878 infoPtr
->hwndFocus
= hwndFocus
;
879 /* Remove default button */
882 /***********************************************************************
883 * DEFDLG_RestoreFocus
885 static void DEFDLG_RestoreFocus( HWND hwnd
)
889 if (IsIconic( hwnd
)) return;
890 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
891 if (!IsWindow( infoPtr
->hwndFocus
)) return;
892 /* Don't set the focus back to controls if EndDialog is already called.*/
893 if (!(infoPtr
->flags
& DF_END
))
895 DEFDLG_SetFocus( hwnd
, infoPtr
->hwndFocus
);
898 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
899 sometimes losing focus when receiving WM_SETFOCUS messages. */
902 /***********************************************************************
903 * DEFDLG_FindDefButton
905 * Find the current default push-button.
907 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
909 HWND hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
912 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
914 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
919 /***********************************************************************
920 * DEFDLG_SetDefButton
922 * Set the new default button to be hwndNew.
924 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
,
927 DWORD dlgcode
=0; /* initialize just to avoid a warning */
929 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
930 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
931 return FALSE
; /* Destination is not a push button */
933 if (dlgInfo
->idResult
) /* There's already a default pushbutton */
935 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
936 if (SendMessageA( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
937 SendMessageA( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
941 if(dlgcode
==DLGC_UNDEFPUSHBUTTON
)
942 SendMessageA( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
943 dlgInfo
->idResult
= GetDlgCtrlID( hwndNew
);
945 else dlgInfo
->idResult
= 0;
949 /***********************************************************************
952 * Implementation of DefDlgProc(). Only handle messages that need special
953 * handling for dialogs.
955 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
956 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
962 HBRUSH brush
= (HBRUSH
)SendMessageW( hwnd
, WM_CTLCOLORDLG
, wParam
, (LPARAM
)hwnd
);
963 if (!brush
) brush
= (HBRUSH
)DefWindowProcW( hwnd
, WM_CTLCOLORDLG
, wParam
, (LPARAM
)hwnd
);
967 HDC hdc
= (HDC
)wParam
;
968 GetClientRect( hwnd
, &rect
);
969 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
970 FillRect( hdc
, &rect
, brush
);
975 if ((dlgInfo
= GETDLGINFO(hwnd
)))
977 /* Free dialog heap (if created) */
978 /*if (dlgInfo->hDialogHeap)
980 GlobalUnlock16(dlgInfo->hDialogHeap);
981 GlobalFree16(dlgInfo->hDialogHeap);
983 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
984 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
985 HeapFree( GetProcessHeap(), 0, dlgInfo
);
987 /* Window clean-up */
988 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
991 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
992 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
995 if (wParam
) DEFDLG_RestoreFocus( hwnd
);
996 else DEFDLG_SaveFocus( hwnd
);
1000 DEFDLG_RestoreFocus( hwnd
);
1004 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1005 DEFDLG_SetDefButton( hwnd
, dlgInfo
, wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
1009 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1012 if (dlgInfo
->idResult
)
1013 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1014 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1015 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1022 HWND hwndDest
= (HWND
)wParam
;
1024 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1025 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
1026 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1030 case WM_ENTERMENULOOP
:
1031 case WM_LBUTTONDOWN
:
1032 case WM_NCLBUTTONDOWN
:
1034 HWND hwndFocus
= GetFocus();
1037 /* always make combo box hide its listbox control */
1038 if (!SendMessageA( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1039 SendMessageA( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1042 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1045 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1048 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1049 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1052 case WM_NOTIFYFORMAT
:
1053 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1058 /***********************************************************************
1061 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, BOOL fResult
)
1063 // TODO: where's wine's WM_CTLCOLOR from?
1064 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1065 /*msg == WM_CTLCOLOR || */ msg
== WM_COMPAREITEM
||
1066 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1067 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1070 return GetWindowLongA( hwnd
, DWL_MSGRESULT
);
1073 /***********************************************************************
1074 * DIALOG_GetNextTabItem
1076 * Helper for GetNextDlgTabItem
1078 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1082 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1084 HWND hChildFirst
= 0;
1088 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1089 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1091 else if (IsChild( hwndMain
, hwndCtrl
))
1093 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1096 if(GetParent(hwndCtrl
) != hwndMain
)
1097 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1101 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDLAST
);
1103 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDFIRST
);
1113 dsStyle
= GetWindowLongA(hChildFirst
,GWL_STYLE
);
1114 exStyle
= GetWindowLongA(hChildFirst
,GWL_EXSTYLE
);
1115 if( (dsStyle
& DS_CONTROL
|| exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1120 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1122 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1127 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1129 retWnd
= hChildFirst
;
1132 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1134 if(!retWnd
&& hwndCtrl
)
1136 HWND hParent
= GetParent(hwndCtrl
);
1139 if(hParent
== hwndMain
) break;
1140 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1142 hParent
= GetParent(hParent
);
1145 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1150 /**********************************************************************
1153 * Helper function for DlgDirList*
1155 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
1156 INT idStatic
, UINT attrib
, BOOL combo
)
1159 LPSTR orig_spec
= spec
;
1162 #define SENDMSG(msg,wparam,lparam) \
1163 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1164 : SendMessageA( hwnd, msg, wparam, lparam ))
1166 DPRINT("%p '%s' %d %d %04x\n",
1167 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
1169 /* If the path exists and is a directory, chdir to it */
1170 if (!spec
|| !spec
[0] || SetCurrentDirectoryA( spec
)) spec
= any
;
1175 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
1176 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
1181 if (!SetCurrentDirectoryA( spec
))
1183 *p
= sep
; /* Restore the original spec */
1190 DPRINT( "mask=%s\n", spec
);
1192 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1194 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1195 if (attrib
& DDL_DIRECTORY
)
1197 if (!(attrib
& DDL_EXCLUSIVE
))
1199 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1200 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1201 (LPARAM
)spec
) == LB_ERR
)
1204 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1205 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1206 (LPARAM
)"*.*" ) == LB_ERR
)
1211 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
1212 (LPARAM
)spec
) == LB_ERR
)
1217 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1219 char temp
[MAX_PATH
];
1220 GetCurrentDirectoryA( sizeof(temp
), temp
);
1222 /* Can't use PostMessage() here, because the string is on the stack */
1223 SetDlgItemTextA( hDlg
, idStatic
, temp
);
1226 if (orig_spec
&& (spec
!= orig_spec
))
1228 /* Update the original file spec */
1230 while ((*orig_spec
++ = *p
++));
1237 /**********************************************************************
1238 * DIALOG_DlgDirListW
1240 * Helper function for DlgDirList*W
1242 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1243 INT idStatic
, UINT attrib
, BOOL combo
)
1250 HEAP_strdupWtoA ( &specA
, spec
, lstrlenW(spec
) );
1251 ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
1253 MultiByteToWideChar( CP_ACP
, 0, specA
, -1, spec
, 0x7fffffff );
1257 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1260 /**********************************************************************
1261 * DIALOG_DlgDirSelect
1263 * Helper function for DlgDirSelect*
1265 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1266 INT id
, BOOL unicode
, BOOL combo
)
1271 HWND listbox
= GetDlgItem( hwnd
, id
);
1273 DPRINT("%p '%s' %d\n", hwnd
, str
, id
);
1274 if (!listbox
) return FALSE
;
1276 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1277 if (item
== LB_ERR
) return FALSE
;
1278 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, 0, 0 );
1279 if (size
== LB_ERR
) return FALSE
;
1281 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
+1 ))) return FALSE
;
1283 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1285 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1287 if (buffer
[1] == '-') /* drive */
1295 buffer
[strlen(buffer
)-1] = '\\';
1303 if (len
> 0 && !MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, (LPWSTR
)str
, len
))
1304 ((LPWSTR
)str
)[len
-1] = 0;
1306 else lstrcpynA( str
, ptr
, len
);
1307 HeapFree( GetProcessHeap(), 0, buffer
);
1308 DPRINT("Returning %d '%s'\n", ret
, str
);
1312 /***********************************************************************
1313 * GetDlgItemEnumProc
1315 * Callback for GetDlgItem
1317 BOOL CALLBACK
GetDlgItemEnumProc (HWND hwnd
, LPARAM lParam
)
1319 GETDLGITEMINFO
* info
= (GETDLGITEMINFO
*)lParam
;
1320 if(info
->nIDDlgItem
== GetWindowLongW( hwnd
, GWL_ID
))
1322 info
->control
= hwnd
;
1329 /* FUNCTIONS *****************************************************************/
1336 CreateDialogIndirectParamA(
1337 HINSTANCE hInstance
,
1338 LPCDLGTEMPLATE lpTemplate
,
1340 DLGPROC lpDialogFunc
,
1343 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, FALSE
, FALSE
);
1352 CreateDialogIndirectParamAorW(
1353 HINSTANCE hInstance
,
1354 LPCDLGTEMPLATE lpTemplate
,
1356 DLGPROC lpDialogFunc
,
1360 This function might be obsolete since I don't think it is exported by NT
1361 Also wine has one more parameter identifying weather it should call
1362 the function with unicode or not */
1373 CreateDialogIndirectParamW(
1374 HINSTANCE hInstance
,
1375 LPCDLGTEMPLATE lpTemplate
,
1377 DLGPROC lpDialogFunc
,
1380 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, TRUE
, FALSE
);
1390 HINSTANCE hInstance
,
1391 LPCSTR lpTemplateName
,
1393 DLGPROC lpDialogFunc
,
1399 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1400 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1401 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1411 HINSTANCE hInstance
,
1412 LPCWSTR lpTemplateName
,
1414 DLGPROC lpDialogFunc
,
1420 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1421 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1422 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1438 BOOL result
= FALSE
;
1439 DIALOGINFO
* dlgInfo
;
1441 /* if there's no dialog info property then call default windows proc?? */
1442 if (!(dlgInfo
= GETDLGINFO(hDlg
)))
1443 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1445 SetWindowLongW( hDlg
, DWL_MSGRESULT
, 0 );
1447 if ((dlgproc
= (WNDPROC
)GetWindowLongA( hDlg
, DWL_DLGPROC
)))
1449 /* Call dialog procedure */
1450 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1453 if (!result
&& IsWindow(hDlg
))
1455 /* callback didn't process this message */
1469 case WM_ENTERMENULOOP
:
1470 case WM_LBUTTONDOWN
:
1471 case WM_NCLBUTTONDOWN
:
1472 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1475 case WM_COMPAREITEM
:
1480 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1483 return DEFDLG_Epilog(hDlg
, Msg
, result
);
1499 BOOL result
= FALSE
;
1500 DIALOGINFO
* dlgInfo
;
1502 /* if there's no dialog info property then call default windows proc?? */
1503 if (!(dlgInfo
= GETDLGINFO(hDlg
)))
1504 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1506 SetWindowLongW( hDlg
, DWL_MSGRESULT
, 0 );
1508 if ((dlgproc
= (WNDPROC
)GetWindowLongW( hDlg
, DWL_DLGPROC
)))
1510 /* Call dialog procedure */
1511 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1514 if (!result
&& IsWindow(hDlg
))
1516 /* callback didn't process this message */
1530 case WM_ENTERMENULOOP
:
1531 case WM_LBUTTONDOWN
:
1532 case WM_NCLBUTTONDOWN
:
1533 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1536 case WM_COMPAREITEM
:
1541 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1544 return DEFDLG_Epilog(hDlg
, Msg
, result
);
1553 DialogBoxIndirectParamA(
1554 HINSTANCE hInstance
,
1555 LPCDLGTEMPLATE hDialogTemplate
,
1557 DLGPROC lpDialogFunc
,
1560 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, TRUE
);
1561 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, hWndParent
);
1571 DialogBoxIndirectParamAorW(
1572 HINSTANCE hInstance
,
1573 LPCDLGTEMPLATE hDialogTemplate
,
1575 DLGPROC lpDialogFunc
,
1579 This function might be obsolete since I don't think it is exported by NT
1580 Also wine has one more parameter identifying weather it should call
1581 the function with unicode or not */
1583 return (INT_PTR
)NULL
;
1592 DialogBoxIndirectParamW(
1593 HINSTANCE hInstance
,
1594 LPCDLGTEMPLATE hDialogTemplate
,
1596 DLGPROC lpDialogFunc
,
1599 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, TRUE
);
1600 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, hWndParent
);
1611 HINSTANCE hInstance
,
1612 LPCSTR lpTemplateName
,
1614 DLGPROC lpDialogFunc
,
1621 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1622 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1623 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, TRUE
);
1624 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1635 HINSTANCE hInstance
,
1636 LPCWSTR lpTemplateName
,
1638 DLGPROC lpDialogFunc
,
1645 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1646 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1647 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, TRUE
);
1648 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1665 return DIALOG_DlgDirList( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1674 DlgDirListComboBoxA(
1691 DlgDirListComboBoxW(
1715 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1724 DlgDirSelectComboBoxExA(
1740 DlgDirSelectComboBoxExW(
1762 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
1777 return DIALOG_DlgDirSelect( hDlg
, (LPSTR
)lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
1790 BOOL wasEnabled
= TRUE
;
1791 DIALOGINFO
* dlgInfo
;
1794 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
1796 dlgInfo
->idResult
= nResult
;
1797 dlgInfo
->flags
|= DF_END
;
1798 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
1800 if (wasEnabled
&& (owner
= GetWindow( hDlg
, GW_OWNER
)))
1801 DIALOG_EnableOwner( owner
);
1803 /* Windows sets the focus to the dialog itself in EndDialog */
1805 if (IsChild(hDlg
, GetFocus()))
1808 /* Don't have to send a ShowWindow(SW_HIDE), just do
1809 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1811 SetWindowPos(hDlg
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
1812 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1814 /* unblock dialog loop */
1815 PostMessageA(hDlg
, WM_NULL
, 0, 0);
1825 GetDialogBaseUnits(VOID
)
1834 if ((hdc
= GetDC(0)))
1836 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
1837 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
1838 ReleaseDC( 0, hdc
);
1853 return GetWindowLongW( hwndCtl
, GWL_ID
);
1866 GETDLGITEMINFO info
;
1867 info
.nIDDlgItem
= nIDDlgItem
;
1869 if(hDlg
&& !EnumChildWindows(hDlg
, (WNDENUMPROC
)&GetDlgItemEnumProc
, (LPARAM
)&info
))
1870 return info
.control
;
1891 if (lpTranslated
) *lpTranslated
= FALSE
;
1892 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1896 result
= strtol( str
, &endptr
, 10 );
1897 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1900 if (((result
== 0) || (result
== 0xFFFFFFFF))/* && (errno == ERANGE) */)
1905 result
= strtoul( str
, &endptr
, 10 );
1906 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1909 if ((result
== 0xFFFFFFFF)/* && (errno == ERANGE) */) return 0;
1911 if (lpTranslated
) *lpTranslated
= TRUE
;
1912 return (UINT
)result
;
1927 return (UINT
)SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1942 return (UINT
)SendDlgItemMessageW( hDlg
, nIDDlgItem
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1951 GetNextDlgGroupItem(
1956 HWND hwnd
, retvalue
;
1960 /* if the hwndCtrl is the child of the control in the hwndDlg,
1961 * then the hwndDlg has to be the parent of the hwndCtrl */
1962 if(GetParent(hCtl
) != hDlg
&& GetParent(GetParent(hCtl
)) == hDlg
)
1963 hDlg
= GetParent(hCtl
);
1968 /* Make sure hwndCtrl is a top-level child */
1969 HWND parent
= GetParent( hCtl
);
1970 while (parent
&& parent
!= hDlg
) parent
= GetParent(parent
);
1971 if (parent
!= hDlg
) return 0;
1975 /* No ctrl specified -> start from the beginning */
1976 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
1977 if (bPrevious
) hCtl
= GetWindow( hCtl
, GW_HWNDLAST
);
1981 hwnd
= GetWindow( hCtl
, GW_HWNDNEXT
);
1984 if (!hwnd
|| (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_GROUP
))
1986 /* Wrap-around to the beginning of the group */
1989 hwnd
= GetWindow( hDlg
, GW_CHILD
);
1990 for (tmp
= hwnd
; tmp
; tmp
= GetWindow( tmp
, GW_HWNDNEXT
) )
1992 if (GetWindowLongW( tmp
, GWL_STYLE
) & WS_GROUP
) hwnd
= tmp
;
1993 if (tmp
== hCtl
) break;
1996 if (hwnd
== hCtl
) break;
1997 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2000 if (!bPrevious
) break;
2002 hwnd
= GetWindow( hwnd
, GW_HWNDNEXT
);
2018 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2028 return IsDialogMessageW(hDlg
, lpMsg
);
2045 if (CallMsgFilterA( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2047 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2049 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2051 switch(lpMsg
->message
)
2054 dlgCode
= SendMessageA( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2055 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2057 switch(lpMsg
->wParam
)
2060 if (!(dlgCode
& DLGC_WANTTAB
))
2062 SendMessageA( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2071 if (!(dlgCode
& DLGC_WANTARROWS
))
2073 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2074 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2075 SendMessageA( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2082 SendMessageA( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2088 DWORD dw
= SendMessageA( hDlg
, DM_GETDEFID
, 0, 0 );
2089 if (HIWORD(dw
) == DC_HASDEFID
)
2091 SendMessageA( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
2092 (LPARAM
)GetDlgItem(hDlg
, LOWORD(dw
)));
2096 SendMessageA( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2105 dlgCode
= SendMessageA( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2106 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2107 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2111 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2113 /* don't translate or dispatch */
2119 TranslateMessage( lpMsg
);
2120 DispatchMessageA( lpMsg
);
2137 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2139 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2141 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2143 switch(lpMsg
->message
)
2146 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2147 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2149 switch(lpMsg
->wParam
)
2152 if (!(dlgCode
& DLGC_WANTTAB
))
2154 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2163 if (!(dlgCode
& DLGC_WANTARROWS
))
2165 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2166 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2167 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2174 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2180 DWORD dw
= SendMessageW( hDlg
, DM_GETDEFID
, 0, 0 );
2181 if (HIWORD(dw
) == DC_HASDEFID
)
2183 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
2184 (LPARAM
)GetDlgItem(hDlg
, LOWORD(dw
)));
2188 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2197 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2198 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2199 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2203 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2205 /* don't translate or dispatch */
2211 TranslateMessage( lpMsg
);
2212 DispatchMessageW( lpMsg
);
2226 return (UINT
)SendDlgItemMessageA( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2239 DIALOGINFO
* dlgInfo
;
2240 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2241 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2242 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2243 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2244 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2254 SendDlgItemMessageA(
2261 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2262 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2272 SendDlgItemMessageW(
2279 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2280 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2298 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2299 else sprintf( str
, "%u", uValue
);
2300 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2315 return SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2329 return SendDlgItemMessageW( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2343 SendDlgItemMessageA( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2347 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2349 LONG lChildID
= GetWindowLongW(hwnd
, GWL_ID
);
2350 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2352 if((lChildID
>= lpRadioGroup
->firstID
) &&
2353 (lChildID
<= lpRadioGroup
->lastID
))
2355 if (lChildID
== lpRadioGroup
->checkID
)
2357 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2361 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2379 RADIOGROUP radioGroup
;
2381 radioGroup
.firstID
= nIDFirstButton
;
2382 radioGroup
.lastID
= nIDLastButton
;
2383 radioGroup
.checkID
= nIDCheckButton
;
2385 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);