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.
20 * PROJECT: ReactOS user32.dll
21 * FILE: dll/win32/user32/windows/dialog.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * Steven Edwards (Steven_Ed4153@yahoo.com)
27 * 07-26-2003 Code ported from wine
28 * 09-05-2001 CSH Created
31 /* INCLUDES ******************************************************************/
35 #include <wine/debug.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
38 /* MACROS/DEFINITIONS ********************************************************/
41 #define DF_OWNERENABLED 0x0002
42 #define DF_DIALOGACTIVE 0x4000 // ReactOS
43 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
44 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
45 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
46 #define GET_WORD(ptr) (*(WORD *)(ptr))
47 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
49 void WINAPI
WinPosActivateOtherWindow(HWND hwnd
);
51 /* INTERNAL STRUCTS **********************************************************/
53 /* Dialog info structure */
56 HWND hwndFocus
; /* Current control with focus */
57 HFONT hUserFont
; /* Dialog font */
58 HMENU hMenu
; /* Dialog menu */
59 UINT xBaseUnit
; /* Dialog units (depends on the font) */
61 INT idResult
; /* EndDialog() result / default pushbutton ID */
62 UINT flags
; /* EndDialog() called for this dialog */
65 /* Dialog control information */
78 BOOL windowNameFree
; // ReactOS
103 /* CheckRadioButton structure */
112 /*********************************************************************
113 * dialog class descriptor
115 const struct builtin_class_descr DIALOG_builtin_class
=
117 WC_DIALOG
, /* name */
118 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
119 (WNDPROC
) DefDlgProcA
, /* procA */
120 (WNDPROC
) DefDlgProcW
, /* procW */
121 DLGWINDOWEXTRA
, /* extra */
122 (LPCWSTR
) IDC_ARROW
, /* cursor */
127 /* INTERNAL FUNCTIONS ********************************************************/
129 /***********************************************************************
132 * Get the DIALOGINFO structure of a window, allocating it if needed
133 * and 'create' is TRUE.
137 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
142 pWindow
= ValidateHwnd( hWnd
);
148 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
150 if (!dlgInfo
&& create
)
152 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
154 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
157 dlgInfo
->idResult
= IDOK
;
158 SETDLGINFO( hWnd
, dlgInfo
);
168 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
170 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
176 /***********************************************************************
179 * Helper function for modal dialogs to enable again the
180 * owner of the dialog box.
182 void DIALOG_EnableOwner( HWND hOwner
)
184 /* Owner must be a top-level window */
186 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
188 EnableWindow( hOwner
, TRUE
);
192 /***********************************************************************
193 * DIALOG_DisableOwner
195 * Helper function for modal dialogs to disable the
196 * owner of the dialog box. Returns TRUE if owner was enabled.
198 BOOL
DIALOG_DisableOwner( HWND hOwner
)
200 /* Owner must be a top-level window */
202 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
203 if (!hOwner
) return FALSE
;
204 if (IsWindowEnabled( hOwner
))
206 EnableWindow( hOwner
, FALSE
);
213 /***********************************************************************
214 * DIALOG_GetControl32
216 * Return the class and text of the control pointed to by ptr,
217 * fill the header structure and return a pointer to the next control.
219 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
224 info
->helpId
= GET_DWORD(p
); p
+= 2;
225 info
->exStyle
= GET_DWORD(p
); p
+= 2;
226 info
->style
= GET_DWORD(p
); p
+= 2;
231 info
->style
= GET_DWORD(p
); p
+= 2;
232 info
->exStyle
= GET_DWORD(p
); p
+= 2;
234 info
->x
= GET_WORD(p
); p
++;
235 info
->y
= GET_WORD(p
); p
++;
236 info
->cx
= GET_WORD(p
); p
++;
237 info
->cy
= GET_WORD(p
); p
++;
241 /* id is a DWORD for DIALOGEX */
242 info
->id
= GET_DWORD(p
);
247 info
->id
= GET_WORD(p
);
251 if (GET_WORD(p
) == 0xffff)
253 static const WCHAR class_names
[6][10] =
255 { 'B','u','t','t','o','n', }, /* 0x80 */
256 { 'E','d','i','t', }, /* 0x81 */
257 { 'S','t','a','t','i','c', }, /* 0x82 */
258 { 'L','i','s','t','B','o','x', }, /* 0x83 */
259 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
260 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
262 WORD id
= GET_WORD(p
+1);
263 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
264 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
267 info
->className
= class_names
[id
];
271 info
->className
= NULL
;
272 /* FIXME: load other classes here? */
273 ERR("Unknown built-in class id %04x\n", id
);
279 info
->className
= (LPCWSTR
)p
;
280 p
+= strlenW( info
->className
) + 1;
283 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
285 //// ReactOS Rev 6478
286 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
287 if (info
->windowName
!= NULL
)
289 wsprintf((LPWSTR
)info
->windowName
, L
"#%d", GET_WORD(p
+ 1));
290 info
->windowNameFree
= TRUE
;
294 info
->windowNameFree
= FALSE
;
300 info
->windowName
= (LPCWSTR
)p
;
301 info
->windowNameFree
= FALSE
;
302 p
+= strlenW( info
->windowName
) + 1;
305 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
306 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
307 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
308 info
->style
, info
->exStyle
, info
->helpId
);
313 p
+= GET_WORD(p
) / sizeof(WORD
);
315 else info
->data
= NULL
;
318 /* Next control is on dword boundary */
319 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
323 /***********************************************************************
324 * DIALOG_CreateControls32
326 * Create the control windows for a dialog.
328 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
329 HINSTANCE hInst
, BOOL unicode
)
331 DIALOGINFO
* dlgInfo
;
332 DLG_CONTROL_INFO info
;
333 HWND hwndCtrl
, hwndDefButton
= 0;
334 INT items
= dlgTemplate
->nbItems
;
336 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
341 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
342 dlgTemplate
->dialogEx
);
343 info
.style
&= ~WS_POPUP
;
344 info
.style
|= WS_CHILD
;
346 if (info
.style
& WS_BORDER
)
348 info
.style
&= ~WS_BORDER
;
349 info
.exStyle
|= WS_EX_CLIENTEDGE
;
354 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
355 info
.className
, info
.windowName
,
356 info
.style
| WS_CHILD
,
357 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
358 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
359 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
360 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
361 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
362 hInst
, (LPVOID
)info
.data
);
366 LPSTR
class = (LPSTR
)info
.className
;
367 LPSTR caption
= (LPSTR
)info
.windowName
;
369 if (!IS_INTRESOURCE(class))
371 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
372 class = HeapAlloc( GetProcessHeap(), 0, len
);
374 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
376 if (!IS_INTRESOURCE(caption
))
378 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
379 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
381 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
384 if (class != NULL
&& caption
!= NULL
)
386 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
387 class, caption
, info
.style
| WS_CHILD
,
388 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
389 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
390 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
391 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
392 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
393 hInst
, (LPVOID
)info
.data
);
397 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
398 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
401 if (info
.windowNameFree
)
403 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
408 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
409 debugstr_w(info
.windowName
));
410 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
414 /* Send initialisation messages to the control */
415 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
416 (WPARAM
)dlgInfo
->hUserFont
, 0 );
417 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
419 /* If there's already a default push-button, set it back */
420 /* to normal and use this one instead. */
422 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
423 hwndDefButton
= hwndCtrl
;
424 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
432 /***********************************************************************
433 * DIALOG_IsAccelerator
435 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
437 HWND hwndControl
= hwnd
;
444 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
445 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
447 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
448 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
449 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
451 /* find the accelerator key */
452 LPWSTR p
= buffer
- 2;
456 p
= strchrW( p
+ 2, '&' );
458 while (p
!= NULL
&& p
[1] == '&');
460 /* and check if it's the one we're looking for */
461 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
463 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
465 /* set focus to the control */
466 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
467 /* and bump it on to next */
468 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
470 else if (dlgCode
& DLGC_BUTTON
)
472 /* send BM_CLICK message to the control */
473 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
478 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
482 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
484 while (!hwndNext
&& hwndControl
)
486 hwndControl
= GetParent( hwndControl
);
487 if (hwndControl
== hwndDlg
)
489 if(hwnd
==hwndDlg
) /* prevent endless loop */
494 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
497 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
499 hwndControl
= hwndNext
;
501 while (hwndControl
&& (hwndControl
!= hwnd
));
506 /***********************************************************************
507 * DIALOG_FindMsgDestination
509 * The messages that IsDialogMessage sends may not go to the dialog
510 * calling IsDialogMessage if that dialog is a child, and it has the
511 * DS_CONTROL style set.
512 * We propagate up until we hit one that does not have DS_CONTROL, or
513 * whose parent is not a dialog.
515 * This is undocumented behaviour.
517 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
519 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
522 HWND hParent
= GetParent(hwndDlg
);
525 if (!IsWindow(hParent
)) break;
527 pWnd
= ValidateHwnd(hParent
);
528 // FIXME: Use pWnd->fnid == FNID_DESKTOP
529 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
531 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
542 /***********************************************************************
545 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
547 DIALOGINFO
* dlgInfo
;
550 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
553 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
556 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
560 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
564 /* ShowWindow the first time the queue goes empty */
565 ShowWindow( hwnd
, SW_SHOWNORMAL
);
568 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
570 /* No message present -> send ENTERIDLE and wait */
571 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
573 GetMessageW( &msg
, 0, 0, 0 );
576 if (msg
.message
== WM_QUIT
)
578 PostQuitMessage( msg
.wParam
);
579 if (!IsWindow( hwnd
)) return 0;
582 if (!IsWindow( hwnd
)) return 0;
583 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
585 TranslateMessage( &msg
);
586 DispatchMessageW( &msg
);
588 if (!IsWindow( hwnd
)) return 0;
589 if (dlgInfo
->flags
& DF_END
) break;
591 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
593 ShowWindow( hwnd
, SW_SHOWNORMAL
);
598 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
599 retval
= dlgInfo
->idResult
;
600 DestroyWindow( hwnd
);
604 /***********************************************************************
605 * DIALOG_ParseTemplate32
607 * Fill a DLG_TEMPLATE structure from the dialog template, and return
608 * a pointer to the first control.
610 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
612 const WORD
*p
= (const WORD
*)template;
616 dlgver
= GET_WORD(p
); p
++;
617 signature
= GET_WORD(p
); p
++;
619 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
621 result
->dialogEx
= TRUE
;
622 result
->helpId
= GET_DWORD(p
); p
+= 2;
623 result
->exStyle
= GET_DWORD(p
); p
+= 2;
624 result
->style
= GET_DWORD(p
); p
+= 2;
628 result
->style
= GET_DWORD(p
- 2);
629 result
->dialogEx
= FALSE
;
631 result
->exStyle
= GET_DWORD(p
); p
+= 2;
633 result
->nbItems
= GET_WORD(p
); p
++;
634 result
->x
= GET_WORD(p
); p
++;
635 result
->y
= GET_WORD(p
); p
++;
636 result
->cx
= GET_WORD(p
); p
++;
637 result
->cy
= GET_WORD(p
); p
++;
638 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
639 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
640 result
->cx
, result
->cy
, result
->helpId
);
641 TRACE(" STYLE 0x%08x\n", result
->style
);
642 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
644 /* Get the menu name */
649 result
->menuName
= NULL
;
653 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
655 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
658 result
->menuName
= (LPCWSTR
)p
;
659 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
660 p
+= strlenW( result
->menuName
) + 1;
664 /* Get the class name */
669 result
->className
= WC_DIALOG
;
673 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
675 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
678 result
->className
= (LPCWSTR
)p
;
679 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
680 p
+= strlenW( result
->className
) + 1;
684 /* Get the window caption */
686 result
->caption
= (LPCWSTR
)p
;
687 p
+= strlenW( result
->caption
) + 1;
688 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
690 /* Get the font name */
692 result
->pointSize
= 0;
693 result
->faceName
= NULL
;
694 result
->weight
= FW_DONTCARE
;
695 result
->italic
= FALSE
;
697 if (result
->style
& DS_SETFONT
)
699 result
->pointSize
= GET_WORD(p
);
702 /* If pointSize is 0x7fff, it means that we need to use the font
703 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
704 * italic, and facename from the dialog template.
706 if (result
->pointSize
== 0x7fff)
708 /* We could call SystemParametersInfo here, but then we'd have
709 * to convert from pixel size to point size (which can be
712 TRACE(" FONT: Using message box font\n");
716 if (result
->dialogEx
)
718 result
->weight
= GET_WORD(p
); p
++;
719 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
721 result
->faceName
= (LPCWSTR
)p
;
722 p
+= strlenW( result
->faceName
) + 1;
724 TRACE(" FONT %d, %s, %d, %s\n",
725 result
->pointSize
, debugstr_w( result
->faceName
),
726 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
730 /* First control is on dword boundary */
731 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
734 /***********************************************************************
737 * Set the focus to a control of the dialog, selecting the text if
738 * the control is an edit dialog.
740 static void DEFDLG_SetFocus( HWND hwndDlg
, HWND hwndCtrl
)
742 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
743 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
744 SetFocus( hwndCtrl
);
748 /***********************************************************************
751 static void DEFDLG_SaveFocus( HWND hwnd
)
754 HWND hwndFocus
= GetFocus();
756 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
757 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
758 infoPtr
->hwndFocus
= hwndFocus
;
759 /* Remove default button */
763 /***********************************************************************
764 * DEFDLG_RestoreFocus
766 static void DEFDLG_RestoreFocus( HWND hwnd
)
770 if (IsIconic( hwnd
)) return;
771 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
772 /* Don't set the focus back to controls if EndDialog is already called.*/
773 if (infoPtr
->flags
& DF_END
) return;
774 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
775 /* If no saved focus control exists, set focus to the first visible,
776 non-disabled, WS_TABSTOP control in the dialog */
777 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
778 if (!IsWindow( infoPtr
->hwndFocus
)) return;
780 DEFDLG_SetFocus( hwnd
, infoPtr
->hwndFocus
);
782 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
783 sometimes losing focus when receiving WM_SETFOCUS messages. */
786 /***********************************************************************
787 * DIALOG_CreateIndirect
788 * Creates a dialog box window
790 * modal = TRUE if we are called from a modal dialog box.
791 * (it's more compatible to do it here, as under Windows the owner
792 * is never disabled if the dialog fails because of an invalid template)
794 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
795 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
796 BOOL unicode
, BOOL modal
)
802 DLG_TEMPLATE
template;
803 DIALOGINFO
* dlgInfo
= NULL
;
804 DWORD units
= GetDialogBaseUnits();
805 BOOL ownerEnabled
= TRUE
;
809 UINT xBaseUnit
= LOWORD(units
);
810 UINT yBaseUnit
= HIWORD(units
);
812 /* Parse dialog template */
814 if (!dlgTemplate
) return 0;
815 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
819 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
821 /* Create custom font if needed */
823 if (template.style
& DS_SETFONT
)
827 if (template.pointSize
== 0x7fff)
829 /* We get the message font from the non-client metrics */
830 NONCLIENTMETRICSW ncMetrics
;
832 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
833 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
834 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
836 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
841 /* We convert the size to pixels and then make it -ve. This works
842 * for both +ve and -ve template.pointSize */
843 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
844 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
845 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
846 PROOF_QUALITY
, FF_DONTCARE
,
853 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
854 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
857 xBaseUnit
= charSize
.cx
;
858 yBaseUnit
= charSize
.cy
;
860 SelectObject( dc
, hOldFont
);
863 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
866 /* Create dialog main window */
868 rect
.left
= rect
.top
= 0;
869 rect
.right
= MulDiv(template.cx
, xBaseUnit
, 4);
870 rect
.bottom
= MulDiv(template.cy
, yBaseUnit
, 8);
871 if (template.style
& WS_CHILD
)
872 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
873 if (template.style
& DS_MODALFRAME
)
874 template.exStyle
|= WS_EX_DLGMODALFRAME
;
875 if (template.style
& DS_CONTROL
)
876 template.exStyle
|= WS_EX_CONTROLPARENT
;
877 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
880 size
.cx
= rect
.right
- rect
.left
;
881 size
.cy
= rect
.bottom
- rect
.top
;
883 if (template.x
== CW_USEDEFAULT16
)
885 pos
.x
= pos
.y
= CW_USEDEFAULT
;
889 HMONITOR monitor
= 0;
890 MONITORINFO mon_info
;
892 mon_info
.cbSize
= sizeof(mon_info
);
893 if (template.style
& DS_CENTER
)
895 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
896 GetMonitorInfoW( monitor
, &mon_info
);
897 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
898 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
900 else if (template.style
& DS_CENTERMOUSE
)
902 GetCursorPos( &pos
);
903 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
904 GetMonitorInfoW( monitor
, &mon_info
);
908 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
909 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
910 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
))) ClientToScreen( owner
, &pos
);
912 if ( !(template.style
& WS_CHILD
) )
916 /* try to fit it into the desktop */
920 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
921 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
922 GetMonitorInfoW( monitor
, &mon_info
);
924 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
926 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
928 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
929 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
935 ownerEnabled
= DIALOG_DisableOwner( owner
);
936 if (ownerEnabled
) flags
|= DF_OWNERENABLED
;
941 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
942 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
943 owner
, hMenu
, hInst
, NULL
);
947 LPCSTR
class = (LPCSTR
)template.className
;
948 LPCSTR caption
= (LPCSTR
)template.caption
;
949 LPSTR class_tmp
= NULL
;
950 LPSTR caption_tmp
= NULL
;
952 if (!IS_INTRESOURCE(class))
954 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
955 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
956 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
959 if (!IS_INTRESOURCE(caption
))
961 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
962 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
963 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
964 caption
= caption_tmp
;
966 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
967 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
968 owner
, hMenu
, hInst
, NULL
);
969 HeapFree( GetProcessHeap(), 0, class_tmp
);
970 HeapFree( GetProcessHeap(), 0, caption_tmp
);
975 if (hUserFont
) DeleteObject( hUserFont
);
976 if (hMenu
) DestroyMenu( hMenu
);
977 if (modal
&& (flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
981 /* moved this from the top of the method to here as DIALOGINFO structure
982 will be valid only after WM_CREATE message has been handled in DefDlgProc
983 All the members of the structure get filled here using temp variables */
984 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
988 if (hUserFont
) DeleteObject( hUserFont
);
989 if (hMenu
) DestroyMenu( hMenu
);
990 if (modal
&& (flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
994 dlgInfo
->hwndFocus
= 0;
995 dlgInfo
->hUserFont
= hUserFont
;
996 dlgInfo
->hMenu
= hMenu
;
997 dlgInfo
->xBaseUnit
= xBaseUnit
;
998 dlgInfo
->yBaseUnit
= yBaseUnit
;
999 dlgInfo
->flags
= flags
;
1001 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1003 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1004 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1006 if (dlgProc
&& dlgInfo
->hUserFont
)
1007 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1009 /* Create controls */
1011 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1013 /* Send initialisation messages and set focus */
1017 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1018 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1019 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1020 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1022 /* By returning TRUE, app has requested a default focus assignment.
1023 * WM_INITDIALOG may have changed the tab order, so find the first
1024 * tabstop control again. */
1025 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1026 if (!dlgInfo
->hwndFocus
) dlgInfo
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1027 if( dlgInfo
->hwndFocus
)
1028 SetFocus( dlgInfo
->hwndFocus
);
1031 DEFDLG_SaveFocus( hwnd
);
1034 //// ReactOS Rev 30613 & 30644
1035 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1036 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1038 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1040 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1041 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1045 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
1046 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
1051 /***********************************************************************
1052 * DEFDLG_FindDefButton
1054 * Find the current default push-button.
1056 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1058 HWND hwndChild
, hwndTmp
;
1060 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1063 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1066 /* Recurse into WS_EX_CONTROLPARENT controls */
1067 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1069 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1070 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1071 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1074 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1080 /***********************************************************************
1083 * Set the default button id.
1085 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1087 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1088 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1089 INT old_id
= dlgInfo
->idResult
;
1091 dlgInfo
->idResult
= wParam
;
1093 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1094 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1095 return FALSE
; /* Destination is not a push button */
1097 /* Make sure the old default control is a valid push button ID */
1098 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1099 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1100 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1101 if (hwndOld
&& hwndOld
!= hwndNew
)
1102 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1106 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1107 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1113 /***********************************************************************
1114 * DEFDLG_SetDefButton
1116 * Set the new default button to be hwndNew.
1118 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1120 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1121 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1124 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1125 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1128 * Need to draw only default push button rectangle.
1129 * Since the next control is not a push button, need to draw the push
1130 * button rectangle for the default control.
1133 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1136 /* Make sure the old default control is a valid push button ID */
1137 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1138 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1139 if (hwndOld
&& hwndOld
!= hwndNew
)
1140 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1144 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1145 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1151 /***********************************************************************
1154 * Implementation of DefDlgProc(). Only handle messages that need special
1155 * handling for dialogs.
1157 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1158 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1164 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1168 HDC hdc
= (HDC
)wParam
;
1169 GetClientRect( hwnd
, &rect
);
1170 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1171 FillRect( hdc
, &rect
, brush
);
1177 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1179 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1180 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1181 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1182 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1183 NtUserxSetDialogPointer( hwnd
, 0 );
1185 /* Window clean-up */
1186 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1189 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1190 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1195 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1196 // if WA_CLICK/ACTIVE ? set dialog is active.
1197 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1198 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1200 if (wParam
) DEFDLG_RestoreFocus( hwnd
);
1201 else DEFDLG_SaveFocus( hwnd
);
1205 DEFDLG_RestoreFocus( hwnd
);
1209 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1210 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1214 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1217 if (dlgInfo
->idResult
)
1218 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1219 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1220 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1227 HWND hwndDest
= (HWND
)wParam
;
1229 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1230 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
1231 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1235 case WM_ENTERMENULOOP
:
1236 case WM_LBUTTONDOWN
:
1237 case WM_NCLBUTTONDOWN
:
1239 HWND hwndFocus
= GetFocus();
1242 /* always make combo box hide its listbox control */
1243 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1244 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1247 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1250 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1253 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1254 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1260 /***********************************************************************
1263 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1265 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1268 if (fResult
) return fResult
;
1270 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1271 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1273 if ( msg
== WM_COMPAREITEM
||
1274 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1275 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1278 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1281 /***********************************************************************
1282 * DIALOG_GetNextTabItem
1284 * Helper for GetNextDlgTabItem
1286 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1290 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1292 HWND hChildFirst
= 0;
1296 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1297 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1299 else if (IsChild( hwndMain
, hwndCtrl
))
1301 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1304 if(GetParent(hwndCtrl
) != hwndMain
)
1305 /* i.e. if we are not at the top level of the recursion */
1306 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1308 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1314 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1315 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1316 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1319 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1320 if (retWnd
) return (retWnd
);
1322 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1324 return (hChildFirst
);
1326 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1330 HWND hParent
= GetParent(hwndCtrl
);
1333 if(hParent
== hwndMain
) break;
1334 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1336 hParent
= GetParent(hParent
);
1339 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1341 return retWnd
? retWnd
: hwndCtrl
;
1345 /**********************************************************************
1346 * DIALOG_DlgDirListW
1348 * Helper function for DlgDirList*W
1350 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1351 INT idStatic
, UINT attrib
, BOOL combo
)
1354 LPWSTR orig_spec
= spec
;
1355 WCHAR any
[] = {'*','.','*',0};
1357 #define SENDMSG(msg,wparam,lparam) \
1358 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1359 : SendMessageW( hwnd, msg, wparam, lparam ))
1361 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1363 /* If the path exists and is a directory, chdir to it */
1364 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1369 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1370 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1371 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1376 if (!SetCurrentDirectoryW( spec
))
1378 *p
= sep
; /* Restore the original spec */
1385 TRACE( "mask=%s\n", spec
);
1387 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1389 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1391 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1392 if (attrib
& DDL_DIRECTORY
)
1394 if (!(attrib
& DDL_EXCLUSIVE
))
1396 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1397 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1400 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1401 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1406 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1410 /* Convert path specification to uppercase */
1411 if (spec
) CharUpperW(spec
);
1413 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1415 WCHAR temp
[MAX_PATH
];
1416 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1418 /* Can't use PostMessage() here, because the string is on the stack */
1419 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1422 if (orig_spec
&& (spec
!= orig_spec
))
1424 /* Update the original file spec */
1426 while ((*orig_spec
++ = *p
++));
1434 /**********************************************************************
1435 * DIALOG_DlgDirListA
1437 * Helper function for DlgDirList*A
1439 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1440 INT idStatic
, UINT attrib
, BOOL combo
)
1444 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1445 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1448 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1449 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1450 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1451 HeapFree( GetProcessHeap(), 0, specW
);
1454 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1457 /**********************************************************************
1458 * DIALOG_DlgDirSelect
1460 * Helper function for DlgDirSelect*
1462 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1463 INT id
, BOOL unicode
, BOOL combo
)
1465 WCHAR
*buffer
, *ptr
;
1468 HWND listbox
= GetDlgItem( hwnd
, id
);
1470 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1471 if (!listbox
) return FALSE
;
1473 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1474 if (item
== LB_ERR
) return FALSE
;
1476 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1477 if (size
== LB_ERR
) return FALSE
;
1479 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1481 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1483 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1485 if (buffer
[1] == '-') /* drive */
1493 buffer
[strlenW(buffer
)-1] = '\\';
1499 /* Filenames without a dot extension must have one tacked at the end */
1500 if (strchrW(buffer
, '.') == NULL
)
1502 buffer
[strlenW(buffer
)+1] = '\0';
1503 buffer
[strlenW(buffer
)] = '.';
1510 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1511 ((LPSTR
)str
)[len
-1] = 0;
1513 else lstrcpynW( str
, ptr
, len
);
1514 HeapFree( GetProcessHeap(), 0, buffer
);
1515 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1520 /* FUNCTIONS *****************************************************************/
1527 CreateDialogIndirectParamAorW(
1528 HINSTANCE hInstance
,
1529 LPCDLGTEMPLATE lpTemplate
,
1531 DLGPROC lpDialogFunc
,
1536 * This function might be obsolete since I don't think it is exported by NT
1537 * Also wine has one more parameter identifying weather it should call
1538 * the function with unicode or not
1540 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, FALSE
);
1549 CreateDialogIndirectParamA(
1550 HINSTANCE hInstance
,
1551 LPCDLGTEMPLATE lpTemplate
,
1553 DLGPROC lpDialogFunc
,
1556 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, DLG_ISANSI
);
1565 CreateDialogIndirectParamW(
1566 HINSTANCE hInstance
,
1567 LPCDLGTEMPLATE lpTemplate
,
1569 DLGPROC lpDialogFunc
,
1572 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, 0);
1582 HINSTANCE hInstance
,
1583 LPCSTR lpTemplateName
,
1585 DLGPROC lpDialogFunc
,
1591 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1592 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1593 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1603 HINSTANCE hInstance
,
1604 LPCWSTR lpTemplateName
,
1606 DLGPROC lpDialogFunc
,
1612 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1613 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1614 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1629 DIALOGINFO
*dlgInfo
;
1631 BOOL result
= FALSE
;
1633 /* Perform DIALOGINFO initialization if not done */
1634 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0;
1636 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1638 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1640 /* Call dialog procedure */
1641 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1644 if (!result
&& IsWindow(hDlg
))
1646 /* callback didn't process this message */
1660 case WM_ENTERMENULOOP
:
1661 case WM_LBUTTONDOWN
:
1662 case WM_NCLBUTTONDOWN
:
1663 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1666 case WM_COMPAREITEM
:
1671 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1674 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, TRUE
);
1689 DIALOGINFO
*dlgInfo
;
1691 BOOL result
= FALSE
;
1693 /* Perform DIALOGINFO initialization if not done */
1694 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0;
1696 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1698 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1700 /* Call dialog procedure */
1701 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1704 if (!result
&& IsWindow(hDlg
))
1706 /* callback didn't process this message */
1720 case WM_ENTERMENULOOP
:
1721 case WM_LBUTTONDOWN
:
1722 case WM_NCLBUTTONDOWN
:
1723 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1726 case WM_COMPAREITEM
:
1731 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1734 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, FALSE
);
1743 DialogBoxIndirectParamAorW(
1744 HINSTANCE hInstance
,
1745 LPCDLGTEMPLATE hDialogTemplate
,
1747 DLGPROC lpDialogFunc
,
1752 * This function might be obsolete since I don't think it is exported by NT
1753 * Also wine has one more parameter identifying weather it should call
1754 * the function with unicode or not
1756 HWND hWnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, TRUE
);
1757 if (hWnd
) return DIALOG_DoDialogBox( hWnd
, hWndParent
);
1767 DialogBoxIndirectParamA(
1768 HINSTANCE hInstance
,
1769 LPCDLGTEMPLATE hDialogTemplate
,
1771 DLGPROC lpDialogFunc
,
1774 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, DLG_ISANSI
);
1783 DialogBoxIndirectParamW(
1784 HINSTANCE hInstance
,
1785 LPCDLGTEMPLATE hDialogTemplate
,
1787 DLGPROC lpDialogFunc
,
1790 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, 0);
1800 HINSTANCE hInstance
,
1801 LPCSTR lpTemplateName
,
1803 DLGPROC lpDialogFunc
,
1809 //// ReactOS rev 33532
1810 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
)) ||
1811 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1813 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1816 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1818 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1821 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, TRUE
);
1822 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1833 HINSTANCE hInstance
,
1834 LPCWSTR lpTemplateName
,
1836 DLGPROC lpDialogFunc
,
1842 //// ReactOS rev 33532
1843 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
)) ||
1844 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1846 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1849 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1851 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1854 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, TRUE
);
1855 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1872 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1881 DlgDirListComboBoxA(
1888 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1897 DlgDirListComboBoxW(
1904 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1920 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1929 DlgDirSelectComboBoxExA(
1935 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, FALSE
, TRUE
);
1944 DlgDirSelectComboBoxExW(
1950 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, TRUE
, TRUE
);
1965 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
1980 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
1993 BOOL wasEnabled
= TRUE
;
1994 DIALOGINFO
* dlgInfo
;
1997 TRACE("%p %ld\n", hwnd
, retval
);
1999 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2001 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2004 dlgInfo
->idResult
= retval
;
2005 dlgInfo
->flags
|= DF_END
;
2006 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
2008 owner
= GetWindow( hwnd
, GW_OWNER
);
2009 if (wasEnabled
&& owner
)
2010 DIALOG_EnableOwner( owner
);
2012 /* Windows sets the focus to the dialog itself in EndDialog */
2014 if (IsChild(hwnd
, GetFocus()))
2017 /* Don't have to send a ShowWindow(SW_HIDE), just do
2018 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2020 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2021 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2023 if (hwnd
== GetActiveWindow())
2025 /* If this dialog was given an owner then set the focus to that owner
2026 even when the owner is disabled (normally when a window closes any
2027 disabled windows cannot receive the focus). */
2029 SetForegroundWindow( owner
);
2031 WinPosActivateOtherWindow( hwnd
);
2034 /* unblock dialog loop */
2035 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2045 GetDialogBaseUnits(VOID
)
2054 if ((hdc
= GetDC(0)))
2056 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2057 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2058 ReleaseDC( 0, hdc
);
2073 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2087 HWND
*list
= WIN_ListChildren(hDlg
);
2090 if (!list
) return 0;
2092 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2094 HeapFree(GetProcessHeap(), 0, list
);
2095 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2113 LONG_PTR result
= 0;
2115 if (lpTranslated
) *lpTranslated
= FALSE
;
2116 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2120 result
= strtol( str
, &endptr
, 10 );
2121 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2123 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
== ERANGE
) )
2128 result
= strtoul( str
, &endptr
, 10 );
2129 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2131 if ((result
== ULONG_MAX
) && (errno
== ERANGE
) ) return 0;
2133 if (lpTranslated
) *lpTranslated
= TRUE
;
2134 return (UINT
)result
;
2149 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2150 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2151 if ( nMaxCount
) *lpString
= 0;
2167 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2168 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2169 if ( nMaxCount
) *lpString
= 0;
2178 GetNextDlgGroupItem(
2183 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2185 BOOL fSkipping
=FALSE
;
2187 if (hDlg
== hCtl
) hCtl
= NULL
;
2188 if (!hCtl
&& bPrevious
) return 0;
2190 /* if the hwndCtrl is the child of the control in the hwndDlg,
2191 * then the hwndDlg has to be the parent of the hwndCtrl */
2195 if (!IsChild (hDlg
, hCtl
)) return 0;
2196 /* Make sure hwndCtrl is a top-level child */
2201 /* No ctrl specified -> start from the beginning */
2202 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2203 /* MSDN is wrong. fPrevious does not result in the last child */
2205 /* No ctrl specified -> start from the beginning */
2206 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2208 /* MSDN is wrong. fPrevious does not result in the last child */
2210 /* Maybe that first one is valid. If so then we don't want to skip it*/
2211 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2218 /* Always go forward around the group and list of controls; for the
2219 * previous control keep track; for the next break when you find one
2223 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
2228 /* Climb out until there is a next sibling of the ancestor or we
2229 * reach the top (in which case we loop back to the start)
2231 if (hDlg
== GetParent (hwnd
))
2233 /* Wrap around to the beginning of the list, within the same
2234 * group. (Once only)
2236 if (fLooped
) goto end
;
2238 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2242 hwnd
= GetParent (hwnd
);
2243 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2248 /* Wander down the leading edge of controlparents */
2249 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2250 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2251 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2253 /* Question. If the control is a control parent but either has no
2254 * children or is not visible/enabled then if it has a WS_GROUP does
2255 * it count? For that matter does it count anyway?
2256 * I believe it doesn't count.
2259 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2261 hwndLastGroup
= hwnd
;
2264 /* Look for the beginning of the group */
2271 if (!fSkipping
) break;
2272 if (hwndLastGroup
== hwnd
) break;
2273 hwnd
= hwndLastGroup
;
2279 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2283 if (!bPrevious
) break;
2303 pWindow
= ValidateHwnd( hDlg
);
2304 if (!pWindow
) return NULL
;
2307 pWindow
= ValidateHwnd( hCtl
);
2308 if (!pWindow
) return NULL
;
2311 /* Undocumented but tested under Win2000 and WinME */
2312 if (hDlg
== hCtl
) hCtl
= NULL
;
2314 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2315 * NB GetLastError returns whatever was set before the function was
2318 if (!hCtl
&& bPrevious
) return 0;
2320 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2331 return IsDialogMessageW(hDlg
, lpMsg
);
2335 /***********************************************************************
2336 * DIALOG_FixOneChildOnChangeFocus
2338 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2341 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2344 /* If a default pushbutton then no longer default */
2345 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2346 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2350 /***********************************************************************
2351 * DIALOG_FixChildrenOnChangeFocus
2353 * Following the change of focus that occurs for example after handling
2354 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2355 * children may be required.
2357 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2359 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2360 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2361 /* Windows does ask for this. I don't know why yet */
2363 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2365 /* If the button that is getting the focus WAS flagged as the default
2366 * pushbutton then ask the dialog what it thinks the default is and
2367 * set that in the default style.
2369 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2371 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2372 if (HIWORD(def_id
) == DC_HASDEFID
)
2375 def_id
= LOWORD(def_id
);
2376 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2379 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2380 /* I know that if it is a button then it should already be a
2381 * UNDEFPUSHBUTTON, since we have just told the buttons to
2382 * change style. But maybe they ignored our request
2384 if ((dlgcode_def
& DLGC_BUTTON
) &&
2385 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2387 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2392 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2394 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2395 /* I wonder why it doesn't send a DM_SETDEFID */
2399 /***********************************************************************
2402 * A recursive version of GetDlgItem
2405 * The HWND for a Child ID.
2407 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2410 HWND
*list
= WIN_ListChildren( hwndDlg
);
2413 if (!list
) return 0;
2415 for (i
= 0; list
[i
]; i
++)
2417 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2423 /* Recurse into every child */
2424 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2427 HeapFree( GetProcessHeap(), 0, list
);
2443 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2445 if (hDlg
== GetDesktopWindow()) return FALSE
;
2446 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2448 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2450 switch(lpMsg
->message
)
2453 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2454 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2456 switch(lpMsg
->wParam
)
2459 if (!(dlgCode
& DLGC_WANTTAB
))
2461 BOOL fIsDialog
= TRUE
;
2462 WND
*pWnd
= ValidateHwnd(hDlg
);
2464 if (pWnd
&& TestWindowProcess(pWnd
))
2466 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2469 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2471 /* I am not sure under which circumstances the TAB is handled
2472 * each way. All I do know is that it does not always simply
2473 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2474 * do so but I presume someone has)
2477 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2480 /* It would appear that GetNextDlgTabItem can handle being
2481 * passed hwndDlg rather than NULL but that is undocumented
2482 * so let's do it properly
2484 HWND hwndFocus
= GetFocus();
2485 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2486 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2487 GetKeyState (VK_SHIFT
) & 0x8000);
2490 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2491 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2492 if (dlgCode
& DLGC_HASSETSEL
)
2494 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2495 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2499 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2500 length
= strlenW (buffer
);
2501 HeapFree (GetProcessHeap(), 0, buffer
);
2502 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2505 SetFocus (hwndNext
);
2506 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2519 if (!(dlgCode
& DLGC_WANTARROWS
))
2521 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2522 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2523 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2530 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2537 if ((GetFocus() == lpMsg
->hwnd
) &&
2538 (SendMessageW (lpMsg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2540 SendMessageW (hDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(lpMsg
->hwnd
),BN_CLICKED
), (LPARAM
)lpMsg
->hwnd
);
2542 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2544 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2545 if (hwndDef
? IsWindowEnabled(hwndDef
) : LOWORD(dw
)==IDOK
)
2546 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2550 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2559 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2560 * It does NOT get sent in the test program I have
2562 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2563 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2564 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2568 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2570 /* don't translate or dispatch */
2576 /* If the ALT key is being pressed display the keyboard cues */
2577 if (HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
)
2578 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2582 /* If the ALT key is being pressed display the keyboard cues */
2583 if (lpMsg
->wParam
== SC_KEYMENU
)
2585 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2590 TranslateMessage( lpMsg
);
2591 DispatchMessageW( lpMsg
);
2605 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2618 DIALOGINFO
* dlgInfo
;
2619 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2620 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2621 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2622 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2623 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2633 SendDlgItemMessageA(
2641 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2642 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2643 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2653 SendDlgItemMessageW(
2661 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2662 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2663 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2681 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2682 else sprintf( str
, "%u", uValue
);
2683 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2698 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2699 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2714 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2715 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2730 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2734 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2736 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2737 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2739 if((lChildID
>= lpRadioGroup
->firstID
) &&
2740 (lChildID
<= lpRadioGroup
->lastID
))
2742 if (lChildID
== lpRadioGroup
->checkID
)
2744 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2748 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2766 RADIOGROUP radioGroup
;
2768 radioGroup
.firstID
= nIDFirstButton
;
2769 radioGroup
.lastID
= nIDLastButton
;
2770 radioGroup
.checkID
= nIDCheckButton
;
2772 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);